Skip to content

Commit 5e5ddb9

Browse files
Use public api keyword in declaring Cython classes
Use api keyword in declaring API functions. Use of API defines initializer functions which allows native extensions that work with dpctl Python types to not link to Python-produced shared objects on Linux, and allows for pybind11 to portably work with Python types defined in dpctl. Example for working with dpctl types is to be added to dpctl/examples
1 parent 260573c commit 5e5ddb9

12 files changed

+34
-21
lines changed

MANIFEST.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ include versioneer.py
22
recursive-include dpctl/include *.h
33
recursive-include dpctl *.pxd
44
include dpctl/_sycl_context.h
5+
include dpctl/_sycl_context_api.h
56
include dpctl/_sycl_device.h
7+
include dpctl/_sycl_device_api.h
68
include dpctl/_sycl_queue.h
7-
include dpctl/_sycl_queue_manager.h
9+
include dpctl/_sycl_queue_api.h
810
include dpctl/_sycl_event.h
11+
include dpctl/_sycl_event_api.h
912
include dpctl/memory/_memory.h
13+
include dpctl/memory/_memory_api.h
14+
include dpctl/tensor/_usmarray.h
15+
include dpctl/tensor/_usmarray_api.h
1016
include dpctl/tests/input_files/*

dpctl/_sycl_context.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ from ._backend cimport DPCTLSyclContextRef
2626
from ._sycl_device cimport SyclDevice
2727

2828

29-
cdef public class _SyclContext [
29+
cdef public api class _SyclContext [
3030
object Py_SyclContextObject,
3131
type Py_SyclContextType
3232
]:
@@ -35,7 +35,7 @@ cdef public class _SyclContext [
3535
cdef DPCTLSyclContextRef _ctxt_ref
3636

3737

38-
cdef public class SyclContext(_SyclContext) [
38+
cdef public api class SyclContext(_SyclContext) [
3939
object PySyclContextObject,
4040
type PySyclContextType
4141
]:

dpctl/_sycl_context.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ cdef class SyclContext(_SyclContext):
474474
&_context_capsule_deleter
475475
)
476476

477-
cdef public DPCTLSyclContextRef get_context_ref(SyclContext ctx):
477+
cdef api DPCTLSyclContextRef get_context_ref(SyclContext ctx):
478478
"""
479479
C-API function to get opaque context reference from
480480
:class:`dpctl.SyclContext` instance.

dpctl/_sycl_device.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from ._backend cimport (
2929
)
3030

3131

32-
cdef public class _SyclDevice [
32+
cdef public api class _SyclDevice [
3333
object Py_SyclDeviceObject,
3434
type Py_SyclDeviceType
3535
]:
@@ -42,7 +42,7 @@ cdef public class _SyclDevice [
4242
cdef size_t *_max_work_item_sizes
4343

4444

45-
cdef public class SyclDevice(_SyclDevice) [
45+
cdef public api class SyclDevice(_SyclDevice) [
4646
object PySyclDeviceObject,
4747
type PySyclDeviceType
4848
]:

dpctl/_sycl_device.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ cdef class SyclDevice(_SyclDevice):
11181118
else:
11191119
return str(relId)
11201120

1121-
cdef public DPCTLSyclDeviceRef get_device_ref(SyclDevice dev):
1121+
cdef api DPCTLSyclDeviceRef get_device_ref(SyclDevice dev):
11221122
"""
11231123
C-API function to get opaque device reference from
11241124
:class:`dpctl.SyclDevice` instance.

dpctl/_sycl_event.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from ._backend cimport DPCTLSyclEventRef
2424

2525

26-
cdef public class SyclEvent [object PySyclEventObject, type PySyclEventType]:
26+
cdef public api class SyclEvent [object PySyclEventObject, type PySyclEventType]:
2727
''' Wrapper class for a Sycl Event
2828
'''
2929
cdef DPCTLSyclEventRef _event_ref

dpctl/_sycl_event.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ __all__ = [
3232
_logger = logging.getLogger(__name__)
3333

3434

35+
cdef api DPCTLSyclEventRef get_event_ref(SyclEvent ev):
36+
""" C-API function to access opaque event reference from
37+
Python object of type :class:`dpctl.SyclEvent`.
38+
"""
39+
return ev.get_event_ref()
40+
41+
3542
cdef class SyclEvent:
3643
""" Python wrapper class for cl::sycl::event.
3744
"""

dpctl/_sycl_queue.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ from .program._program cimport SyclKernel
3131

3232
cdef void default_async_error_handler(int) nogil except *
3333

34-
cdef public class _SyclQueue [
34+
cdef public api class _SyclQueue [
3535
object Py_SyclQueueObject, type Py_SyclQueueType
3636
]:
3737
""" Python data owner class for a sycl::queue.
@@ -41,7 +41,7 @@ cdef public class _SyclQueue [
4141
cdef SyclDevice _device
4242

4343

44-
cdef public class SyclQueue (_SyclQueue) [
44+
cdef public api class SyclQueue (_SyclQueue) [
4545
object PySyclQueueObject, type PySyclQueueType
4646
]:
4747
""" Python wrapper class for a sycl::queue.

dpctl/_sycl_queue.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ cdef class SyclQueue(_SyclQueue):
969969
self.sycl_device.print_device_info()
970970

971971

972-
cdef public DPCTLSyclQueueRef get_queue_ref(SyclQueue q):
972+
cdef api DPCTLSyclQueueRef get_queue_ref(SyclQueue q):
973973
"""
974974
C-API function to get opaque queue reference from
975975
:class:`dpctl.SyclQueue` instance.

dpctl/memory/_memory.pxd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cdef DPCTLSyclQueueRef get_queue_ref_from_ptr_and_syclobj(
3232
DPCTLSyclUSMRef ptr, object syclobj)
3333

3434

35-
cdef public class _Memory [object Py_MemoryObject, type Py_MemoryType]:
35+
cdef public api class _Memory [object Py_MemoryObject, type Py_MemoryType]:
3636
cdef DPCTLSyclUSMRef memory_ptr
3737
cdef Py_ssize_t nbytes
3838
cdef SyclQueue queue
@@ -51,25 +51,25 @@ cdef public class _Memory [object Py_MemoryObject, type Py_MemoryType]:
5151
cpdef bytes tobytes(self)
5252

5353
@staticmethod
54-
cdef public SyclDevice get_pointer_device(
54+
cdef SyclDevice get_pointer_device(
5555
DPCTLSyclUSMRef p, SyclContext ctx)
5656
@staticmethod
57-
cdef public bytes get_pointer_type(DPCTLSyclUSMRef p, SyclContext ctx)
57+
cdef bytes get_pointer_type(DPCTLSyclUSMRef p, SyclContext ctx)
5858
@staticmethod
59-
cdef public object create_from_usm_pointer_size_qref(
59+
cdef object create_from_usm_pointer_size_qref(
6060
DPCTLSyclUSMRef USMRef,
6161
Py_ssize_t nbytes,
6262
DPCTLSyclQueueRef QRef,
6363
object memory_owner=*
6464
)
6565

6666

67-
cdef public class MemoryUSMShared(_Memory) [object PyMemoryUSMSharedObject,
67+
cdef public api class MemoryUSMShared(_Memory) [object PyMemoryUSMSharedObject,
6868
type PyMemoryUSMSharedType]:
6969
pass
7070

7171

72-
cdef public class MemoryUSMHost(_Memory) [object PyMemoryUSMHostObject,
72+
cdef public api class MemoryUSMHost(_Memory) [object PyMemoryUSMHostObject,
7373
type PyMemoryUSMHostType]:
7474
pass
7575

dpctl/memory/_memory.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,11 @@ def as_usm_memory(obj):
708708
)
709709

710710

711-
cdef public DPCTLSyclUSMRef get_usm_pointer(_Memory obj):
711+
cdef api DPCTLSyclUSMRef get_usm_pointer(_Memory obj):
712712
return obj.memory_ptr
713713

714-
cdef public DPCTLSyclContextRef get_context(_Memory obj):
714+
cdef api DPCTLSyclContextRef get_context(_Memory obj):
715715
return obj.queue._context.get_context_ref()
716716

717-
cdef public size_t get_nbytes(_Memory obj):
717+
cdef api size_t get_nbytes(_Memory obj):
718718
return <size_t>obj.nbytes

dpctl/tensor/_usmarray.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cdef public int USM_ARRAY_F_CONTIGUOUS
99
cdef public int USM_ARRAY_WRITEABLE
1010

1111

12-
cdef public class usm_ndarray [object PyUSMArrayObject, type PyUSMArrayType]:
12+
cdef public api class usm_ndarray [object PyUSMArrayObject, type PyUSMArrayType]:
1313
# data fields
1414
cdef char* data_
1515
cdef readonly int nd_

0 commit comments

Comments
 (0)