Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for select_device_with_aspects. #726

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions examples/python/device_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@
import dpctl


def print_device(d):
"Display information about given device argument."
if type(d) is not dpctl.SyclDevice:
raise ValueError
print("Name: ", d.name)
print("Vendor: ", d.vendor)
print("Driver version: ", d.driver_version)
print("Backend: ", d.backend)
print("Max EU: ", d.max_compute_units)


def create_default_device():
"""
Create default SyclDevice using `cl::sycl::default_selector`.
Expand All @@ -42,7 +31,7 @@ def create_default_device():
d1 = dpctl.SyclDevice()
d2 = dpctl.select_default_device()
assert d1 == d2
print_device(d1)
d1.print_device_info()
return d1


Expand All @@ -58,7 +47,7 @@ def create_gpu_device():
d1 = dpctl.SyclDevice("gpu")
d2 = dpctl.select_gpu_device()
assert d1 == d2
print_device(d1)
d1.print_device_info()
except ValueError:
print("A GPU device is not available on the system")

Expand Down Expand Up @@ -96,12 +85,24 @@ def custom_select_device():
max_score = d.default_selector_score
selected_dev = d
if selected_dev:
print_device(selected_dev)
selected_dev.print_device_info()
else:
print("No device with half-precision support is available.")
return selected_dev


def create_device_with_aspects():
"""
Programmatically select a device based on specific set of aspects.

Demonstrate the usage of :func:`dpctl.select_device_with_aspects()`.
"""
dev = dpctl.select_device_with_aspects(
required_aspects=["fp64", "gpu", "usm_shared_allocations"]
)
dev.print_device_info()


if __name__ == "__main__":
import _runner as runner

Expand Down
19 changes: 4 additions & 15 deletions examples/python/filter_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,29 @@
import dpctl


def print_device(d):
"Display information about given device argument."
if type(d) is not dpctl.SyclDevice:
raise ValueError
print("Name: ", d.name)
print("Vendor: ", d.vendor)
print("Driver version: ", d.driver_version)
print("Backend: ", d.backend)
print("Max EU: ", d.max_compute_units)


def select_using_filter():
"""
Demonstrate the usage of a filter string to create a SyclDevice.

"""
try:
d1 = dpctl.SyclDevice("cpu")
print_device(d1)
d1.print_device_info()
except ValueError:
print("A CPU type device is not available on the system")

try:
d1 = dpctl.SyclDevice("opencl:cpu:0")
print_device(d1)
d1.print_device_info()
except ValueError:
print("An OpenCL CPU driver needs to be installed on the system")

d1 = dpctl.SyclDevice("0")
print_device(d1)
d1.print_device_info()

try:
d1 = dpctl.SyclDevice("gpu")
print_device(d1)
d1.print_device_info()
except ValueError:
print("A GPU type device is not available on the system")

Expand Down