Skip to content

Commit 0ce1aef

Browse files
committed
extend pre-commit hooks with cython-lint
1 parent f57963e commit 0ce1aef

31 files changed

+817
-556
lines changed

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414

1515
# Transition from clang-format 11 to clang-format 18
1616
b37657e6ad9af16eaec2982d8e2397acd2af2881
17+
18+
# Add cython-lint to pre-commit config

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ repos:
4242
hooks:
4343
- id: pretty-format-toml
4444
args: [--autofix]
45+
- repo: https://github.com/MarcoGorelli/cython-lint
46+
rev: v0.16.6
47+
hooks:
48+
- id: cython-lint
49+
- id: double-quote-cython-strings

dpctl/_backend.pxd

+212-139
Large diffs are not rendered by default.

dpctl/_diagnostics.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import os
2525

2626

2727
cdef extern from "syclinterface/dpctl_service.h":
28-
cdef void DPCTLService_InitLogger(const char *, const char *)
29-
cdef void DPCTLService_ShutdownLogger()
28+
cdef void DPCTLService_InitLogger(const char *, const char *)
29+
cdef void DPCTLService_ShutdownLogger()
3030

3131

3232
def _init_logger(log_dir=None):
@@ -62,7 +62,7 @@ def syclinterface_diagnostics(verbosity="warning", log_dir=None):
6262
function calls.
6363
"""
6464
_allowed_verbosity = ["warning", "error"]
65-
if not verbosity in _allowed_verbosity:
65+
if verbosity not in _allowed_verbosity:
6666
raise ValueError(
6767
f"Verbosity argument not understood. "
6868
f"Permitted values are {_allowed_verbosity}"

dpctl/_sycl_context.pyx

-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ from ._backend cimport ( # noqa: E211
3535
DPCTLContext_DeviceCount,
3636
DPCTLContext_GetDevices,
3737
DPCTLContext_Hash,
38-
DPCTLDevice_Copy,
39-
DPCTLDevice_Delete,
4038
DPCTLDeviceMgr_GetCachedContext,
4139
DPCTLDeviceVector_CreateFromArray,
4240
DPCTLDeviceVector_Delete,
@@ -216,7 +214,6 @@ cdef class SyclContext(_SyclContext):
216214
cdef int _init_context_from_devices(self, object devices, int props):
217215
cdef int num_devices = len(devices)
218216
cdef int i = 0
219-
cdef int j = 0
220217
cdef size_t num_bytes
221218
cdef DPCTLDeviceVectorRef DVRef = NULL
222219
cdef error_handler_callback * eh_callback = NULL

dpctl/_sycl_device.pxd

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ cdef public api class SyclDevice(_SyclDevice) [
5353
cdef DPCTLSyclDeviceRef get_device_ref(self)
5454
cdef list create_sub_devices_equally(self, size_t count)
5555
cdef list create_sub_devices_by_counts(self, object counts)
56-
cdef list create_sub_devices_by_affinity(self, _partition_affinity_domain_type domain)
56+
cdef list create_sub_devices_by_affinity(
57+
self, _partition_affinity_domain_type domain
58+
)
5759
cdef cpp_bool equals(self, SyclDevice q)
5860
cdef int get_device_type_ordinal(self)
5961
cdef int get_overall_ordinal(self)

dpctl/_sycl_device.pyx

+18-22
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ from ._backend cimport ( # noqa: E211
8585
DPCTLDevice_IsCPU,
8686
DPCTLDevice_IsGPU,
8787
DPCTLDeviceMgr_GetDeviceInfoStr,
88-
DPCTLDeviceMgr_GetDevices,
8988
DPCTLDeviceMgr_GetPositionInDevices,
9089
DPCTLDeviceMgr_GetRelativeId,
9190
DPCTLDeviceSelector_Delete,
@@ -348,7 +347,7 @@ cdef class SyclDevice(_SyclDevice):
348347
if ret == -1:
349348
raise SyclDeviceCreationError(
350349
"Could not create a SyclDevice with the selector string "
351-
"'{selector_string}'".format(selector_string=arg)
350+
"'{selector_string}'".format(selector_string=arg)
352351
)
353352
elif isinstance(arg, _SyclDevice):
354353
ret = self._init_from__SyclDevice(arg)
@@ -810,7 +809,6 @@ cdef class SyclDevice(_SyclDevice):
810809
cdef _aspect_type AT = _aspect_type._is_component
811810
return DPCTLDevice_HasAspect(self._device_ref, AT)
812811

813-
814812
@property
815813
def has_aspect_is_composite(self):
816814
""" Returns ``True`` if this device is a composite device, ``False``
@@ -1113,8 +1111,8 @@ cdef class SyclDevice(_SyclDevice):
11131111

11141112
@property
11151113
def sub_group_independent_forward_progress(self):
1116-
""" Returns ``True`` if the device supports independent forward progress of
1117-
sub-groups with respect to other sub-groups in the same work-group.
1114+
""" Returns ``True`` if the device supports independent forward progress
1115+
of sub-groups with respect to other sub-groups in the same work-group.
11181116
11191117
Returns:
11201118
bool:
@@ -1155,7 +1153,7 @@ cdef class SyclDevice(_SyclDevice):
11551153
DPCTLSize_t_Array_Delete(sg_sizes)
11561154
return res
11571155
else:
1158-
return []
1156+
return []
11591157

11601158
@property
11611159
def sycl_platform(self):
@@ -1667,19 +1665,20 @@ cdef class SyclDevice(_SyclDevice):
16671665
16681666
- Specifying an int (``count``)
16691667
The returned list contains as
1670-
many sub-devices as can be created such that each sub-device
1671-
contains ``count`` compute units. If the device’s total number
1672-
of compute units is not evenly divided by ``count``, then the
1673-
remaining compute units are not included in any of the
1674-
sub-devices.
1668+
many sub-devices as can be created such that each
1669+
sub-device contains ``count`` compute units. If the
1670+
device’s total number of compute units is not evenly
1671+
divided by ``count``, then the remaining compute units
1672+
are not included in any of the sub-devices.
16751673
16761674
- Specifying an affinity domain as a string
1677-
The supported values are: ``"numa"``, ``"L4_cache"``, ``"L3_cache"``,
1678-
``"L2_cache"``, ``"L1_cache"``, ``"next_partitionable"``.
1675+
The supported values are: ``"numa"``, ``"L4_cache"``,
1676+
``"L3_cache"``, ``"L2_cache"``, ``"L1_cache"``,
1677+
``"next_partitionable"``.
16791678
16801679
- Specifying a collection of integral values
1681-
For each non-zero value ``M`` in the collection, a sub-device with ``M``
1682-
compute units is created.
1680+
For each non-zero value ``M`` in the collection, a
1681+
sub-device with ``M`` compute units is created.
16831682
16841683
Returns:
16851684
List[:class:`dpctl.SyclDevice`]:
@@ -1816,7 +1815,7 @@ cdef class SyclDevice(_SyclDevice):
18161815
"""
18171816
cdef uint32_t clock_fr = DPCTLDevice_GetMaxClockFrequency(
18181817
self._device_ref
1819-
)
1818+
)
18201819
return clock_fr
18211820

18221821
@property
@@ -1829,7 +1828,7 @@ cdef class SyclDevice(_SyclDevice):
18291828
"""
18301829
cdef uint64_t max_alloc_sz = DPCTLDevice_GetMaxMemAllocSize(
18311830
self._device_ref
1832-
)
1831+
)
18331832
return max_alloc_sz
18341833

18351834
@property
@@ -1875,7 +1874,7 @@ cdef class SyclDevice(_SyclDevice):
18751874
"""
18761875
cdef uint64_t cache_sz = DPCTLDevice_GetGlobalMemCacheSize(
18771876
self._device_ref
1878-
)
1877+
)
18791878
return cache_sz
18801879

18811880
@property
@@ -1888,7 +1887,7 @@ cdef class SyclDevice(_SyclDevice):
18881887
"""
18891888
cdef uint64_t cache_line_sz = DPCTLDevice_GetGlobalMemCacheLineSize(
18901889
self._device_ref
1891-
)
1890+
)
18921891
return cache_line_sz
18931892

18941893
@property
@@ -1957,9 +1956,6 @@ cdef class SyclDevice(_SyclDevice):
19571956
assert level_zero_gpu == dev
19581957
"""
19591958
cdef DPCTLSyclDeviceRef pDRef = NULL
1960-
cdef _backend_type BTy
1961-
cdef _device_type DTy
1962-
cdef int64_t relId = -1
19631959
pDRef = DPCTLDevice_GetParentDevice(self._device_ref)
19641960
if (pDRef is NULL):
19651961
return _cached_filter_string(self)

dpctl/_sycl_device_factory.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ cdef class _DefaultDeviceCache:
437437

438438

439439
_global_default_device_cache = ContextVar(
440-
'global_default_device_cache',
440+
"global_default_device_cache",
441441
default=_DefaultDeviceCache()
442442
)
443443

@@ -452,5 +452,6 @@ cpdef SyclDevice _cached_default_device():
452452
"""
453453
cdef _DefaultDeviceCache _cache = _global_default_device_cache.get()
454454
d_, changed_ = _cache.get_or_create()
455-
if changed_: _global_default_device_cache.set(_cache)
455+
if changed_:
456+
_global_default_device_cache.set(_cache)
456457
return d_

dpctl/_sycl_event.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ from ._backend cimport ( # noqa: E211
3838
DPCTLEvent_GetProfilingInfoSubmit,
3939
DPCTLEvent_GetWaitList,
4040
DPCTLEvent_Wait,
41-
DPCTLEvent_WaitAndThrow,
4241
DPCTLEventVector_Delete,
4342
DPCTLEventVector_GetAt,
4443
DPCTLEventVector_Size,
@@ -220,7 +219,8 @@ cdef class SyclEvent(_SyclEvent):
220219

221220
@staticmethod
222221
cdef void _wait(SyclEvent event):
223-
with nogil: DPCTLEvent_Wait(event._event_ref)
222+
with nogil:
223+
DPCTLEvent_Wait(event._event_ref)
224224

225225
@staticmethod
226226
def wait_for(event):
@@ -417,4 +417,5 @@ cdef class SyclEvent(_SyclEvent):
417417
Returns:
418418
None
419419
"""
420-
with nogil: DPCTLEvent_Wait(self._event_ref)
420+
with nogil:
421+
DPCTLEvent_Wait(self._event_ref)

dpctl/_sycl_platform.pyx

+6-5
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ cdef class SyclPlatform(_SyclPlatform):
238238
Args:
239239
verbosity (Literal[0, 1, 2], optional):.
240240
The verbosity controls how much information is printed by the
241-
function. Value ``0`` is the lowest level set by default and ``2``
242-
is the highest level to print the most verbose output.
241+
function. Value ``0`` is the lowest level set by default and
242+
``2`` is the highest level to print the most verbose output.
243243
Default: ``0``
244244
"""
245245
cdef size_t v = 0
@@ -367,7 +367,8 @@ cdef class SyclPlatform(_SyclPlatform):
367367

368368
def __hash__(self):
369369
"""
370-
Returns a hash value by hashing the underlying ``sycl::platform`` object.
370+
Returns a hash value by hashing the underlying ``sycl::platform``
371+
object.
371372
372373
Returns:
373374
int:
@@ -579,11 +580,11 @@ def lsplatform(verbosity=0):
579580
if v != 0:
580581
print("Platform ", i, "::")
581582
PRef = DPCTLPlatformVector_GetAt(PVRef, i)
582-
info_str = DPCTLPlatformMgr_GetInfo(PRef,v)
583+
info_str = DPCTLPlatformMgr_GetInfo(PRef, v)
583584
py_info = <bytes> info_str
584585
DPCTLCString_Delete(info_str)
585586
DPCTLPlatform_Delete(PRef)
586-
print(py_info.decode("utf-8"),end='')
587+
print(py_info.decode("utf-8"), end="")
587588
DPCTLPlatformVector_Delete(PVRef)
588589

589590

dpctl/_sycl_queue.pxd

+2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ cdef public api class SyclQueue (_SyclQueue) [
6565
_arg_data_type *kargty
6666
)
6767
cdef int _populate_range(self, size_t Range[3], list gS, size_t nGS)
68+
6869
@staticmethod
6970
cdef SyclQueue _create(DPCTLSyclQueueRef qref)
71+
7072
@staticmethod
7173
cdef SyclQueue _create_from_context_and_device(
7274
SyclContext ctx, SyclDevice dev, int props=*

0 commit comments

Comments
 (0)