Skip to content

Static methods _init_helper made into functions #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dpctl/_sycl_context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ cdef public class SyclContext(_SyclContext) [object PySyclContextObject, type Py

@staticmethod
cdef SyclContext _create (DPCTLSyclContextRef CRef)
@staticmethod
cdef void _init_helper(_SyclContext self, DPCTLSyclContextRef CRef)
cdef int _init_context_from__SyclContext(self, _SyclContext other)
cdef int _init_context_from_one_device(self, SyclDevice device, int props)
cdef int _init_context_from_devices(self, object devices, int props)
Expand Down
16 changes: 8 additions & 8 deletions dpctl/_sycl_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ cdef void _context_capsule_deleter(object o):
DPCTLContext_Delete(CRef)


cdef void _init_helper(_SyclContext context, DPCTLSyclContextRef CRef):
"Populate context attributes from opaque reference CRef"
context._ctxt_ref = CRef


cdef class _SyclContext:
""" Data owner for SyclContext
"""
Expand Down Expand Up @@ -157,11 +162,6 @@ cdef class SyclContext(_SyclContext):
be renamed.

"""

@staticmethod
cdef void _init_helper(_SyclContext context, DPCTLSyclContextRef CRef):
context._ctxt_ref = CRef

@staticmethod
cdef SyclContext _create(DPCTLSyclContextRef ctxt):
"""
Expand All @@ -170,7 +170,7 @@ cdef class SyclContext(_SyclContext):
Users should pass a copy if they intend to keep the argument ctxt alive.
"""
cdef _SyclContext ret = <_SyclContext>_SyclContext.__new__(_SyclContext)
SyclContext._init_helper(ret, ctxt)
_init_helper(ret, ctxt)
return SyclContext(ret)

cdef int _init_context_from__SyclContext(self, _SyclContext other):
Expand All @@ -191,7 +191,7 @@ cdef class SyclContext(_SyclContext):
CRef = DPCTLContext_Create(DRef, eh_callback, props)
if (CRef is NULL):
return -1
SyclContext._init_helper(<_SyclContext> self, CRef)
_init_helper(<_SyclContext> self, CRef)
return 0

cdef int _init_context_from_devices(self, object devices, int props):
Expand Down Expand Up @@ -231,7 +231,7 @@ cdef class SyclContext(_SyclContext):
DPCTLDeviceVector_Delete(DVRef)
if (CRef is NULL):
return -1
SyclContext._init_helper(<_SyclContext> self, CRef)
_init_helper(<_SyclContext> self, CRef)
return 0

cdef int _init_context_from_capsule(self, object cap):
Expand Down
2 changes: 0 additions & 2 deletions dpctl/_sycl_device.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ cdef class _SyclDevice:
cdef public class SyclDevice(_SyclDevice) [object PySyclDeviceObject, type PySyclDeviceType]:
@staticmethod
cdef SyclDevice _create(DPCTLSyclDeviceRef dref)
@staticmethod
cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef)
cdef int _init_from__SyclDevice(self, _SyclDevice other)
cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef)
cdef DPCTLSyclDeviceRef get_device_ref(self)
Expand Down
20 changes: 10 additions & 10 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ cdef str _device_type_to_filter_string_part(_device_type DTy):
else:
return "unknown"

cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef):
"Populate attributes of device from opaque device reference DRef"
device._device_ref = DRef
device._name = DPCTLDevice_GetName(DRef)
device._driver_version = DPCTLDevice_GetDriverVersion(DRef)
device._vendor = DPCTLDevice_GetVendor(DRef)
device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(DRef)


cdef class SyclDevice(_SyclDevice):
""" SyclDevice(arg=None)
Expand Down Expand Up @@ -203,14 +211,6 @@ cdef class SyclDevice(_SyclDevice):
gpu.print_device_info()

"""
@staticmethod
cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef):
device._device_ref = DRef
device._name = DPCTLDevice_GetName(DRef)
device._driver_version = DPCTLDevice_GetDriverVersion(DRef)
device._vendor = DPCTLDevice_GetVendor(DRef)
device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(DRef)

@staticmethod
cdef SyclDevice _create(DPCTLSyclDeviceRef dref):
"""
Expand All @@ -221,7 +221,7 @@ cdef class SyclDevice(_SyclDevice):
"""
cdef _SyclDevice ret = _SyclDevice.__new__(_SyclDevice)
# Initialize the attributes of the SyclDevice object
SyclDevice._init_helper(<_SyclDevice> ret, dref)
_init_helper(<_SyclDevice> ret, dref)
# ret is a temporary, and _SyclDevice.__dealloc__ will delete dref
return SyclDevice(ret)

Expand All @@ -245,7 +245,7 @@ cdef class SyclDevice(_SyclDevice):
if DRef is NULL:
return -1
else:
SyclDevice._init_helper(self, DRef)
_init_helper(self, DRef)
return 0

def __cinit__(self, arg=None):
Expand Down
2 changes: 0 additions & 2 deletions dpctl/_sycl_platform.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ cdef class _SyclPlatform:
cdef class SyclPlatform(_SyclPlatform):
@staticmethod
cdef SyclPlatform _create(DPCTLSyclPlatformRef dref)
@staticmethod
cdef void _init_helper(_SyclPlatform platform, DPCTLSyclPlatformRef DRef)
cdef int _init_from_cstring(self, const char *string)
cdef int _init_from_selector(self, DPCTLSyclDeviceSelectorRef DSRef)
cdef int _init_from__SyclPlatform(self, _SyclPlatform other)
Expand Down
21 changes: 11 additions & 10 deletions dpctl/_sycl_platform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ cdef class _SyclPlatform:
DPCTLCString_Delete(self._version)


cdef void _init_helper(_SyclPlatform platform, DPCTLSyclPlatformRef PRef):
"Populate attributes of class from opaque reference PRef"
platform._platform_ref = PRef
platform._name = DPCTLPlatform_GetName(PRef)
platform._version = DPCTLPlatform_GetVersion(PRef)
platform._vendor = DPCTLPlatform_GetVendor(PRef)


cdef class SyclPlatform(_SyclPlatform):
""" SyclPlatform(self, arg=None)
Python class representing ``cl::sycl::platform`` class.
Expand All @@ -73,13 +81,6 @@ cdef class SyclPlatform(_SyclPlatform):
SyclPlatform(filter_selector) - create platform selected by filter
selector
"""
@staticmethod
cdef void _init_helper(_SyclPlatform platform, DPCTLSyclPlatformRef PRef):
platform._platform_ref = PRef
platform._name = DPCTLPlatform_GetName(PRef)
platform._version = DPCTLPlatform_GetVersion(PRef)
platform._vendor = DPCTLPlatform_GetVendor(PRef)

@staticmethod
cdef SyclPlatform _create(DPCTLSyclPlatformRef pref):
"""
Expand All @@ -90,7 +91,7 @@ cdef class SyclPlatform(_SyclPlatform):
"""
cdef _SyclPlatform p = _SyclPlatform.__new__(_SyclPlatform)
# Initialize the attributes of the SyclPlatform object
SyclPlatform._init_helper(<_SyclPlatform>p, pref)
_init_helper(<_SyclPlatform>p, pref)
return SyclPlatform(p)

cdef int _init_from__SyclPlatform(self, _SyclPlatform other):
Expand All @@ -114,7 +115,7 @@ cdef class SyclPlatform(_SyclPlatform):
if PRef is NULL:
return -1
else:
SyclPlatform._init_helper(self, PRef)
_init_helper(self, PRef)
return 0

cdef DPCTLSyclPlatformRef get_platform_ref(self):
Expand Down Expand Up @@ -169,7 +170,7 @@ cdef class SyclPlatform(_SyclPlatform):
"Could not create a SyclPlatform from default selector"
)
else:
SyclPlatform._init_helper(self, PRef)
_init_helper(self, PRef)
else:
raise ValueError(
"Invalid argument. Argument should be a str object specifying "
Expand Down