@@ -26,6 +26,10 @@ from libcpp cimport bool
26
26
from ._backend cimport ( # noqa: E211
27
27
DPCTLCString_Delete,
28
28
DPCTLDeviceSelector_Delete,
29
+ DPCTLDeviceVector_Delete,
30
+ DPCTLDeviceVector_GetAt,
31
+ DPCTLDeviceVector_Size,
32
+ DPCTLDeviceVectorRef,
29
33
DPCTLFilterSelector_Create,
30
34
DPCTLPlatform_AreEq,
31
35
DPCTLPlatform_Copy,
@@ -34,6 +38,7 @@ from ._backend cimport ( # noqa: E211
34
38
DPCTLPlatform_Delete,
35
39
DPCTLPlatform_GetBackend,
36
40
DPCTLPlatform_GetDefaultContext,
41
+ DPCTLPlatform_GetDevices,
37
42
DPCTLPlatform_GetName,
38
43
DPCTLPlatform_GetPlatforms,
39
44
DPCTLPlatform_GetVendor,
@@ -46,17 +51,21 @@ from ._backend cimport ( # noqa: E211
46
51
DPCTLPlatformVector_Size,
47
52
DPCTLPlatformVectorRef,
48
53
DPCTLSyclContextRef,
54
+ DPCTLSyclDeviceRef,
49
55
DPCTLSyclDeviceSelectorRef,
50
56
DPCTLSyclPlatformRef,
51
57
_backend_type,
58
+ _device_type,
52
59
)
53
60
54
61
import warnings
55
62
56
63
from ._sycl_context import SyclContextCreationError
57
64
from .enum_types import backend_type
65
+ from .enum_types import device_type as device_type_t
58
66
59
67
from ._sycl_context cimport SyclContext
68
+ from ._sycl_device cimport SyclDevice
60
69
61
70
__all__ = [
62
71
" get_platforms" ,
@@ -366,6 +375,92 @@ cdef class SyclPlatform(_SyclPlatform):
366
375
"""
367
376
return DPCTLPlatform_Hash(self ._platform_ref)
368
377
378
+ def get_devices (self , device_type = device_type_t.all):
379
+ """
380
+ Returns the list of :class:`dpctl.SyclDevice` objects associated with
381
+ :class:`dpctl.SyclPlatform` instance selected based on
382
+ the given :class:`dpctl.device_type`.
383
+
384
+ Args:
385
+ device_type (optional):
386
+ A :class:`dpctl.device_type` enum value or a string that
387
+ specifies a SYCL device type. Currently, accepted values are:
388
+ "gpu", "cpu", "accelerator", "host", or "all".
389
+ Default: ``dpctl.device_type.all``.
390
+
391
+ Returns:
392
+ list:
393
+ A :obj:`list` of :class:`dpctl.SyclDevice` objects
394
+ that belong to this platform.
395
+
396
+ Raises:
397
+ TypeError:
398
+ If `device_type` is not a str or :class:`dpctl.device_type`
399
+ enum.
400
+ ValueError:
401
+ If the value of `device_type` is not supported.
402
+
403
+ If the ``DPCTLPlatform_GetDevices`` call returned
404
+ ``NULL`` instead of a ``DPCTLDeviceVectorRef`` object.
405
+ """
406
+ cdef _device_type DTy = _device_type._ALL_DEVICES
407
+ cdef DPCTLDeviceVectorRef DVRef = NULL
408
+ cdef size_t num_devs
409
+ cdef size_t i
410
+ cdef DPCTLSyclDeviceRef DRef
411
+
412
+ if isinstance (device_type, str ):
413
+ dty_str = device_type.strip().lower()
414
+ if dty_str == " accelerator" :
415
+ DTy = _device_type._ACCELERATOR
416
+ elif dty_str == " all" :
417
+ DTy = _device_type._ALL_DEVICES
418
+ elif dty_str == " automatic" :
419
+ DTy = _device_type._AUTOMATIC
420
+ elif dty_str == " cpu" :
421
+ DTy = _device_type._CPU
422
+ elif dty_str == " custom" :
423
+ DTy = _device_type._CUSTOM
424
+ elif dty_str == " gpu" :
425
+ DTy = _device_type._GPU
426
+ else :
427
+ raise ValueError (
428
+ " Unexpected value of `device_type`."
429
+ )
430
+ elif isinstance (device_type, device_type_t):
431
+ if device_type == device_type_t.all:
432
+ DTy = _device_type._ALL_DEVICES
433
+ elif device_type == device_type_t.accelerator:
434
+ DTy = _device_type._ACCELERATOR
435
+ elif device_type == device_type_t.automatic:
436
+ DTy = _device_type._AUTOMATIC
437
+ elif device_type == device_type_t.cpu:
438
+ DTy = _device_type._CPU
439
+ elif device_type == device_type_t.custom:
440
+ DTy = _device_type._CUSTOM
441
+ elif device_type == device_type_t.gpu:
442
+ DTy = _device_type._GPU
443
+ else :
444
+ raise ValueError (
445
+ " Unexpected value of `device_type`."
446
+ )
447
+ else :
448
+ raise TypeError (
449
+ " device type should be specified as a str or an "
450
+ " ``enum_types.device_type``."
451
+ )
452
+ DVRef = DPCTLPlatform_GetDevices(self .get_platform_ref(), DTy)
453
+ if (DVRef is NULL ):
454
+ raise ValueError (" Internal error: NULL device vector encountered" )
455
+ num_devs = DPCTLDeviceVector_Size(DVRef)
456
+ devices = []
457
+ for i in range (num_devs):
458
+ DRef = DPCTLDeviceVector_GetAt(DVRef, i)
459
+ devices.append(SyclDevice._create(DRef))
460
+ DPCTLDeviceVector_Delete(DVRef)
461
+
462
+ return devices
463
+
369
464
370
465
def lsplatform (verbosity = 0 ):
371
466
"""
0 commit comments