Skip to content

Commit 76f2fc2

Browse files
committed
Add composite device related attributes to dpctl.SyclDevice
1 parent 6c79e90 commit 76f2fc2

File tree

6 files changed

+157
-1
lines changed

6 files changed

+157
-1
lines changed

dpctl/_backend.pxd

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
9797
_usm_atomic_shared_allocations 'usm_atomic_shared_allocations',
9898
_host_debuggable 'host_debuggable',
9999
_emulated 'emulated',
100+
_is_component 'is_component',
101+
_is_composite 'is_composite',
100102

101103
ctypedef enum _partition_affinity_domain_type 'DPCTLPartitionAffinityDomainType':
102104
_not_applicable 'not_applicable',
@@ -216,6 +218,8 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
216218
cdef uint32_t DPCTLDevice_GetPartitionMaxSubDevices(const DPCTLSyclDeviceRef DRef)
217219
cdef uint32_t DPCTLDevice_GetMaxClockFrequency(const DPCTLSyclDeviceRef DRef)
218220
cdef uint64_t DPCTLDevice_GetMaxMemAllocSize(const DPCTLSyclDeviceRef DRef)
221+
cdef DPCTLSyclDeviceRef DPCTLDevice_GetCompositeDevice(const DPCTLSyclDeviceRef DRef)
222+
cdef DPCTLDeviceVectorRef DPCTLDevice_GetComponentDevices(const DPCTLSyclDeviceRef DRef)
219223

220224

221225
cdef extern from "syclinterface/dpctl_sycl_device_manager.h":

dpctl/_sycl_device.pyx

+63
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ from ._backend cimport ( # noqa: E211
3232
DPCTLDevice_CreateSubDevicesEqually,
3333
DPCTLDevice_Delete,
3434
DPCTLDevice_GetBackend,
35+
DPCTLDevice_GetComponentDevices,
36+
DPCTLDevice_GetCompositeDevice,
3537
DPCTLDevice_GetDeviceType,
3638
DPCTLDevice_GetDriverVersion,
3739
DPCTLDevice_GetGlobalMemCacheLineSize,
@@ -795,6 +797,32 @@ cdef class SyclDevice(_SyclDevice):
795797
cdef _aspect_type AT = _aspect_type._emulated
796798
return DPCTLDevice_HasAspect(self._device_ref, AT)
797799

800+
@property
801+
def is_component(self):
802+
""" Returns ``True`` if this device is a component device, ``False``
803+
otherwise. A device with this aspect will have a composite device
804+
from which it is descended.
805+
806+
Returns:
807+
bool:
808+
Indicates if device is a component device.
809+
"""
810+
cdef _aspect_type AT = _aspect_type._is_component
811+
return DPCTLDevice_HasAspect(self._device_ref, AT)
812+
813+
814+
@property
815+
def is_composite(self):
816+
""" Returns ``True`` if this device is a composite device, ``False``
817+
otherwise. A device with this aspect contains component devices.
818+
819+
Returns:
820+
bool:
821+
Indicates if device is a composite device.
822+
"""
823+
cdef _aspect_type AT = _aspect_type._is_composite
824+
return DPCTLDevice_HasAspect(self._device_ref, AT)
825+
798826
@property
799827
def image_2d_max_width(self):
800828
""" Returns the maximum width of a 2D image or 1D image in pixels.
@@ -1728,6 +1756,41 @@ cdef class SyclDevice(_SyclDevice):
17281756
return None
17291757
return SyclDevice._create(pDRef)
17301758

1759+
@property
1760+
def composite_device(self):
1761+
""" The composite device for a component device, or None for a non-component device.
1762+
1763+
Returns:
1764+
dpctl.SyclDevice:
1765+
The composite :class:`dpctl.SyclDevice` instance for a
1766+
component device, or ``None`` for a non-component device.
1767+
"""
1768+
cdef DPCTLSyclDeviceRef cDRef = NULL
1769+
cDRef = DPCTLDevice_GetCompositeDevice(self._device_ref)
1770+
if (cDRef is NULL):
1771+
return None
1772+
return SyclDevice._create(cDRef)
1773+
1774+
def component_devices(self):
1775+
""" Returns a list of component devices contained in this SYCL device.
1776+
1777+
The returned list will be empty if this SYCL device is not a composite
1778+
device, i.e., if `is_composite` is ``False``.
1779+
1780+
Returns:
1781+
List[:class:`dpctl.SyclDevice`]:
1782+
List of component devices.
1783+
1784+
Raises:
1785+
dpctl.SyclSubdeviceCreationError:
1786+
if sub-devices can not be created.
1787+
"""
1788+
cdef DPCTLDeviceVectorRef cDVRef = NULL
1789+
cDVRef = DPCTLDevice_GetComponentDevices(self._device_ref)
1790+
if cDVRef is NULL:
1791+
raise ValueError("Internal error: NULL device vector encountered")
1792+
return _get_devices(cDVRef)
1793+
17311794
@property
17321795
def profiling_timer_resolution(self):
17331796
""" Profiling timer resolution.

libsyclinterface/helper/source/dpctl_utils_helper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
335335
return aspect::host_debuggable;
336336
case DPCTLSyclAspectType::emulated:
337337
return aspect::emulated;
338+
case DPCTLSyclAspectType::is_component:
339+
return aspect::ext_oneapi_is_component;
340+
case DPCTLSyclAspectType::is_composite:
341+
return aspect::ext_oneapi_is_composite;
338342
default:
339343
throw std::runtime_error("Unsupported aspect type");
340344
}
@@ -381,6 +385,10 @@ DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
381385
return DPCTLSyclAspectType::host_debuggable;
382386
case aspect::emulated:
383387
return DPCTLSyclAspectType::emulated;
388+
case aspect::ext_oneapi_is_composite:
389+
return DPCTLSyclAspectType::is_composite;
390+
case aspect::ext_oneapi_is_component:
391+
return DPCTLSyclAspectType::is_component;
384392
default:
385393
throw std::runtime_error("Unsupported aspect type");
386394
}

libsyclinterface/include/syclinterface/dpctl_sycl_device_interface.h

+26
Original file line numberDiff line numberDiff line change
@@ -766,4 +766,30 @@ __dpctl_keep size_t *
766766
DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
767767
size_t *res_len);
768768

769+
/*!
770+
* @brief Wrapper over
771+
* device.get_info<info::device::parent_device>
772+
*
773+
* @param DRef Opaque pointer to a sycl::device
774+
* @return Returns an opaque pointer to the composite device for a
775+
* component device, or nullptr if the device is not a component device.
776+
*/
777+
DPCTL_API
778+
__dpctl_give DPCTLSyclDeviceRef
779+
DPCTLDevice_GetCompositeDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef);
780+
781+
/*!
782+
* @brief Returns a vector of component devices that are contained by the
783+
* provided composite device. If the device is not a composite device,
784+
* returns an empty vector.
785+
*
786+
* @param DRef Opaque pointer to a ``sycl::device``
787+
* @return A #DPCTLDeviceVectorRef containing component
788+
* #DPCTLSyclDeviceRef objects
789+
* @ingroup DeviceInterface
790+
*/
791+
DPCTL_API
792+
__dpctl_give DPCTLDeviceVectorRef
793+
DPCTLDevice_GetComponentDevices(__dpctl_keep const DPCTLSyclDeviceRef DRef);
794+
769795
DPCTL_C_EXTERN_C_END

libsyclinterface/include/syclinterface/dpctl_sycl_enum_types.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ typedef enum
129129
usm_atomic_host_allocations,
130130
usm_atomic_shared_allocations,
131131
host_debuggable,
132-
emulated
132+
emulated,
133+
is_component,
134+
is_composite
133135
} DPCTLSyclAspectType;
134136

135137
/*!

libsyclinterface/source/dpctl_sycl_device_interface.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -849,3 +849,56 @@ DPCTLDevice_GetSubGroupSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef,
849849
}
850850
return sizes;
851851
}
852+
853+
__dpctl_give DPCTLDeviceVectorRef
854+
DPCTLDevice_GetComponentDevices(__dpctl_keep const DPCTLSyclDeviceRef DRef)
855+
{
856+
using vecTy = std::vector<DPCTLSyclDeviceRef>;
857+
vecTy *ComponentDevicesVectorPtr = nullptr;
858+
if (DRef) {
859+
auto D = unwrap<device>(DRef);
860+
try {
861+
auto componentDevices =
862+
D->get_info<sycl::ext::oneapi::experimental::info::device::
863+
component_devices>();
864+
ComponentDevicesVectorPtr = new vecTy();
865+
for (const auto &cd : componentDevices) {
866+
ComponentDevicesVectorPtr->emplace_back(
867+
wrap<device>(new device(cd)));
868+
}
869+
} catch (std::exception const &e) {
870+
delete ComponentDevicesVectorPtr;
871+
error_handler(e, __FILE__, __func__, __LINE__);
872+
return nullptr;
873+
}
874+
}
875+
return wrap<vecTy>(ComponentDevicesVectorPtr);
876+
}
877+
878+
__dpctl_give DPCTLSyclDeviceRef
879+
DPCTLDevice_GetCompositeDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
880+
{
881+
auto D = unwrap<device>(DRef);
882+
if (D) {
883+
bool is_component = false;
884+
try {
885+
is_component = D->has(sycl::aspect::ext_oneapi_is_component);
886+
} catch (std::exception const &e) {
887+
error_handler(e, __FILE__, __func__, __LINE__);
888+
return nullptr;
889+
}
890+
if (!is_component)
891+
return nullptr;
892+
try {
893+
const auto &compositeDevice =
894+
D->get_info<sycl::ext::oneapi::experimental::info::device::
895+
composite_device>();
896+
return wrap<device>(new device(compositeDevice));
897+
} catch (std::exception const &e) {
898+
error_handler(e, __FILE__, __func__, __LINE__);
899+
return nullptr;
900+
}
901+
}
902+
else
903+
return nullptr;
904+
}

0 commit comments

Comments
 (0)