Skip to content

Commit 0f4f61e

Browse files
Added property parent_device
This returns None for root devices, but returns a SyclDevice for a sub-device. Added cpdef method equals, and Python method __eq__ ``` Python 3.7.9 (default, Mar 10 2021, 05:18:00) Type 'copyright', 'credits' or 'license' for more information IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import dpctl In [2]: cpu_device = dpctl.SyclDevice("cpu") In [3]: cpu_device == cpu_device Out[3]: True In [4]: cpu_device2 = dpctl.SyclDevice("cpu") In [5]: cpu_device == cpu_device2 Out[5]: True In [6]: [d1, d2, d3 ] =cpu_device.create_sub_devices(partition=4) In [7]: d1.parent_device == cpu_device Out[7]: True In [8]: d2.parent_device == cpu_device Out[8]: True In [9]: d3.parent_device == cpu_device Out[9]: True ```
1 parent f10dc20 commit 0f4f61e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

dpctl/_sycl_device.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ from ._backend cimport (
2525
DPCTLSyclDeviceSelectorRef,
2626
_partition_affinity_domain_type
2727
)
28+
from libcpp cimport bool as cpp_bool
2829

2930

3031
cdef class _SyclDevice:
31-
''' Wrapper class for a Sycl Device
32+
''' Wrapper data owner class for a Sycl Device
3233
'''
3334
cdef DPCTLSyclDeviceRef _device_ref
3435
cdef const char *_vendor_name
@@ -48,3 +49,4 @@ cdef class SyclDevice(_SyclDevice):
4849
cdef list create_sub_devices_equally(self, size_t count)
4950
cdef list create_sub_devices_by_counts(self, object counts)
5051
cdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain)
52+
cpdef cpp_bool equals(self, SyclDevice q)

dpctl/_sycl_device.pyx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ from ._backend cimport (
3434
DPCTLDeviceVector_Delete,
3535
DPCTLDeviceVector_GetAt,
3636
DPCTLDeviceVector_Size,
37+
DPCTLDevice_AreEq,
3738
DPCTLDevice_GetBackend,
3839
DPCTLDevice_GetDeviceType,
3940
DPCTLDevice_GetDriverInfo,
@@ -74,6 +75,7 @@ from ._backend cimport (
7475
DPCTLDevice_CreateSubDevicesEqually,
7576
DPCTLDevice_CreateSubDevicesByCounts,
7677
DPCTLDevice_CreateSubDevicesByAffinity,
78+
DPCTLDevice_GetParentDevice,
7779
)
7880
from . import backend_type, device_type
7981
from libc.stdint cimport uint32_t
@@ -96,7 +98,7 @@ cdef class SubDeviceCreationError(Exception):
9698

9799

98100
cdef class _SyclDevice:
99-
""" A helper metaclass to abstract a cl::sycl::device instance.
101+
""" A helper data-owner class to abstract a cl::sycl::device instance.
100102
"""
101103

102104
def __dealloc__(self):
@@ -714,3 +716,23 @@ cdef class SyclDevice(_SyclDevice):
714716
return self.create_sub_devices_equally(partition)
715717
except Exception as e:
716718
raise TypeError("Unsupported type of sub-device argument")
719+
720+
@property
721+
def parent_device(self):
722+
cdef DPCTLSyclDeviceRef pDRef = NULL
723+
pDRef = DPCTLDevice_GetParentDevice(self._device_ref)
724+
if (pDRef is NULL):
725+
return None
726+
return SyclDevice._create(pDRef)
727+
728+
cpdef cpp_bool equals(self, SyclDevice other):
729+
""" Returns true if the SyclDevice argument has the same _device_ref
730+
as this SyclDevice.
731+
"""
732+
return DPCTLDevice_AreEq(self._device_ref, other.get_device_ref())
733+
734+
def __eq__(self, other):
735+
if isinstance(other, SyclDevice):
736+
return self.equals(<SyclDevice> other)
737+
else:
738+
return False

0 commit comments

Comments
 (0)