|
| 1 | +# Data Parallel Control (dpctl) |
| 2 | +# |
| 3 | +# Copyright 2020-2021 Intel Corporation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +"""Examples illustrating SYCL device selection using filter strings. |
| 18 | +""" |
| 19 | + |
| 20 | +import dpctl |
| 21 | + |
| 22 | + |
| 23 | +def print_device(d): |
| 24 | + "Display information about given device argument." |
| 25 | + if type(d) is not dpctl.SyclDevice: |
| 26 | + raise ValueError |
| 27 | + print("Name: ", d.name) |
| 28 | + print("Vendor: ", d.vendor) |
| 29 | + print("Driver version: ", d.driver_version) |
| 30 | + print("Backend: ", d.backend) |
| 31 | + print("Max EU: ", d.max_compute_units) |
| 32 | + |
| 33 | + |
| 34 | +def select_using_filter(): |
| 35 | + """ |
| 36 | + Demonstrate the usage of a filter string to create a SyclDevice. |
| 37 | +
|
| 38 | + """ |
| 39 | + try: |
| 40 | + d1 = dpctl.SyclDevice("cpu") |
| 41 | + print_device(d1) |
| 42 | + except ValueError: |
| 43 | + print("A CPU type device is not available on the system") |
| 44 | + |
| 45 | + try: |
| 46 | + d1 = dpctl.SyclDevice("opencl:cpu:0") |
| 47 | + print_device(d1) |
| 48 | + except ValueError: |
| 49 | + print("An OpenCL CPU driver needs to be installed on the system") |
| 50 | + |
| 51 | + d1 = dpctl.SyclDevice("0") |
| 52 | + print_device(d1) |
| 53 | + |
| 54 | + try: |
| 55 | + d1 = dpctl.SyclDevice("gpu") |
| 56 | + print_device(d1) |
| 57 | + except ValueError: |
| 58 | + print("A GPU type device is not available on the system") |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + import _runner as runner |
| 63 | + |
| 64 | + runner.run_examples("Filter selection examples for dpctl.", globals()) |
0 commit comments