20
20
""" Implements SyclDevice Cython extension type.
21
21
"""
22
22
23
- from ._backend cimport *
23
+ from ._backend cimport (
24
+ DPCTLAcceleratorSelector_Create,
25
+ DPCTLCPUSelector_Create,
26
+ DPCTLDefaultSelector_Create,
27
+ DPCTLGPUSelector_Create,
28
+ DPCTLHostSelector_Create,
29
+ DPCTLCString_Delete,
30
+ DPCTLDevice_CreateFromSelector,
31
+ DPCTLDevice_Delete,
32
+ DPCTLDevice_DumpInfo,
33
+ DPCTLDevice_GetVendorName,
34
+ DPCTLDevice_GetName,
35
+ DPCTLDevice_GetDriverInfo,
36
+ DPCTLDevice_GetMaxComputeUnits,
37
+ DPCTLDevice_GetMaxWorkItemDims,
38
+ DPCTLDevice_GetMaxWorkItemSizes,
39
+ DPCTLDevice_GetMaxWorkGroupSize,
40
+ DPCTLDevice_GetMaxNumSubGroups,
41
+ DPCTLDevice_HasInt64BaseAtomics,
42
+ DPCTLDevice_HasInt64ExtendedAtomics,
43
+ DPCTLDevice_IsGPU,
44
+ DPCTLDevice_IsCPU,
45
+ DPCTLDeviceSelector_Delete,
46
+ DPCTLSize_t_Array_Delete,
47
+ DPCTLSyclDeviceRef,
48
+ )
24
49
from . import device_type
25
50
26
51
__all__ = [
27
52
" SyclDevice" ,
53
+ " select_accelerator_device" ,
54
+ " select_cpu_device" ,
55
+ " select_default_device" ,
56
+ " select_gpu_device" ,
57
+ " select_host_device" ,
28
58
]
29
59
30
60
@@ -33,7 +63,7 @@ cdef class SyclDevice:
33
63
"""
34
64
35
65
@staticmethod
36
- cdef SyclDevice _create (DPCTLSyclDeviceRef dref):
66
+ cdef SyclDevice _create(DPCTLSyclDeviceRef dref):
37
67
cdef SyclDevice ret = SyclDevice.__new__ (SyclDevice)
38
68
ret._device_ref = dref
39
69
ret._vendor_name = DPCTLDevice_GetVendorName(dref)
@@ -48,24 +78,28 @@ cdef class SyclDevice:
48
78
ret._int64_extended_atomics = DPCTLDevice_HasInt64ExtendedAtomics(dref)
49
79
return ret
50
80
51
- def __dealloc__ (self ):
81
+
82
+ def __dealloc__ (self ):
52
83
DPCTLDevice_Delete(self ._device_ref)
53
84
DPCTLCString_Delete(self ._device_name)
54
85
DPCTLCString_Delete(self ._vendor_name)
55
86
DPCTLCString_Delete(self ._driver_version)
56
87
DPCTLSize_t_Array_Delete(self ._max_work_item_sizes)
57
88
58
- def dump_device_info (self ):
89
+
90
+ def dump_device_info (self ):
59
91
""" Print information about the SYCL device.
60
92
"""
61
93
DPCTLDevice_DumpInfo(self ._device_ref)
62
94
63
- cpdef get_device_name (self ):
95
+
96
+ cpdef get_device_name(self ):
64
97
""" Returns the name of the device as a string
65
98
"""
66
99
return self ._device_name.decode()
67
100
68
- cpdef get_device_type (self ):
101
+
102
+ cpdef get_device_type(self ):
69
103
""" Returns the type of the device as a `device_type` enum
70
104
"""
71
105
if DPCTLDevice_IsGPU(self ._device_ref):
@@ -75,36 +109,42 @@ cdef class SyclDevice:
75
109
else :
76
110
raise ValueError (" Unknown device type." )
77
111
78
- cpdef get_vendor_name (self ):
112
+
113
+ cpdef get_vendor_name(self ):
79
114
""" Returns the device vendor name as a string
80
115
"""
81
116
return self ._vendor_name.decode()
82
117
83
- cpdef get_driver_version (self ):
118
+
119
+ cpdef get_driver_version(self ):
84
120
""" Returns the OpenCL software driver version as a string
85
121
in the form: major number.minor number, if this SYCL
86
122
device is an OpenCL device. Returns a string class
87
123
with the value "1.2" if this SYCL device is a host device.
88
124
"""
89
125
return self ._driver_version.decode()
90
126
91
- cpdef has_int64_base_atomics (self ):
127
+
128
+ cpdef has_int64_base_atomics(self ):
92
129
""" Returns true if device has int64_base_atomics else returns false.
93
130
"""
94
131
return self ._int64_base_atomics
95
132
96
- cpdef has_int64_extended_atomics (self ):
133
+
134
+ cpdef has_int64_extended_atomics(self ):
97
135
""" Returns true if device has int64_extended_atomics else returns false.
98
136
"""
99
137
return self ._int64_extended_atomics
100
138
101
- cpdef get_max_compute_units (self ):
139
+
140
+ cpdef get_max_compute_units(self ):
102
141
""" Returns the number of parallel compute units
103
142
available to the device. The minimum value is 1.
104
143
"""
105
144
return self ._max_compute_units
106
145
107
- cpdef get_max_work_item_dims (self ):
146
+
147
+ cpdef get_max_work_item_dims(self ):
108
148
""" Returns the maximum dimensions that specify
109
149
the global and local work-item IDs used by the
110
150
data parallel execution model. The minimum
@@ -113,7 +153,8 @@ cdef class SyclDevice:
113
153
"""
114
154
return self ._max_work_item_dims
115
155
116
- cpdef get_max_work_item_sizes (self ):
156
+
157
+ cpdef get_max_work_item_sizes(self ):
117
158
""" Returns the maximum number of work-items
118
159
that are permitted in each dimension of the
119
160
work-group of the nd_range. The minimum
@@ -125,27 +166,31 @@ cdef class SyclDevice:
125
166
max_work_item_sizes.append(self ._max_work_item_sizes[n])
126
167
return tuple (max_work_item_sizes)
127
168
128
- cpdef get_max_work_group_size (self ):
169
+
170
+ cpdef get_max_work_group_size(self ):
129
171
""" Returns the maximum number of work-items
130
172
that are permitted in a work-group executing a
131
173
kernel on a single compute unit. The minimum
132
174
value is 1.
133
175
"""
134
176
return self ._max_work_group_size
135
177
136
- cpdef get_max_num_sub_groups (self ):
178
+
179
+ cpdef get_max_num_sub_groups(self ):
137
180
""" Returns the maximum number of sub-groups
138
181
in a work-group for any kernel executed on the
139
182
device. The minimum value is 1.
140
183
"""
141
184
return self ._max_num_sub_groups
142
185
186
+
143
187
cdef DPCTLSyclDeviceRef get_device_ref (self ):
144
188
""" Returns the DPCTLSyclDeviceRef pointer for this class.
145
189
"""
146
190
return self ._device_ref
147
191
148
- def addressof_ref (self ):
192
+
193
+ def addressof_ref (self ):
149
194
"""
150
195
Returns the address of the DPCTLSyclDeviceRef pointer as a size_t.
151
196
@@ -154,3 +199,98 @@ cdef class SyclDevice:
154
199
SyclDevice cast to a size_t.
155
200
"""
156
201
return int (< size_t> self ._device_ref)
202
+
203
+
204
+ cpdef select_accelerator_device():
205
+ """ A wrapper for SYCL's `accelerator_selector` device_selector class.
206
+
207
+ Returns:
208
+ A new SyclDevice object containing the SYCL device returned by the
209
+ `accelerator_selector`.
210
+ Raises:
211
+ A ValueError is raised if the SYCL `accelerator_selector` is unable to
212
+ select a device.
213
+ """
214
+ cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLAcceleratorSelector_Create()
215
+ cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
216
+ DPCTLDeviceSelector_Delete(DSRef)
217
+ if DRef is NULL :
218
+ raise ValueError (" Device unavailable." )
219
+ Device = SyclDevice._create(DRef)
220
+ return Device
221
+
222
+
223
+ cpdef select_cpu_device():
224
+ """ A wrapper for SYCL's `cpu_selector` device_selector class.
225
+
226
+ Returns:
227
+ A new SyclDevice object containing the SYCL device returned by the
228
+ `cpu_selector`.
229
+ Raises:
230
+ A ValueError is raised if the SYCL `cpu_seector` is unable to select a
231
+ device.
232
+ """
233
+ cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLCPUSelector_Create()
234
+ cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
235
+ DPCTLDeviceSelector_Delete(DSRef)
236
+ if DRef is NULL :
237
+ raise ValueError (" Device unavailable." )
238
+ Device = SyclDevice._create(DRef)
239
+ return Device
240
+
241
+
242
+ cpdef select_default_device():
243
+ """ A wrapper for SYCL's `default_selector` device_selector class.
244
+
245
+ Returns:
246
+ A new SyclDevice object containing the SYCL device returned by the
247
+ `default_selector`.
248
+ Raises:
249
+ A ValueError is raised if the SYCL `default_seector` is unable to
250
+ select a device.
251
+ """
252
+ cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create()
253
+ cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
254
+ DPCTLDeviceSelector_Delete(DSRef)
255
+ if DRef is NULL :
256
+ raise ValueError (" Device unavailable." )
257
+ Device = SyclDevice._create(DRef)
258
+ return Device
259
+
260
+
261
+ cpdef select_gpu_device():
262
+ """ A wrapper for SYCL's `gpu_selector` device_selector class.
263
+
264
+ Returns:
265
+ A new SyclDevice object containing the SYCL device returned by the
266
+ `gpu_selector`.
267
+ Raises:
268
+ A ValueError is raised if the SYCL `gpu_seector` is unable to select a
269
+ device.
270
+ """
271
+ cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLGPUSelector_Create()
272
+ cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
273
+ DPCTLDeviceSelector_Delete(DSRef)
274
+ if DRef is NULL :
275
+ raise ValueError (" Device unavailable." )
276
+ Device = SyclDevice._create(DRef)
277
+ return Device
278
+
279
+
280
+ cpdef select_host_device():
281
+ """ A wrapper for SYCL's `host_selector` device_selector class.
282
+
283
+ Returns:
284
+ A new SyclDevice object containing the SYCL device returned by the
285
+ `host_selector`.
286
+ Raises:
287
+ A ValueError is raised if the SYCL `host_seector` is unable to select a
288
+ device.
289
+ """
290
+ cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLHostSelector_Create()
291
+ cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
292
+ DPCTLDeviceSelector_Delete(DSRef)
293
+ if DRef is NULL :
294
+ raise ValueError (" Device unavailable." )
295
+ Device = SyclDevice._create(DRef)
296
+ return Device
0 commit comments