@@ -26,6 +26,10 @@ from libcpp cimport bool
2626from ._backend cimport ( # noqa: E211
2727 DPCTLCString_Delete,
2828 DPCTLDeviceSelector_Delete,
29+ DPCTLDeviceVector_Delete,
30+ DPCTLDeviceVector_GetAt,
31+ DPCTLDeviceVector_Size,
32+ DPCTLDeviceVectorRef,
2933 DPCTLFilterSelector_Create,
3034 DPCTLPlatform_AreEq,
3135 DPCTLPlatform_Copy,
@@ -34,6 +38,7 @@ from ._backend cimport ( # noqa: E211
3438 DPCTLPlatform_Delete,
3539 DPCTLPlatform_GetBackend,
3640 DPCTLPlatform_GetDefaultContext,
41+ DPCTLPlatform_GetDevices,
3742 DPCTLPlatform_GetName,
3843 DPCTLPlatform_GetPlatforms,
3944 DPCTLPlatform_GetVendor,
@@ -46,17 +51,21 @@ from ._backend cimport ( # noqa: E211
4651 DPCTLPlatformVector_Size,
4752 DPCTLPlatformVectorRef,
4853 DPCTLSyclContextRef,
54+ DPCTLSyclDeviceRef,
4955 DPCTLSyclDeviceSelectorRef,
5056 DPCTLSyclPlatformRef,
5157 _backend_type,
58+ _device_type,
5259)
5360
5461import warnings
5562
5663from ._sycl_context import SyclContextCreationError
5764from .enum_types import backend_type
65+ from .enum_types import device_type as device_type_t
5866
5967from ._sycl_context cimport SyclContext
68+ from ._sycl_device cimport SyclDevice
6069
6170__all__ = [
6271 " get_platforms" ,
@@ -366,6 +375,79 @@ cdef class SyclPlatform(_SyclPlatform):
366375 """
367376 return DPCTLPlatform_Hash(self ._platform_ref)
368377
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+
369451
370452def lsplatform (verbosity = 0 ):
371453 """
0 commit comments