Skip to content

Commit 084ba59

Browse files
Diptorup Deboleksandr-pavlyk
authored andcommitted
Code changes to comply with latest linters
1 parent 1684403 commit 084ba59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1062
-628
lines changed

docs/conf.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use_doxyrest = "@DPCTL_ENABLE_DOXYREST@"
4141

4242
if use_doxyrest == "ON":
4343
# Specify the path to Doxyrest extensions for Sphinx:
44-
import sys, os
44+
import os
45+
import sys
4546

4647
sys.path.insert(
4748
1,
@@ -168,9 +169,8 @@ class ClassMembersDocumenter(ClassDocumenter):
168169
# members and attributes.
169170
# See https://stackoverflow.com/questions/20569011/python-sphinx-autosummary-automated-listing-of-member-functions
170171

171-
from sphinx.ext.autosummary import Autosummary
172-
from sphinx.ext.autosummary import get_documenter
173172
from docutils.parsers.rst import directives
173+
from sphinx.ext.autosummary import Autosummary, get_documenter
174174
from sphinx.util.inspect import safe_getattr
175175

176176

dpctl/__init__.py

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,104 @@
1919
2020
Dpctl's Python API implements Python wrappers for a subset of DPC++/SYCL's
2121
API. The Python API exposes wrappers for the SYCL runtime classes (expect
22-
`device_selector`) described in Section 4.6 of the SYCL 2020 spec (https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#_sycl_runtime_classes).
23-
Apart from the main SYCL runtime classes, dpctl includes a `memory` sub-module that exposes the SYCL USM allocators and deallocators.
22+
``device_selector``) described in Section 4.6 of the
23+
[SYCL 2020 spec](https://www.khronos.org/registry/SYCL/specs/sycl-2020/
24+
html/sycl-2020.html#_sycl_runtime_classes).
25+
Apart from the main SYCL runtime classes, dpctl includes a `memory`
26+
sub-module that exposes the SYCL USM allocators and deallocators.
2427
"""
2528
__author__ = "Intel Corp."
2629

27-
from .enum_types import *
28-
from .enum_types import __all__ as _enum_types_all__
29-
from dpctl._sycl_context import *
30-
from dpctl._sycl_context import __all__ as _sycl_context__all__
31-
from dpctl._sycl_device import *
32-
from dpctl._sycl_device import __all__ as _sycl_device__all__
33-
from dpctl._sycl_device_factory import *
34-
from dpctl._sycl_device_factory import __all__ as _sycl_device_factory__all__
35-
from dpctl._sycl_event import *
36-
from dpctl._sycl_event import __all__ as _sycl_event__all__
37-
from dpctl._sycl_platform import *
38-
from dpctl._sycl_platform import __all__ as _sycl_platform__all__
39-
from dpctl._sycl_queue import *
40-
from dpctl._sycl_queue import __all__ as _sycl_queue__all__
41-
from dpctl._sycl_queue_manager import *
42-
from dpctl._sycl_queue_manager import __all__ as _sycl_qm__all__
43-
from ._version import get_versions
30+
from dpctl._sycl_context import SyclContext
31+
from dpctl._sycl_device import SyclDevice
32+
from dpctl._sycl_device_factory import (
33+
get_devices,
34+
get_num_devices,
35+
has_accelerator_devices,
36+
has_cpu_devices,
37+
has_gpu_devices,
38+
has_host_device,
39+
select_accelerator_device,
40+
select_cpu_device,
41+
select_default_device,
42+
select_gpu_device,
43+
select_host_device,
44+
)
45+
from dpctl._sycl_event import SyclEvent
46+
from dpctl._sycl_platform import SyclPlatform, get_platforms, lsplatform
47+
from dpctl._sycl_queue import (
48+
SyclKernelInvalidRangeError,
49+
SyclKernelSubmitError,
50+
SyclQueue,
51+
SyclQueueCreationError,
52+
)
53+
from dpctl._sycl_queue_manager import (
54+
device_context,
55+
get_current_backend,
56+
get_current_device_type,
57+
get_current_queue,
58+
get_num_activated_queues,
59+
is_in_device_context,
60+
set_global_queue,
61+
)
4462

63+
from ._version import get_versions
64+
from .enum_types import backend_type, device_type
4565

46-
__all__ = (
47-
_sycl_context__all__
48-
+ _sycl_device__all__
49-
+ _sycl_device_factory__all__
50-
+ _sycl_event__all__
51-
+ _sycl_platform__all__
52-
+ _sycl_queue__all__
53-
+ _sycl_qm__all__
54-
+ _enum_types_all__
55-
)
66+
__all__ = [
67+
"SyclContext",
68+
]
69+
__all__ += [
70+
"SyclDevice",
71+
]
72+
__all__ += [
73+
"get_devices",
74+
"select_accelerator_device",
75+
"select_cpu_device",
76+
"select_default_device",
77+
"select_gpu_device",
78+
"select_host_device",
79+
"get_num_devices",
80+
"has_cpu_devices",
81+
"has_gpu_devices",
82+
"has_accelerator_devices",
83+
"has_host_device",
84+
]
85+
__all__ += [
86+
"SyclEvent",
87+
]
88+
__all__ += [
89+
"get_platforms",
90+
"lsplatform",
91+
"SyclPlatform",
92+
]
93+
__all__ += [
94+
"SyclQueue",
95+
"SyclKernelInvalidRangeError",
96+
"SyclKernelSubmitError",
97+
"SyclQueueCreationError",
98+
]
99+
__all__ += [
100+
"device_context",
101+
"get_current_backend",
102+
"get_current_device_type",
103+
"get_current_queue",
104+
"get_num_activated_queues",
105+
"is_in_device_context",
106+
"set_global_queue",
107+
]
108+
__all__ += [
109+
"device_type",
110+
"backend_type",
111+
]
112+
__all__ += [
113+
"get_include",
114+
]
56115

57116

58117
def get_include():
59-
r"""
60-
Return the directory that contains the dpctl \*.h header files.
118+
"""
119+
Return the directory that contains the dpctl *.h header files.
61120
62121
Extension modules that need to be compiled against dpctl should use
63122
this function to locate the appropriate include directory.
@@ -69,11 +128,3 @@ def get_include():
69128

70129
__version__ = get_versions()["version"]
71130
del get_versions
72-
del _sycl_context__all__
73-
del _sycl_device__all__
74-
del _sycl_device_factory__all__
75-
del _sycl_event__all__
76-
del _sycl_queue__all__
77-
del _sycl_qm__all__
78-
del _sycl_platform__all__
79-
del _enum_types_all__

dpctl/_backend.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
types defined by dpctl's C API.
2222
"""
2323

24+
from libc.stdint cimport int64_t, uint32_t
2425
from libcpp cimport bool
25-
from libc.stdint cimport uint32_t, int64_t
2626

2727

2828
cdef extern from "dpctl_error_handler_type.h":

dpctl/_sycl_context.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
""" This file declares the SyclContext extension type.
2121
"""
2222

23+
from libcpp cimport bool
24+
2325
from ._backend cimport DPCTLSyclContextRef
2426
from ._sycl_device cimport SyclDevice
25-
from libcpp cimport bool
27+
2628

2729
cdef class _SyclContext:
2830
""" Data owner for SyclContext

dpctl/_sycl_context.pyx

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,34 @@
2121
"""
2222

2323
from __future__ import print_function
24+
2425
import logging
25-
from ._backend cimport(
26-
DPCTLSyclContextRef,
27-
DPCTLSyclDeviceRef,
26+
27+
from cpython cimport pycapsule
28+
from cpython.mem cimport PyMem_Free, PyMem_Malloc
29+
30+
from ._backend cimport ( # noqa: E211
31+
DPCTLContext_AreEq,
32+
DPCTLContext_Copy,
2833
DPCTLContext_Create,
2934
DPCTLContext_CreateFromDevices,
35+
DPCTLContext_Delete,
3036
DPCTLContext_DeviceCount,
3137
DPCTLContext_GetDevices,
32-
DPCTLContext_Copy,
33-
DPCTLContext_Delete,
34-
DPCTLContext_AreEq,
35-
DPCTLDevice_Delete,
3638
DPCTLDevice_Copy,
37-
DPCTLDeviceVectorRef,
39+
DPCTLDevice_Delete,
40+
DPCTLDeviceMgr_GetCachedContext,
3841
DPCTLDeviceVector_CreateFromArray,
42+
DPCTLDeviceVector_Delete,
3943
DPCTLDeviceVector_GetAt,
4044
DPCTLDeviceVector_Size,
41-
DPCTLDeviceVector_Delete,
45+
DPCTLDeviceVectorRef,
46+
DPCTLSyclContextRef,
47+
DPCTLSyclDeviceRef,
4248
error_handler_callback,
43-
DPCTLDeviceMgr_GetCachedContext,
4449
)
45-
from ._sycl_queue cimport default_async_error_handler
4650
from ._sycl_device cimport SyclDevice
47-
from cpython.mem cimport PyMem_Malloc, PyMem_Free
48-
from cpython cimport pycapsule
51+
from ._sycl_queue cimport default_async_error_handler
4952

5053
__all__ = [
5154
"SyclContext",
@@ -56,7 +59,9 @@ _logger = logging.getLogger(__name__)
5659
cdef void _context_capsule_deleter(object o):
5760
cdef DPCTLSyclContextRef CRef = NULL
5861
if pycapsule.PyCapsule_IsValid(o, "SyclContextRef"):
59-
CRef = <DPCTLSyclContextRef> pycapsule.PyCapsule_GetPointer(o, "SyclContextRef")
62+
CRef = <DPCTLSyclContextRef> pycapsule.PyCapsule_GetPointer(
63+
o, "SyclContextRef"
64+
)
6065
DPCTLContext_Delete(CRef)
6166

6267

@@ -124,7 +129,7 @@ cdef class SyclContext(_SyclContext):
124129
125130
# Create a CPU device using the opencl driver
126131
cpu_d = dpctl.SyclDevice("opencl:cpu")
127-
# Partition the CPU device into sub-devices, each with two cores.
132+
# Partition the CPU device into sub-devices with two cores each.
128133
sub_devices = cpu_d.create_sub_devices(partition=2)
129134
# Create a context common to all the sub-devices.
130135
ctx = dpctl.SyclContext(sub_devices)
@@ -154,7 +159,7 @@ cdef class SyclContext(_SyclContext):
154159

155160
@staticmethod
156161
cdef void _init_helper(_SyclContext context, DPCTLSyclContextRef CRef):
157-
context._ctxt_ref = CRef
162+
context._ctxt_ref = CRef
158163

159164
@staticmethod
160165
cdef SyclContext _create(DPCTLSyclContextRef ctxt):
@@ -254,8 +259,8 @@ cdef class SyclContext(_SyclContext):
254259
return 0
255260
else:
256261
# __cinit__ checks that capsule is valid, so one can be here only
257-
# if call to `_init_context_from_capsule` was made outside of __cinit__
258-
# and the capsule was not checked to be valid
262+
# if call to `_init_context_from_capsule` was made outside of
263+
# __cinit__ and the capsule was not checked to be valid
259264
return -128
260265

261266
def __cinit__(self, arg=None):
@@ -266,8 +271,8 @@ cdef class SyclContext(_SyclContext):
266271
ret = self._init_context_from_one_device(<SyclDevice> arg, 0)
267272
elif pycapsule.PyCapsule_IsValid(arg, "SyclContextRef"):
268273
status = self._init_context_from_capsule(arg)
269-
elif isinstance(
270-
arg, (list, tuple)) and all([isinstance(argi, SyclDevice) for argi in arg]
274+
elif isinstance(arg, (list, tuple)) and all(
275+
[isinstance(argi, SyclDevice) for argi in arg]
271276
):
272277
ret = self._init_context_from_devices(arg, 0)
273278
else:
@@ -333,7 +338,7 @@ cdef class SyclContext(_SyclContext):
333338
cdef DPCTLSyclContextRef get_context_ref(self):
334339
return self._ctxt_ref
335340

336-
def addressof_ref (self):
341+
def addressof_ref(self):
337342
"""
338343
Returns the address of the ``DPCTLSyclContextRef`` pointer as a
339344
``size_t``.
@@ -416,7 +421,8 @@ cdef class SyclContext(_SyclContext):
416421
cpu_d = dpctl.SyclDevice("opencl:cpu")
417422
sub_devices = create_sub_devices(partition=2)
418423
ctx2 = dpctl.SyclContext(sub_devices)
419-
print(ctx2) # E.g : <dpctl.SyclContext for 4 devices at 0x7f154d8ab070>
424+
# prints: <dpctl.SyclContext for 4 devices at 0x7f154d8ab070>
425+
print(ctx2)
420426
421427
Returns:
422428
:obj:`str`: A string representation of the
@@ -427,8 +433,11 @@ cdef class SyclContext(_SyclContext):
427433
if n == 1:
428434
return ("<dpctl." + self.__name__ + " at {}>".format(hex(id(self))))
429435
else:
430-
return ("<dpctl." + self.__name__ + " for {} devices at {}>"
431-
.format(n, hex(id(self))))
436+
return (
437+
"<dpctl."
438+
+ self.__name__
439+
+ " for {} devices at {}>".format(n, hex(id(self)))
440+
)
432441

433442
def _get_capsule(self):
434443
"""

dpctl/_sycl_device.pxd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
""" This file declares the SyclDevice extension type.
2121
"""
2222

23+
from libcpp cimport bool as cpp_bool
24+
2325
from ._backend cimport (
2426
DPCTLSyclDeviceRef,
2527
DPCTLSyclDeviceSelectorRef,
26-
_partition_affinity_domain_type
28+
_partition_affinity_domain_type,
2729
)
28-
from libcpp cimport bool as cpp_bool
2930

3031

3132
cdef class _SyclDevice:

0 commit comments

Comments
 (0)