Skip to content

Fix/code style #416

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

Closed
wants to merge 6 commits into from
Closed
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
6 changes: 3 additions & 3 deletions docs/conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ use_doxyrest = "@DPCTL_ENABLE_DOXYREST@"

if use_doxyrest == "ON":
# Specify the path to Doxyrest extensions for Sphinx:
import sys, os
import os
import sys

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

from sphinx.ext.autosummary import Autosummary
from sphinx.ext.autosummary import get_documenter
from docutils.parsers.rst import directives
from sphinx.ext.autosummary import Autosummary, get_documenter
from sphinx.util.inspect import safe_getattr


Expand Down
128 changes: 90 additions & 38 deletions dpctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,105 @@

Dpctl's Python API implements Python wrappers for a subset of DPC++/SYCL's
API. The Python API exposes wrappers for the SYCL runtime classes (expect
`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).
Apart from the main SYCL runtime classes, dpctl includes a `memory` sub-module that exposes the SYCL USM allocators and deallocators.
``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).
Apart from the main SYCL runtime classes, dpctl includes a `memory`
sub-module that exposes the SYCL USM allocators and deallocators.
"""
__author__ = "Intel Corp."

from .enum_types import *
from .enum_types import __all__ as _enum_types_all__
from dpctl._sycl_context import *
from dpctl._sycl_context import __all__ as _sycl_context__all__
from dpctl._sycl_device import *
from dpctl._sycl_device import __all__ as _sycl_device__all__
from dpctl._sycl_device_factory import *
from dpctl._sycl_device_factory import __all__ as _sycl_device_factory__all__
from dpctl._sycl_event import *
from dpctl._sycl_event import __all__ as _sycl_event__all__
from dpctl._sycl_platform import *
from dpctl._sycl_platform import __all__ as _sycl_platform__all__
from dpctl._sycl_queue import *
from dpctl._sycl_queue import __all__ as _sycl_queue__all__
from dpctl._sycl_queue_manager import *
from dpctl._sycl_queue_manager import __all__ as _sycl_qm__all__
from dpctl._sycl_context import SyclContext
from dpctl._sycl_device import SyclDevice
from dpctl._sycl_device_factory import (
get_devices,
get_num_devices,
has_accelerator_devices,
has_cpu_devices,
has_gpu_devices,
has_host_device,
select_accelerator_device,
select_cpu_device,
select_default_device,
select_gpu_device,
select_host_device,
)
from dpctl._sycl_event import SyclEvent
from dpctl._sycl_platform import SyclPlatform, get_platforms, lsplatform
from dpctl._sycl_queue import (
SyclKernelInvalidRangeError,
SyclKernelSubmitError,
SyclQueue,
SyclQueueCreationError,
)
from dpctl._sycl_queue_manager import (
device_context,
get_current_backend,
get_current_device_type,
get_current_queue,
get_num_activated_queues,
is_in_device_context,
set_global_queue,
)

from ._version import get_versions
from .enum_types import backend_type, device_type

__all__ = [
"SyclContext",
]
__all__ += [
"SyclDevice",
]

__all__ = (
_sycl_context__all__
+ _sycl_device__all__
+ _sycl_device_factory__all__
+ _sycl_event__all__
+ _sycl_platform__all__
+ _sycl_queue__all__
+ _sycl_qm__all__
+ _enum_types_all__
)
__all__ += [
"get_devices",
"select_accelerator_device",
"select_cpu_device",
"select_default_device",
"select_gpu_device",
"select_host_device",
"get_num_devices",
"has_cpu_devices",
"has_gpu_devices",
"has_accelerator_devices",
"has_host_device",
]
__all__ += [
"SyclEvent",
]
__all__ += [
"get_platforms",
"lsplatform",
"SyclPlatform",
]
__all__ += [
"SyclQueue",
"SyclKernelInvalidRangeError",
"SyclKernelSubmitError",
"SyclQueueCreationError",
]
__all__ += [
"device_context",
"get_current_backend",
"get_current_device_type",
"get_current_queue",
"get_num_activated_queues",
"is_in_device_context",
"set_global_queue",
]
__all__ += [
"device_type",
"backend_type",
]
__all__ += [
"get_include",
]


def get_include():
r"""
Return the directory that contains the dpctl \*.h header files.
"""
Return the directory that contains the dpctl *.h header files.

Extension modules that need to be compiled against dpctl should use
this function to locate the appropriate include directory.
Expand All @@ -69,11 +129,3 @@ def get_include():

__version__ = get_versions()["version"]
del get_versions
del _sycl_context__all__
del _sycl_device__all__
del _sycl_device_factory__all__
del _sycl_event__all__
del _sycl_queue__all__
del _sycl_qm__all__
del _sycl_platform__all__
del _enum_types_all__
2 changes: 1 addition & 1 deletion dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
types defined by dpctl's C API.
"""

from libc.stdint cimport int64_t, uint32_t
from libcpp cimport bool
from libc.stdint cimport uint32_t, int64_t


cdef extern from "dpctl_error_handler_type.h":
Expand Down
4 changes: 3 additions & 1 deletion dpctl/_sycl_context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
""" This file declares the SyclContext extension type.
"""

from libcpp cimport bool

from ._backend cimport DPCTLSyclContextRef
from ._sycl_device cimport SyclDevice
from libcpp cimport bool


cdef class _SyclContext:
""" Data owner for SyclContext
Expand Down
57 changes: 33 additions & 24 deletions dpctl/_sycl_context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,34 @@
"""

from __future__ import print_function

import logging
from ._backend cimport(
DPCTLSyclContextRef,
DPCTLSyclDeviceRef,

from cpython cimport pycapsule
from cpython.mem cimport PyMem_Free, PyMem_Malloc

from ._backend cimport ( # noqa: E211
DPCTLContext_AreEq,
DPCTLContext_Copy,
DPCTLContext_Create,
DPCTLContext_CreateFromDevices,
DPCTLContext_Delete,
DPCTLContext_DeviceCount,
DPCTLContext_GetDevices,
DPCTLContext_Copy,
DPCTLContext_Delete,
DPCTLContext_AreEq,
DPCTLDevice_Delete,
DPCTLDevice_Copy,
DPCTLDeviceVectorRef,
DPCTLDevice_Delete,
DPCTLDeviceMgr_GetCachedContext,
DPCTLDeviceVector_CreateFromArray,
DPCTLDeviceVector_Delete,
DPCTLDeviceVector_GetAt,
DPCTLDeviceVector_Size,
DPCTLDeviceVector_Delete,
DPCTLDeviceVectorRef,
DPCTLSyclContextRef,
DPCTLSyclDeviceRef,
error_handler_callback,
DPCTLDeviceMgr_GetCachedContext,
)
from ._sycl_queue cimport default_async_error_handler
from ._sycl_device cimport SyclDevice
from cpython.mem cimport PyMem_Malloc, PyMem_Free
from cpython cimport pycapsule
from ._sycl_queue cimport default_async_error_handler

__all__ = [
"SyclContext",
Expand All @@ -56,7 +59,9 @@ _logger = logging.getLogger(__name__)
cdef void _context_capsule_deleter(object o):
cdef DPCTLSyclContextRef CRef = NULL
if pycapsule.PyCapsule_IsValid(o, "SyclContextRef"):
CRef = <DPCTLSyclContextRef> pycapsule.PyCapsule_GetPointer(o, "SyclContextRef")
CRef = <DPCTLSyclContextRef> pycapsule.PyCapsule_GetPointer(
o, "SyclContextRef"
)
DPCTLContext_Delete(CRef)


Expand Down Expand Up @@ -124,7 +129,7 @@ cdef class SyclContext(_SyclContext):

# Create a CPU device using the opencl driver
cpu_d = dpctl.SyclDevice("opencl:cpu")
# Partition the CPU device into sub-devices, each with two cores.
# Partition the CPU device into sub-devices with two cores each.
sub_devices = cpu_d.create_sub_devices(partition=2)
# Create a context common to all the sub-devices.
ctx = dpctl.SyclContext(sub_devices)
Expand Down Expand Up @@ -154,7 +159,7 @@ cdef class SyclContext(_SyclContext):

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

@staticmethod
cdef SyclContext _create(DPCTLSyclContextRef ctxt):
Expand Down Expand Up @@ -254,8 +259,8 @@ cdef class SyclContext(_SyclContext):
return 0
else:
# __cinit__ checks that capsule is valid, so one can be here only
# if call to `_init_context_from_capsule` was made outside of __cinit__
# and the capsule was not checked to be valid
# if call to `_init_context_from_capsule` was made outside of
# __cinit__ and the capsule was not checked to be valid
return -128

def __cinit__(self, arg=None):
Expand All @@ -266,8 +271,8 @@ cdef class SyclContext(_SyclContext):
ret = self._init_context_from_one_device(<SyclDevice> arg, 0)
elif pycapsule.PyCapsule_IsValid(arg, "SyclContextRef"):
status = self._init_context_from_capsule(arg)
elif isinstance(
arg, (list, tuple)) and all([isinstance(argi, SyclDevice) for argi in arg]
elif isinstance(arg, (list, tuple)) and all(
[isinstance(argi, SyclDevice) for argi in arg]
):
ret = self._init_context_from_devices(arg, 0)
else:
Expand Down Expand Up @@ -333,7 +338,7 @@ cdef class SyclContext(_SyclContext):
cdef DPCTLSyclContextRef get_context_ref(self):
return self._ctxt_ref

def addressof_ref (self):
def addressof_ref(self):
"""
Returns the address of the ``DPCTLSyclContextRef`` pointer as a
``size_t``.
Expand Down Expand Up @@ -416,7 +421,8 @@ cdef class SyclContext(_SyclContext):
cpu_d = dpctl.SyclDevice("opencl:cpu")
sub_devices = create_sub_devices(partition=2)
ctx2 = dpctl.SyclContext(sub_devices)
print(ctx2) # E.g : <dpctl.SyclContext for 4 devices at 0x7f154d8ab070>
# prints: <dpctl.SyclContext for 4 devices at 0x7f154d8ab070>
print(ctx2)

Returns:
:obj:`str`: A string representation of the
Expand All @@ -427,8 +433,11 @@ cdef class SyclContext(_SyclContext):
if n == 1:
return ("<dpctl." + self.__name__ + " at {}>".format(hex(id(self))))
else:
return ("<dpctl." + self.__name__ + " for {} devices at {}>"
.format(n, hex(id(self))))
return (
"<dpctl."
+ self.__name__
+ " for {} devices at {}>".format(n, hex(id(self)))
)

def _get_capsule(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions dpctl/_sycl_device.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
""" This file declares the SyclDevice extension type.
"""

from libcpp cimport bool as cpp_bool

from ._backend cimport (
DPCTLSyclDeviceRef,
DPCTLSyclDeviceSelectorRef,
_partition_affinity_domain_type
_partition_affinity_domain_type,
)
from libcpp cimport bool as cpp_bool


cdef class _SyclDevice:
Expand Down
Loading