-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy path_sycl_device.pyx
More file actions
2386 lines (1986 loc) · 78 KB
/
_sycl_device.pyx
File metadata and controls
2386 lines (1986 loc) · 78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Data Parallel Control (dpctl)
#
# Copyright 2020-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# distutils: language = c++
# cython: language_level=3
# cython: linetrace=True
# cython: freethreading_compatible = True
""" Implements SyclDevice Cython extension type.
"""
from ._backend cimport ( # noqa: E211
DPCTLCString_Delete,
DPCTLDefaultSelector_Create,
DPCTLDevice_AreEq,
DPCTLDevice_CanAccessPeer,
DPCTLDevice_Copy,
DPCTLDevice_CreateFromSelector,
DPCTLDevice_CreateSubDevicesByAffinity,
DPCTLDevice_CreateSubDevicesByCounts,
DPCTLDevice_CreateSubDevicesEqually,
DPCTLDevice_Delete,
DPCTLDevice_DisablePeerAccess,
DPCTLDevice_EnablePeerAccess,
DPCTLDevice_GetBackend,
DPCTLDevice_GetComponentDevices,
DPCTLDevice_GetCompositeDevice,
DPCTLDevice_GetDeviceType,
DPCTLDevice_GetDriverVersion,
DPCTLDevice_GetGlobalMemCacheLineSize,
DPCTLDevice_GetGlobalMemCacheSize,
DPCTLDevice_GetGlobalMemCacheType,
DPCTLDevice_GetGlobalMemSize,
DPCTLDevice_GetImage2dMaxHeight,
DPCTLDevice_GetImage2dMaxWidth,
DPCTLDevice_GetImage3dMaxDepth,
DPCTLDevice_GetImage3dMaxHeight,
DPCTLDevice_GetImage3dMaxWidth,
DPCTLDevice_GetLocalMemSize,
DPCTLDevice_GetMaxClockFrequency,
DPCTLDevice_GetMaxComputeUnits,
DPCTLDevice_GetMaxMemAllocSize,
DPCTLDevice_GetMaxNumSubGroups,
DPCTLDevice_GetMaxReadImageArgs,
DPCTLDevice_GetMaxWorkGroupSize,
DPCTLDevice_GetMaxWorkItemDims,
DPCTLDevice_GetMaxWorkItemSizes1d,
DPCTLDevice_GetMaxWorkItemSizes2d,
DPCTLDevice_GetMaxWorkItemSizes3d,
DPCTLDevice_GetMaxWriteImageArgs,
DPCTLDevice_GetName,
DPCTLDevice_GetNativeVectorWidthChar,
DPCTLDevice_GetNativeVectorWidthDouble,
DPCTLDevice_GetNativeVectorWidthFloat,
DPCTLDevice_GetNativeVectorWidthHalf,
DPCTLDevice_GetNativeVectorWidthInt,
DPCTLDevice_GetNativeVectorWidthLong,
DPCTLDevice_GetNativeVectorWidthShort,
DPCTLDevice_GetParentDevice,
DPCTLDevice_GetPartitionMaxSubDevices,
DPCTLDevice_GetPlatform,
DPCTLDevice_GetPreferredVectorWidthChar,
DPCTLDevice_GetPreferredVectorWidthDouble,
DPCTLDevice_GetPreferredVectorWidthFloat,
DPCTLDevice_GetPreferredVectorWidthHalf,
DPCTLDevice_GetPreferredVectorWidthInt,
DPCTLDevice_GetPreferredVectorWidthLong,
DPCTLDevice_GetPreferredVectorWidthShort,
DPCTLDevice_GetProfilingTimerResolution,
DPCTLDevice_GetSubGroupIndependentForwardProgress,
DPCTLDevice_GetSubGroupSizes,
DPCTLDevice_GetVendor,
DPCTLDevice_HasAspect,
DPCTLDevice_Hash,
DPCTLDevice_IsAccelerator,
DPCTLDevice_IsCPU,
DPCTLDevice_IsGPU,
DPCTLDeviceMgr_GetDeviceInfoStr,
DPCTLDeviceMgr_GetPositionInDevices,
DPCTLDeviceMgr_GetRelativeId,
DPCTLDeviceSelector_Delete,
DPCTLDeviceSelector_Score,
DPCTLDeviceVector_Delete,
DPCTLDeviceVector_GetAt,
DPCTLDeviceVector_Size,
DPCTLDeviceVectorRef,
DPCTLFilterSelector_Create,
DPCTLSize_t_Array_Delete,
DPCTLSyclDeviceRef,
DPCTLSyclDeviceSelectorRef,
DPCTLSyclPlatformRef,
_aspect_type,
_backend_type,
_device_type,
_global_mem_cache_type,
_partition_affinity_domain_type,
_peer_access,
)
from .enum_types import backend_type, device_type, global_mem_cache_type
from libc.stdint cimport int64_t, uint32_t, uint64_t
from libc.stdlib cimport free, malloc
from ._sycl_platform cimport SyclPlatform
import collections
import functools
import warnings
__all__ = [
"SyclDevice", "SyclDeviceCreationError", "SyclSubDeviceCreationError",
]
cdef class SyclDeviceCreationError(Exception):
"""
A ``SyclDeviceCreationError`` exception is raised when
:class:`.SyclDevice` instance could not be created.
"""
pass
cdef class SyclSubDeviceCreationError(Exception):
"""
A ``SyclSubDeviceCreationError`` exception is raised
by :meth:`.SyclDevice.create_sub_devices` when
:class:`.SyclDevice` instance could not be partitioned
into sub-devices.
"""
pass
cdef class _SyclDevice:
"""
A helper data-owner class to abstract ``sycl::device``
instance.
"""
def __dealloc__(self):
DPCTLDevice_Delete(self._device_ref)
DPCTLCString_Delete(self._name)
DPCTLCString_Delete(self._vendor)
DPCTLCString_Delete(self._driver_version)
DPCTLSize_t_Array_Delete(self._max_work_item_sizes)
cdef list _get_devices(DPCTLDeviceVectorRef DVRef):
"""
Deletes DVRef. Pass a copy in case an original reference is needed.
"""
cdef list devices = []
cdef size_t nelems = 0
if DVRef:
nelems = DPCTLDeviceVector_Size(DVRef)
for i in range(0, nelems):
DRef = DPCTLDeviceVector_GetAt(DVRef, i)
D = SyclDevice._create(DRef)
devices.append(D)
DPCTLDeviceVector_Delete(DVRef)
return devices
cdef str _backend_type_to_filter_string_part(_backend_type BTy):
if BTy == _backend_type._CUDA:
return "cuda"
elif BTy == _backend_type._HIP:
return "hip"
elif BTy == _backend_type._LEVEL_ZERO:
return "level_zero"
elif BTy == _backend_type._OPENCL:
return "opencl"
else:
return "unknown"
cdef str _device_type_to_filter_string_part(_device_type DTy):
if DTy == _device_type._ACCELERATOR:
return "accelerator"
elif DTy == _device_type._AUTOMATIC:
return "automatic"
elif DTy == _device_type._CPU:
return "cpu"
elif DTy == _device_type._GPU:
return "gpu"
else:
return "unknown"
cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef) except *:
"Populate attributes of device from opaque device reference DRef"
device._device_ref = DRef
device._name = DPCTLDevice_GetName(DRef)
if device._name is NULL:
raise RuntimeError("Descriptor 'name' not available")
device._driver_version = DPCTLDevice_GetDriverVersion(DRef)
if device._driver_version is NULL:
raise RuntimeError("Descriptor 'driver_version' not available")
device._vendor = DPCTLDevice_GetVendor(DRef)
if device._vendor is NULL:
raise RuntimeError("Descriptor 'vendor' not available")
device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes3d(DRef)
if device._max_work_item_sizes is NULL:
raise RuntimeError("Descriptor 'max_work_item_sizes3d' not available")
cdef inline bint _check_peer_access(SyclDevice dev, SyclDevice peer) except *:
"""
Check peer access ahead of time to avoid errors from unified runtime or
compiler implementation.
"""
cdef list _peer_access_backends = [
_backend_type._CUDA,
_backend_type._HIP,
_backend_type._LEVEL_ZERO
]
cdef _backend_type BTy1 = DPCTLDevice_GetBackend(dev._device_ref)
cdef _backend_type BTy2 = DPCTLDevice_GetBackend(peer.get_device_ref())
if (
BTy1 == BTy2 and
BTy1 in _peer_access_backends and
BTy2 in _peer_access_backends and
dev != peer
):
return True
return False
cdef inline void _raise_invalid_peer_access(
SyclDevice dev,
SyclDevice peer,
) except *:
"""
Check peer access ahead of time and raise errors for invalid cases.
"""
cdef list _peer_access_backends = [
_backend_type._CUDA,
_backend_type._HIP,
_backend_type._LEVEL_ZERO
]
cdef _backend_type BTy1 = DPCTLDevice_GetBackend(dev._device_ref)
cdef _backend_type BTy2 = DPCTLDevice_GetBackend(peer.get_device_ref())
if (BTy1 != BTy2):
raise ValueError(
f"Device with backend {_backend_type_to_filter_string_part(BTy1)} "
"cannot peer access device with backend "
f"{_backend_type_to_filter_string_part(BTy2)}"
)
if (BTy1 not in _peer_access_backends):
raise ValueError(
"Peer access not supported for backend "
f"{_backend_type_to_filter_string_part(BTy1)}"
)
if (BTy2 not in _peer_access_backends):
raise ValueError(
"Peer access not supported for backend "
f"{_backend_type_to_filter_string_part(BTy2)}"
)
if (dev == peer):
raise ValueError(
"Peer access cannot be enabled between a device and itself"
)
return
@functools.lru_cache(maxsize=None)
def _cached_filter_string(d : SyclDevice):
"""
Internal utility to compute filter_string of input SyclDevice
and cached with `functools.cache`.
Args:
d (:class:`dpctl.SyclDevice`):
A device for which to compute the filter string.
Returns:
out(str):
Filter string that can be used to create input device,
if the device is a root (unpartitioned) device.
Raises:
ValueError: if the input device is a sub-device.
"""
cdef _backend_type BTy
cdef _device_type DTy
cdef int64_t relId = -1
cdef SyclDevice cd = <SyclDevice> d
relId = DPCTLDeviceMgr_GetRelativeId(cd._device_ref)
if (relId == -1):
raise ValueError("This SyclDevice is not a root device")
BTy = DPCTLDevice_GetBackend(cd._device_ref)
br_str = _backend_type_to_filter_string_part(BTy)
DTy = DPCTLDevice_GetDeviceType(cd._device_ref)
dt_str = _device_type_to_filter_string_part(DTy)
return ":".join((br_str, dt_str, str(relId)))
cdef class SyclDevice(_SyclDevice):
""" SyclDevice(arg=None)
A Python wrapper for the ``sycl::device`` C++ class.
There are two ways of creating a SyclDevice instance:
- by directly passing in a filter string to the class
constructor. The filter string needs to conform to the
:oneapi_filter_selection:`DPC++ filter selector SYCL extension <>`.
:Example:
.. code-block:: python
import dpctl
# Create a SyclDevice with an explicit filter string,
# in this case the first level_zero gpu device.
level_zero_gpu = dpctl.SyclDevice("level_zero:gpu:0")
level_zero_gpu.print_device_info()
- by calling one of the device selector helper functions:
:py:func:`dpctl.select_accelerator_device()`,
:py:func:`dpctl.select_cpu_device()`,
:py:func:`dpctl.select_default_device()`,
:py:func:`dpctl.select_gpu_device()`
:Example:
.. code-block:: python
import dpctl
# Create a SyclDevice of type GPU based on whatever is returned
# by the SYCL `gpu_selector` device selector class.
gpu = dpctl.select_gpu_device()
gpu.print_device_info()
Args:
arg (str, optional):
The argument can be a selector string, another
:class:`dpctl.SyclDevice`, or ``None``.
Defaults to ``None``.
Raises:
MemoryError:
If the constructor could not allocate necessary
temporary memory.
SyclDeviceCreationError:
If the :class:`dpctl.SyclDevice` object creation failed.
TypeError:
If the argument is not a :class:`dpctl.SyclDevice` or string.
"""
@staticmethod
cdef SyclDevice _create(DPCTLSyclDeviceRef dref):
"""
This function calls DPCTLDevice_Delete(dref).
The user of this function must pass a copy to keep the
dref argument alive.
"""
cdef _SyclDevice ret = _SyclDevice.__new__(_SyclDevice)
# Initialize the attributes of the SyclDevice object
_init_helper(<_SyclDevice> ret, dref)
# ret is a temporary, and _SyclDevice.__dealloc__ will delete dref
return SyclDevice(ret)
cdef int _init_from__SyclDevice(self, _SyclDevice other):
self._device_ref = DPCTLDevice_Copy(other._device_ref)
if (self._device_ref is NULL):
return -1
self._name = DPCTLDevice_GetName(self._device_ref)
self._driver_version = DPCTLDevice_GetDriverVersion(self._device_ref)
self._max_work_item_sizes = (
DPCTLDevice_GetMaxWorkItemSizes3d(self._device_ref)
)
self._vendor = DPCTLDevice_GetVendor(self._device_ref)
return 0
cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef):
# Initialize the attributes of the SyclDevice object
cdef DPCTLSyclDeviceRef DRef = DPCTLDevice_CreateFromSelector(DSRef)
# Free up the device selector
DPCTLDeviceSelector_Delete(DSRef)
if DRef is NULL:
return -1
else:
_init_helper(self, DRef)
return 0
def __cinit__(self, arg=None):
cdef DPCTLSyclDeviceSelectorRef DSRef = NULL
cdef const char *filter_c_str = NULL
cdef int ret = 0
if type(arg) is str:
string = bytes(<str>arg, "utf-8")
filter_c_str = string
DSRef = DPCTLFilterSelector_Create(filter_c_str)
ret = self._init_from_selector(DSRef)
if ret == -1:
raise SyclDeviceCreationError(
"Could not create a SyclDevice with the selector string "
"'{selector_string}'".format(selector_string=arg)
)
elif isinstance(arg, _SyclDevice):
ret = self._init_from__SyclDevice(arg)
if ret == -1:
raise SyclDeviceCreationError(
"Could not create a SyclDevice from _SyclDevice instance"
)
elif arg is None:
DSRef = DPCTLDefaultSelector_Create()
ret = self._init_from_selector(DSRef)
if ret == -1:
raise SyclDeviceCreationError(
"Could not create a SyclDevice from default selector"
)
else:
raise TypeError(
"Invalid argument. Argument should be a str object specifying "
"a SYCL filter selector string or another SyclDevice."
)
def print_device_info(self):
"""
Print information about the SYCL device.
"""
cdef const char * info_str = DPCTLDeviceMgr_GetDeviceInfoStr(
self._device_ref
)
py_info = <bytes> info_str
DPCTLCString_Delete(info_str)
print(py_info.decode("utf-8"))
cdef DPCTLSyclDeviceRef get_device_ref(self):
"""
Returns the :c:struct:`DPCTLSyclDeviceRef` pointer for this class.
"""
return self._device_ref
def addressof_ref(self):
"""
Returns the address of the :c:struct:`DPCTLSyclDeviceRef` pointer as a
``size_t``.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> hex(dev.addressof_ref())
'0x55b18ec649d0'
Returns:
int: The address of the :c:struct:`DPCTLSyclDeviceRef` object used
to create this :class:`dpctl.SyclDevice` cast to a ``size_t``.
"""
return <size_t>self._device_ref
@property
def backend(self):
"""Returns the ``backend_type`` enum value for this device
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.backend
<backend_type.opencl: 4>
Returns:
backend_type:
The backend for the device.
"""
cdef _backend_type BTy = (
DPCTLDevice_GetBackend(self._device_ref)
)
if BTy == _backend_type._CUDA:
return backend_type.cuda
elif BTy == _backend_type._HIP:
return backend_type.hip
elif BTy == _backend_type._LEVEL_ZERO:
return backend_type.level_zero
elif BTy == _backend_type._OPENCL:
return backend_type.opencl
else:
raise ValueError("Unknown backend type.")
@property
def device_type(self):
""" Returns the type of the device as a ``device_type`` enum.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.device_type
<device_type.cpu: 4>
Returns:
device_type:
The type of device encoded as a ``device_type`` enum.
Raises:
ValueError:
If the device type is not recognized.
"""
cdef _device_type DTy = (
DPCTLDevice_GetDeviceType(self._device_ref)
)
if DTy == _device_type._ACCELERATOR:
return device_type.accelerator
elif DTy == _device_type._AUTOMATIC:
return device_type.automatic
elif DTy == _device_type._CPU:
return device_type.cpu
elif DTy == _device_type._GPU:
return device_type.gpu
else:
raise ValueError("Unknown device type.")
@property
def has_aspect_cpu(self):
""" Returns ``True`` if this device is a CPU device,
``False`` otherwise.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_cpu
True
Returns:
bool:
Indicates whether the device is a cpu.
"""
cdef _aspect_type AT = _aspect_type._cpu
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_gpu(self):
""" Returns ``True`` if this device is a GPU device,
``False`` otherwise.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_gpu
False
Returns:
bool:
Indicates whether the device is a gpu.
"""
cdef _aspect_type AT = _aspect_type._gpu
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_accelerator(self):
""" Returns ``True`` if this device is an accelerator device,
``False`` otherwise.
SYCL considers an accelerator to be a device that usually uses a
peripheral interconnect for communication.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_accelerator
False
Returns:
bool:
Indicates whether the device is an accelerator.
"""
cdef _aspect_type AT = _aspect_type._accelerator
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_custom(self):
""" Returns ``True`` if this device is a custom device,
``False`` otherwise.
A custom device can be a dedicated accelerator that can use the
SYCL API, but programmable kernels cannot be dispatched to the device,
only fixed functionality is available. Refer SYCL spec for more details.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_custom
False
Returns:
bool:
Indicates if the device is a custom SYCL device.
"""
cdef _aspect_type AT = _aspect_type._custom
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_fp16(self):
""" Returns ``True`` if the device supports half-precision floating
point operations, ``False`` otherwise.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_fp16
True
Returns:
bool:
Indicates that the device supports half precision floating
point operations.
"""
cdef _aspect_type AT = _aspect_type._fp16
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_fp64(self):
""" Returns ``True`` if the device supports 64-bit precision floating
point operations, ``False`` otherwise.
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_fp64
True
Returns:
bool:
Indicates that the device supports 64-bit precision floating
point operations.
"""
cdef _aspect_type AT = _aspect_type._fp64
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_atomic64(self):
""" Returns ``True`` if the device supports a basic set of atomic
operations, ``False`` otherwise.
Indicates that the device supports the following atomic operations on
64-bit values:
- ``sycl::atomic_ref::load``
- ``sycl::atomic_ref::store``
- ``sycl::atomic_ref::fetch_add``
- ``sycl::atomic_ref::fetch_sub``
- ``sycl::atomic_ref::exchange``
- ``sycl::atomic_ref::compare_exchange_strong``
- ``sycl::atomic_ref::compare_exchange_weak``
:Example:
.. code-block:: python
>>> import dpctl
>>> dev = dpctl.select_cpu_device()
>>> dev.has_aspect_atomic64
True
Returns:
bool:
Indicates that the device supports a basic set of atomic
operations on 64-bit values.
"""
cdef _aspect_type AT = _aspect_type._atomic64
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_image(self):
""" Returns ``True`` if the device supports images, ``False`` otherwise
(refer Sec 4.15.3 of SYCL 2020 spec).
Returns:
bool:
Indicates that the device supports images
"""
cdef _aspect_type AT = _aspect_type._image
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_online_compiler(self):
""" Returns ``True`` if this device supports online compilation of
device code, ``False`` otherwise.
Returns:
bool:
Indicates that the device supports online compilation of
device code.
"""
cdef _aspect_type AT = _aspect_type._online_compiler
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_online_linker(self):
""" Returns ``True`` if this device supports online linking of
device code, ``False`` otherwise.
Returns:
bool:
Indicates that the device supports online linking of device
code.
"""
cdef _aspect_type AT = _aspect_type._online_linker
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_queue_profiling(self):
""" Returns ``True`` if this device supports queue profiling,
``False`` otherwise.
Returns:
bool:
Indicates that the device supports queue profiling.
"""
cdef _aspect_type AT = _aspect_type._queue_profiling
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_usm_device_allocations(self):
""" Returns ``True`` if this device supports explicit USM allocations,
``False`` otherwise (refer Section 4.8 of SYCL 2020 specs).
Returns:
bool:
Indicates that the device supports explicit USM allocations.
"""
cdef _aspect_type AT = _aspect_type._usm_device_allocations
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_usm_host_allocations(self):
""" Returns ``True`` if this device can access USM-host memory,
``False`` otherwise (refer Section 4.8 of SYCL 2020 specs).
Returns:
bool:
Indicates that the device can access USM memory
allocated using ``sycl::malloc_host``.
"""
cdef _aspect_type AT = _aspect_type._usm_host_allocations
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_usm_shared_allocations(self):
""" Returns ``True`` if this device supports USM-shared memory
allocated on the same device, ``False`` otherwise.
Returns:
bool:
Indicates that the device supports USM memory
allocated using ``sycl::malloc_shared``.
"""
cdef _aspect_type AT = _aspect_type._usm_shared_allocations
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_usm_system_allocations(self):
""" Returns ``True`` if system allocator may be used instead of
SYCL USM allocation mechanism for USM-shared allocations on this
device, ``False`` otherwise.
Returns:
bool:
Indicates that system allocator may be used instead of
``sycl::malloc_shared``.
"""
cdef _aspect_type AT = _aspect_type._usm_system_allocations
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_usm_atomic_host_allocations(self):
""" Returns ``True`` if this device supports USM-host allocations
and the host and this device may concurrently access and atomically
modify host allocations, ``False`` otherwise.
Returns:
bool:
Indicates if the device supports USM atomic host allocations.
"""
cdef _aspect_type AT = _aspect_type._usm_atomic_host_allocations
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_usm_atomic_shared_allocations(self):
""" Returns ``True`` if this device supports USM-shared allocations
and the host and other devices in the same context as this device may
concurrently access and atomically modify shared allocations,
``False`` otherwise.
Returns:
bool:
Indicates if this device supports concurrent atomic modification
of USM-shared allocation by host and device.
"""
cdef _aspect_type AT = _aspect_type._usm_atomic_shared_allocations
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_host_debuggable(self):
""" Returns ``True`` if kernels running on this device can be debugged
using standard debuggers that are normally available on the host
system, ``False`` otherwise.
Returns:
bool:
Indicates if host debugger may be used to debug device code.
"""
cdef _aspect_type AT = _aspect_type._host_debuggable
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_emulated(self):
""" Returns ``True`` if this device is somehow emulated, ``False``
otherwise. A device with this aspect is not intended for performance,
and instead will generally have another purpose such as emulation
or profiling.
Returns:
bool:
Indicates if device is somehow emulated.
"""
cdef _aspect_type AT = _aspect_type._emulated
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_is_component(self):
""" Returns ``True`` if this device is a component device, ``False``
otherwise. A device with this aspect will have a composite device
from which it is descended.
Returns:
bool:
Indicates if device is a component device.
"""
cdef _aspect_type AT = _aspect_type._is_component
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def has_aspect_is_composite(self):
""" Returns ``True`` if this device is a composite device, ``False``
otherwise. A device with this aspect contains component devices.
Returns:
bool:
Indicates if device is a composite device.
"""
cdef _aspect_type AT = _aspect_type._is_composite
return DPCTLDevice_HasAspect(self._device_ref, AT)
@property
def image_2d_max_width(self):
""" Returns the maximum width of a 2D image or 1D image in pixels.
The minimum value is 8192 if the SYCL device has
``sycl::aspect::image``.
Returns:
int:
Maximum width of a 2D image or 1D image in pixels.
"""
return DPCTLDevice_GetImage2dMaxWidth(self._device_ref)
@property
def image_2d_max_height(self):
""" Returns the maximum height of a 2D image or 1D image in pixels.
The minimum value is 8192 if the SYCL device has
``sycl::aspect::image``.
Returns:
int:
Maximum height of a 2D image or 1D image in pixels.
"""
return DPCTLDevice_GetImage2dMaxHeight(self._device_ref)
@property
def image_3d_max_width(self):
""" Returns the maximum width of a 3D image in pixels.
The minimum value is 2048 if the SYCL device has
``sycl::aspect::image``.
Returns:
int:
Maximum width of a 3D image in pixels.
"""
return DPCTLDevice_GetImage3dMaxWidth(self._device_ref)
@property
def image_3d_max_height(self):
""" Returns the maximum height of a 3D image in pixels.
The minimum value is 2048 if the SYCL device has
``sycl::aspect::image``.
Returns:
int:
Maximum height of a 3D image in pixels.
"""
return DPCTLDevice_GetImage3dMaxHeight(self._device_ref)
@property
def image_3d_max_depth(self):
""" Returns the maximum depth of a 3D image in pixels.
The minimum value is 2048 if the SYCL device has
``sycl::aspect::image``.
Returns:
int:
Maximum depth of a 3D image in pixels.
"""
return DPCTLDevice_GetImage3dMaxDepth(self._device_ref)
@property
def default_selector_score(self):
""" Integral score assigned to this device by DPC++ runtime's default
selector's scoring function. Score of -1 denotes that this device
was rejected and may not be properly programmed by the DPC++ runtime.
Returns:
int:
Score assign to this device by ``sycl::default_selector_v``
function.
"""
cdef DPCTLSyclDeviceSelectorRef DSRef = DPCTLDefaultSelector_Create()
cdef int score = -1
if (DSRef):
score = DPCTLDeviceSelector_Score(DSRef, self._device_ref)
DPCTLDeviceSelector_Delete(DSRef)
return score
@property
def max_read_image_args(self):
""" Returns the maximum number of simultaneous image objects that
can be read from by a kernel. The minimum value is 128 if the
SYCL device has ``sycl::aspect::image``.
Returns:
int:
Maximum number of image objects that can be read from by
a kernel.
"""
return DPCTLDevice_GetMaxReadImageArgs(self._device_ref)
@property
def max_write_image_args(self):
""" Returns the maximum number of simultaneous image objects that
can be written to by a kernel. The minimum value is 8 if the SYCL
device has ``sycl::aspect::image``.
Return:
int:
Maximum number of simultaneous image objects that
can be written to by a kernel.
"""
return DPCTLDevice_GetMaxWriteImageArgs(self._device_ref)
@property
def is_accelerator(self):
""" Returns ``True`` if this instance is a SYCL
accelerator device.
Returns:
bool:
``True`` if the :class:`.SyclDevice` is a SYCL accelerator
device, else ``False``.