From 49eaea9d650de72040f44be5457e9a671accf381 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 17 Aug 2021 13:07:26 -0500 Subject: [PATCH] Static methods _init_helper made into functions and removed from PXD files --- dpctl/_sycl_context.pxd | 2 -- dpctl/_sycl_context.pyx | 16 ++++++++-------- dpctl/_sycl_device.pxd | 2 -- dpctl/_sycl_device.pyx | 20 ++++++++++---------- dpctl/_sycl_platform.pxd | 2 -- dpctl/_sycl_platform.pyx | 21 +++++++++++---------- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/dpctl/_sycl_context.pxd b/dpctl/_sycl_context.pxd index 0549682b78..c9c4d9d5cd 100644 --- a/dpctl/_sycl_context.pxd +++ b/dpctl/_sycl_context.pxd @@ -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) diff --git a/dpctl/_sycl_context.pyx b/dpctl/_sycl_context.pyx index 0ceafe857c..bd430c4f7a 100644 --- a/dpctl/_sycl_context.pyx +++ b/dpctl/_sycl_context.pyx @@ -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 """ @@ -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): """ @@ -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): @@ -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): @@ -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): diff --git a/dpctl/_sycl_device.pxd b/dpctl/_sycl_device.pxd index 88b23b12b3..51a66e6fa1 100644 --- a/dpctl/_sycl_device.pxd +++ b/dpctl/_sycl_device.pxd @@ -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) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 31d20c8928..b5734a141a 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -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) @@ -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): """ @@ -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) @@ -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): diff --git a/dpctl/_sycl_platform.pxd b/dpctl/_sycl_platform.pxd index 07b0cc2216..8bb3a9a36a 100644 --- a/dpctl/_sycl_platform.pxd +++ b/dpctl/_sycl_platform.pxd @@ -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) diff --git a/dpctl/_sycl_platform.pyx b/dpctl/_sycl_platform.pyx index f65c6dd561..8cd057dcd5 100644 --- a/dpctl/_sycl_platform.pyx +++ b/dpctl/_sycl_platform.pyx @@ -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. @@ -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): """ @@ -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): @@ -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): @@ -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 "