Skip to content

Commit e6270e4

Browse files
Examples for creation of sycl_queue
1 parent ae51b45 commit e6270e4

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

examples/python/sycl_queue.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
import dpctl
18+
19+
def create_default_queue():
20+
""" Create a queue from default selector.
21+
"""
22+
q = dpctl.SyclQueue()
23+
# Queue is out-of-order by default
24+
print("Queue {} is in order: {}".format(q, q.is_in_order))
25+
26+
27+
def create_queue_from_filter_selector():
28+
""" Create queue for a GPU device or,
29+
if it is not available, for a CPU device.
30+
31+
Create in-order queue with profilign enabled.
32+
"""
33+
q = dpctl.SyclQueue(
34+
"gpu,cpu",
35+
property=("in_order", "enable_profiling")
36+
)
37+
print("Queue {} is in order: {}".format(q, q.is_in_order))
38+
# display the device used
39+
print("Device targeted by the queue:")
40+
q.sycl_device.print_device_info()
41+
42+
43+
def create_queue_from_device():
44+
"""
45+
Create a queue from SyclDevice instance.
46+
"""
47+
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
48+
q = dpctl.SyclQueue(cpu_d, property="enable_profiling")
49+
assert q.sycl_device == cpu_d
50+
print("Number of devices in SyclContext "
51+
"associated with the queue: ", q.sycl_context.device_count)
52+
53+
54+
def create_queue_from_subdevice():
55+
"""
56+
Create a queue from a sub-device.
57+
"""
58+
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
59+
sub_devs = cpu_d.create_sub_devices(partition=4)
60+
q = dpctl.SyclQueue(sub_devs[0])
61+
# a single-device context is created automatically
62+
print("Number of devices in SyclContext "
63+
"associated with the queue: ", q.sycl_context.device_count)
64+
65+
66+
def create_queue_from_subdevice_multidevice_context():
67+
"""
68+
Create a queue from a sub-device.
69+
"""
70+
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
71+
sub_devs = cpu_d.create_sub_devices(partition=4)
72+
ctx = dpctl.SyclContext(sub_devs)
73+
q = dpctl.SyclQueue(ctx, sub_devs[0])
74+
# a single-device context is created automatically
75+
print("Number of devices in SyclContext "
76+
"associated with the queue: ", q.sycl_context.device_count)
77+
78+
79+
if __name__ == "__main__":
80+
import _runner as runner
81+
runner.run_examples(
82+
"Queue creation examples for dpctl.",
83+
globals()
84+
)

0 commit comments

Comments
 (0)