Skip to content

extend pre-commit hooks with cython-lint #2056

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 3 commits into from
Apr 19, 2025
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
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

# Transition from clang-format 11 to clang-format 18
b37657e6ad9af16eaec2982d8e2397acd2af2881

# Add cython-lint to pre-commit config
0ce1aef210ffb88b7d2ea3a89e861486498f652f
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ repos:
hooks:
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.6
hooks:
- id: cython-lint
- id: double-quote-cython-strings
351 changes: 212 additions & 139 deletions dpctl/_backend.pxd

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dpctl/_diagnostics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import os


cdef extern from "syclinterface/dpctl_service.h":
cdef void DPCTLService_InitLogger(const char *, const char *)
cdef void DPCTLService_ShutdownLogger()
cdef void DPCTLService_InitLogger(const char *, const char *)
cdef void DPCTLService_ShutdownLogger()


def _init_logger(log_dir=None):
Expand Down Expand Up @@ -62,7 +62,7 @@ def syclinterface_diagnostics(verbosity="warning", log_dir=None):
function calls.
"""
_allowed_verbosity = ["warning", "error"]
if not verbosity in _allowed_verbosity:
if verbosity not in _allowed_verbosity:
raise ValueError(
f"Verbosity argument not understood. "
f"Permitted values are {_allowed_verbosity}"
Expand Down
5 changes: 1 addition & 4 deletions dpctl/_sycl_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ from ._backend cimport ( # noqa: E211
DPCTLContext_DeviceCount,
DPCTLContext_GetDevices,
DPCTLContext_Hash,
DPCTLDevice_Copy,
DPCTLDevice_Delete,
DPCTLDeviceMgr_GetCachedContext,
DPCTLDeviceVector_CreateFromArray,
DPCTLDeviceVector_Delete,
Expand Down Expand Up @@ -216,7 +214,6 @@ cdef class SyclContext(_SyclContext):
cdef int _init_context_from_devices(self, object devices, int props):
cdef int num_devices = len(devices)
cdef int i = 0
cdef int j = 0
cdef size_t num_bytes
cdef DPCTLDeviceVectorRef DVRef = NULL
cdef error_handler_callback * eh_callback = NULL
Expand Down Expand Up @@ -289,7 +286,7 @@ cdef class SyclContext(_SyclContext):
elif isinstance(arg, SyclDevice):
ret = self._init_context_from_one_device(<SyclDevice> arg, 0)
elif pycapsule.PyCapsule_IsValid(arg, "SyclContextRef"):
status = self._init_context_from_capsule(arg)
ret = self._init_context_from_capsule(arg)
elif isinstance(arg, (list, tuple)) and all(
[isinstance(argi, SyclDevice) for argi in arg]
):
Expand Down
4 changes: 3 additions & 1 deletion dpctl/_sycl_device.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ cdef public api class SyclDevice(_SyclDevice) [
cdef DPCTLSyclDeviceRef get_device_ref(self)
cdef list create_sub_devices_equally(self, size_t count)
cdef list create_sub_devices_by_counts(self, object counts)
cdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain)
cdef list create_sub_devices_by_affinity(
self, _partition_affinity_domain_type domain
)
cdef cpp_bool equals(self, SyclDevice q)
cdef int get_device_type_ordinal(self)
cdef int get_overall_ordinal(self)
Expand Down
40 changes: 18 additions & 22 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ from ._backend cimport ( # noqa: E211
DPCTLDevice_IsCPU,
DPCTLDevice_IsGPU,
DPCTLDeviceMgr_GetDeviceInfoStr,
DPCTLDeviceMgr_GetDevices,
DPCTLDeviceMgr_GetPositionInDevices,
DPCTLDeviceMgr_GetRelativeId,
DPCTLDeviceSelector_Delete,
Expand Down Expand Up @@ -348,7 +347,7 @@ cdef class SyclDevice(_SyclDevice):
if ret == -1:
raise SyclDeviceCreationError(
"Could not create a SyclDevice with the selector string "
"'{selector_string}'".format(selector_string=arg)
"'{selector_string}'".format(selector_string=arg)
)
elif isinstance(arg, _SyclDevice):
ret = self._init_from__SyclDevice(arg)
Expand Down Expand Up @@ -810,7 +809,6 @@ cdef class SyclDevice(_SyclDevice):
cdef _aspect_type AT = _aspect_type._is_component
return DPCTLDevice_HasAspect(self._device_ref, AT)


@property
def has_aspect_is_composite(self):
""" Returns ``True`` if this device is a composite device, ``False``
Expand Down Expand Up @@ -1113,8 +1111,8 @@ cdef class SyclDevice(_SyclDevice):

@property
def sub_group_independent_forward_progress(self):
""" Returns ``True`` if the device supports independent forward progress of
sub-groups with respect to other sub-groups in the same work-group.
""" Returns ``True`` if the device supports independent forward progress
of sub-groups with respect to other sub-groups in the same work-group.

Returns:
bool:
Expand Down Expand Up @@ -1155,7 +1153,7 @@ cdef class SyclDevice(_SyclDevice):
DPCTLSize_t_Array_Delete(sg_sizes)
return res
else:
return []
return []

@property
def sycl_platform(self):
Expand Down Expand Up @@ -1667,19 +1665,20 @@ cdef class SyclDevice(_SyclDevice):

- Specifying an int (``count``)
The returned list contains as
many sub-devices as can be created such that each sub-device
contains ``count`` compute units. If the device’s total number
of compute units is not evenly divided by ``count``, then the
remaining compute units are not included in any of the
sub-devices.
many sub-devices as can be created such that each
sub-device contains ``count`` compute units. If the
device’s total number of compute units is not evenly
divided by ``count``, then the remaining compute units
are not included in any of the sub-devices.

- Specifying an affinity domain as a string
The supported values are: ``"numa"``, ``"L4_cache"``, ``"L3_cache"``,
``"L2_cache"``, ``"L1_cache"``, ``"next_partitionable"``.
The supported values are: ``"numa"``, ``"L4_cache"``,
``"L3_cache"``, ``"L2_cache"``, ``"L1_cache"``,
``"next_partitionable"``.

- Specifying a collection of integral values
For each non-zero value ``M`` in the collection, a sub-device with ``M``
compute units is created.
For each non-zero value ``M`` in the collection, a
sub-device with ``M`` compute units is created.

Returns:
List[:class:`dpctl.SyclDevice`]:
Expand Down Expand Up @@ -1816,7 +1815,7 @@ cdef class SyclDevice(_SyclDevice):
"""
cdef uint32_t clock_fr = DPCTLDevice_GetMaxClockFrequency(
self._device_ref
)
)
return clock_fr

@property
Expand All @@ -1829,7 +1828,7 @@ cdef class SyclDevice(_SyclDevice):
"""
cdef uint64_t max_alloc_sz = DPCTLDevice_GetMaxMemAllocSize(
self._device_ref
)
)
return max_alloc_sz

@property
Expand Down Expand Up @@ -1875,7 +1874,7 @@ cdef class SyclDevice(_SyclDevice):
"""
cdef uint64_t cache_sz = DPCTLDevice_GetGlobalMemCacheSize(
self._device_ref
)
)
return cache_sz

@property
Expand All @@ -1888,7 +1887,7 @@ cdef class SyclDevice(_SyclDevice):
"""
cdef uint64_t cache_line_sz = DPCTLDevice_GetGlobalMemCacheLineSize(
self._device_ref
)
)
return cache_line_sz

@property
Expand Down Expand Up @@ -1957,9 +1956,6 @@ cdef class SyclDevice(_SyclDevice):
assert level_zero_gpu == dev
"""
cdef DPCTLSyclDeviceRef pDRef = NULL
cdef _backend_type BTy
cdef _device_type DTy
cdef int64_t relId = -1
pDRef = DPCTLDevice_GetParentDevice(self._device_ref)
if (pDRef is NULL):
return _cached_filter_string(self)
Expand Down
5 changes: 3 additions & 2 deletions dpctl/_sycl_device_factory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ cdef class _DefaultDeviceCache:


_global_default_device_cache = ContextVar(
'global_default_device_cache',
"global_default_device_cache",
default=_DefaultDeviceCache()
)

Expand All @@ -452,5 +452,6 @@ cpdef SyclDevice _cached_default_device():
"""
cdef _DefaultDeviceCache _cache = _global_default_device_cache.get()
d_, changed_ = _cache.get_or_create()
if changed_: _global_default_device_cache.set(_cache)
if changed_:
_global_default_device_cache.set(_cache)
return d_
7 changes: 4 additions & 3 deletions dpctl/_sycl_event.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ from ._backend cimport ( # noqa: E211
DPCTLEvent_GetProfilingInfoSubmit,
DPCTLEvent_GetWaitList,
DPCTLEvent_Wait,
DPCTLEvent_WaitAndThrow,
DPCTLEventVector_Delete,
DPCTLEventVector_GetAt,
DPCTLEventVector_Size,
Expand Down Expand Up @@ -220,7 +219,8 @@ cdef class SyclEvent(_SyclEvent):

@staticmethod
cdef void _wait(SyclEvent event):
with nogil: DPCTLEvent_Wait(event._event_ref)
with nogil:
DPCTLEvent_Wait(event._event_ref)

@staticmethod
def wait_for(event):
Expand Down Expand Up @@ -417,4 +417,5 @@ cdef class SyclEvent(_SyclEvent):
Returns:
None
"""
with nogil: DPCTLEvent_Wait(self._event_ref)
with nogil:
DPCTLEvent_Wait(self._event_ref)
11 changes: 6 additions & 5 deletions dpctl/_sycl_platform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ cdef class SyclPlatform(_SyclPlatform):
Args:
verbosity (Literal[0, 1, 2], optional):.
The verbosity controls how much information is printed by the
function. Value ``0`` is the lowest level set by default and ``2``
is the highest level to print the most verbose output.
function. Value ``0`` is the lowest level set by default and
``2`` is the highest level to print the most verbose output.
Default: ``0``
"""
cdef size_t v = 0
Expand Down Expand Up @@ -367,7 +367,8 @@ cdef class SyclPlatform(_SyclPlatform):

def __hash__(self):
"""
Returns a hash value by hashing the underlying ``sycl::platform`` object.
Returns a hash value by hashing the underlying ``sycl::platform``
object.

Returns:
int:
Expand Down Expand Up @@ -579,11 +580,11 @@ def lsplatform(verbosity=0):
if v != 0:
print("Platform ", i, "::")
PRef = DPCTLPlatformVector_GetAt(PVRef, i)
info_str = DPCTLPlatformMgr_GetInfo(PRef,v)
info_str = DPCTLPlatformMgr_GetInfo(PRef, v)
py_info = <bytes> info_str
DPCTLCString_Delete(info_str)
DPCTLPlatform_Delete(PRef)
print(py_info.decode("utf-8"),end='')
print(py_info.decode("utf-8"), end="")
DPCTLPlatformVector_Delete(PVRef)


Expand Down
2 changes: 2 additions & 0 deletions dpctl/_sycl_queue.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ cdef public api class SyclQueue (_SyclQueue) [
_arg_data_type *kargty
)
cdef int _populate_range(self, size_t Range[3], list gS, size_t nGS)

@staticmethod
cdef SyclQueue _create(DPCTLSyclQueueRef qref)

@staticmethod
cdef SyclQueue _create_from_context_and_device(
SyclContext ctx, SyclDevice dev, int props=*
Expand Down
Loading
Loading