@@ -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,79 @@ 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 (str, :class:`dpctl.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", or "all", and their equivalent
389
+ ``dpctl.device_type`` enumerators.
390
+ Default: ``dpctl.device_type.all``.
391
+
392
+ Returns:
393
+ list:
394
+ A :obj:`list` of :class:`dpctl.SyclDevice` objects
395
+ that belong to this platform.
396
+
397
+ Raises:
398
+ TypeError:
399
+ If `device_type` is not a string or :class:`dpctl.device_type`
400
+ enum.
401
+ ValueError:
402
+ If the ``DPCTLPlatform_GetDevices`` call returned
403
+ ``NULL`` instead of a ``DPCTLDeviceVectorRef`` object.
404
+ """
405
+ cdef _device_type DTy = _device_type._ALL_DEVICES
406
+ cdef DPCTLDeviceVectorRef DVRef = NULL
407
+ cdef size_t num_devs
408
+ cdef size_t i
409
+ cdef DPCTLSyclDeviceRef DRef
410
+
411
+ if isinstance (device_type, str ):
412
+ dty_str = device_type.strip().lower()
413
+ if dty_str == " accelerator" :
414
+ DTy = _device_type._ACCELERATOR
415
+ elif dty_str == " all" :
416
+ DTy = _device_type._ALL_DEVICES
417
+ elif dty_str == " cpu" :
418
+ DTy = _device_type._CPU
419
+ elif dty_str == " gpu" :
420
+ DTy = _device_type._GPU
421
+ else :
422
+ DTy = _device_type._UNKNOWN_DEVICE
423
+ elif isinstance (device_type, device_type_t):
424
+ if device_type == device_type_t.all:
425
+ DTy = _device_type._ALL_DEVICES
426
+ elif device_type == device_type_t.accelerator:
427
+ DTy = _device_type._ACCELERATOR
428
+ elif device_type == device_type_t.cpu:
429
+ DTy = _device_type._CPU
430
+ elif device_type == device_type_t.gpu:
431
+ DTy = _device_type._GPU
432
+ else :
433
+ DTy = _device_type._UNKNOWN_DEVICE
434
+ else :
435
+ raise TypeError (
436
+ " device type should be specified as a str or an "
437
+ " ``enum_types.device_type``."
438
+ )
439
+ DVRef = DPCTLPlatform_GetDevices(self .get_platform_ref(), DTy)
440
+ if (DVRef is NULL ):
441
+ raise ValueError (" Internal error: NULL device vector encountered" )
442
+ num_devs = DPCTLDeviceVector_Size(DVRef)
443
+ devices = []
444
+ for i in range (num_devs):
445
+ DRef = DPCTLDeviceVector_GetAt(DVRef, i)
446
+ devices.append(SyclDevice._create(DRef))
447
+ DPCTLDeviceVector_Delete(DVRef)
448
+
449
+ return devices
450
+
369
451
370
452
def lsplatform (verbosity = 0 ):
371
453
"""
0 commit comments