Skip to content

Commit 8129cfb

Browse files
committed
Merge commit 'b97efdf' into gold/2021
2 parents 73ccfa3 + b97efdf commit 8129cfb

32 files changed

+1565
-731
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ per-file-ignores =
2424
dpctl/program/_program.pyx: E999, E225, E226, E227
2525
dpctl/tensor/_usmarray.pyx: E999, E225, E226, E227
2626
dpctl/tensor/numpy_usm_shared.py: F821
27+
dpctl/tests/_cython_api.pyx: E999, E225, E227, E402
2728
examples/cython/sycl_buffer/_buffer_example.pyx: E999, E225, E402
2829
examples/cython/sycl_direct_linkage/_buffer_example.pyx: E999, E225, E402
2930
examples/cython/usm_memory/blackscholes.pyx: E999, E225, E226, E402

.github/workflows/generate-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
source /opt/intel/oneapi/setvars.sh
8888
python setup.py develop --coverage=True
8989
python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()"
90-
pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv
90+
pytest -q -ra --disable-warnings --cov-config pyproject.toml --cov dpctl --cov-report term-missing --pyargs dpctl -vv
9191
9292
- name: Install coverall dependencies
9393
shell: bash -l {0}

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ include dpctl/memory/_memory_api.h
1414
include dpctl/tensor/_usmarray.h
1515
include dpctl/tensor/_usmarray_api.h
1616
include dpctl/tests/input_files/*
17+
include dpctl/tests/*.pyx

conda-recipe/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ requirements:
3232

3333
test:
3434
requires:
35+
- cython
3536
- pytest
3637
- pytest-cov
3738

dpctl/_sycl_context.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ cdef void _context_capsule_deleter(object o):
6363
o, "SyclContextRef"
6464
)
6565
DPCTLContext_Delete(CRef)
66+
elif pycapsule.PyCapsule_IsValid(o, "used_SyclContextRef"):
67+
CRef = <DPCTLSyclContextRef> pycapsule.PyCapsule_GetPointer(
68+
o, "used_SyclContextRef"
69+
)
70+
DPCTLContext_Delete(CRef)
6671

6772

6873
cdef void _init_helper(_SyclContext context, DPCTLSyclContextRef CRef):

dpctl/_sycl_device.pyx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,8 @@ cdef class SyclDevice(_SyclDevice):
253253
cdef const char *filter_c_str = NULL
254254
cdef int ret = 0
255255

256-
if type(arg) is unicode:
257-
string = bytes(<unicode>arg, "utf-8")
258-
filter_c_str = string
259-
DSRef = DPCTLFilterSelector_Create(filter_c_str)
260-
ret = self._init_from_selector(DSRef)
261-
if ret == -1:
262-
raise ValueError(
263-
"Could not create a SyclDevice with the selector string"
264-
)
265-
elif isinstance(arg, unicode):
266-
string = bytes(<unicode>unicode(arg), "utf-8")
256+
if type(arg) is str:
257+
string = bytes(<str>arg, "utf-8")
267258
filter_c_str = string
268259
DSRef = DPCTLFilterSelector_Create(filter_c_str)
269260
ret = self._init_from_selector(DSRef)

dpctl/_sycl_event.pyx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ cdef void _event_capsule_deleter(object o):
7171
o, "SyclEventRef"
7272
)
7373
DPCTLEvent_Delete(ERef)
74+
elif pycapsule.PyCapsule_IsValid(o, "used_SyclEventRef"):
75+
ERef = <DPCTLSyclEventRef> pycapsule.PyCapsule_GetPointer(
76+
o, "used_SyclEventRef"
77+
)
78+
DPCTLEvent_Delete(ERef)
7479

7580

7681
cdef void _init_helper(_SyclEvent event, DPCTLSyclEventRef ERef):
@@ -83,8 +88,10 @@ cdef class _SyclEvent:
8388
"""
8489

8590
def __dealloc__(self):
86-
DPCTLEvent_Wait(self._event_ref)
87-
DPCTLEvent_Delete(self._event_ref)
91+
if (self._event_ref):
92+
DPCTLEvent_Wait(self._event_ref)
93+
DPCTLEvent_Delete(self._event_ref)
94+
self._event_ref = NULL
8895
self.args = None
8996

9097

@@ -318,6 +325,7 @@ cdef class SyclEvent(_SyclEvent):
318325
DPCTLEventVector_Delete(EVRef)
319326
return events
320327

328+
@property
321329
def profiling_info_submit(self):
322330
"""
323331
Returns the 64-bit time value in nanoseconds

dpctl/_sycl_queue.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ cdef public api class SyclQueue (_SyclQueue) [
6666
cdef SyclQueue _create(DPCTLSyclQueueRef qref)
6767
@staticmethod
6868
cdef SyclQueue _create_from_context_and_device(
69-
SyclContext ctx, SyclDevice dev
69+
SyclContext ctx, SyclDevice dev, int props=*
7070
)
7171
cdef cpp_bool equals(self, SyclQueue q)
7272
cpdef SyclContext get_sycl_context(self)

dpctl/_sycl_queue.pyx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ cdef void _queue_capsule_deleter(object o):
160160
o, "SyclQueueRef"
161161
)
162162
DPCTLQueue_Delete(QRef)
163+
elif pycapsule.PyCapsule_IsValid(o, "used_SyclQueueRef"):
164+
QRef = <DPCTLSyclQueueRef> pycapsule.PyCapsule_GetPointer(
165+
o, "used_SyclQueueRef"
166+
)
167+
DPCTLQueue_Delete(QRef)
163168

164169

165170
cdef class _SyclQueue:
@@ -284,18 +289,13 @@ cdef class SyclQueue(_SyclQueue):
284289
status = self._init_queue_default(props)
285290
elif len_args == 1:
286291
arg = args[0]
287-
if type(arg) is unicode:
288-
string = bytes(<unicode>arg, "utf-8")
292+
if type(arg) is str:
293+
string = bytes(<str>arg, "utf-8")
289294
filter_c_str = string
290295
status = self._init_queue_from_filter_string(
291296
filter_c_str, props)
292297
elif type(arg) is _SyclQueue:
293298
status = self._init_queue_from__SyclQueue(<_SyclQueue>arg)
294-
elif isinstance(arg, unicode):
295-
string = bytes(<unicode>unicode(arg), "utf-8")
296-
filter_c_str = string
297-
status = self._init_queue_from_filter_string(
298-
filter_c_str, props)
299299
elif isinstance(arg, SyclDevice):
300300
status = self._init_queue_from_device(<SyclDevice>arg, props)
301301
elif pycapsule.PyCapsule_IsValid(arg, "SyclQueueRef"):
@@ -537,13 +537,24 @@ cdef class SyclQueue(_SyclQueue):
537537

538538
@staticmethod
539539
cdef SyclQueue _create_from_context_and_device(
540-
SyclContext ctx, SyclDevice dev
540+
SyclContext ctx, SyclDevice dev, int props=0
541541
):
542+
"""
543+
Static factory method to create :class:`dpctl.SyclQueue` instance
544+
from given :class:`dpctl.SyclContext`, :class:`dpctl.SyclDevice`
545+
and optional integer `props` encoding the queue properties.
546+
"""
542547
cdef _SyclQueue ret = _SyclQueue.__new__(_SyclQueue)
543548
cdef DPCTLSyclContextRef cref = ctx.get_context_ref()
544549
cdef DPCTLSyclDeviceRef dref = dev.get_device_ref()
545-
cdef DPCTLSyclQueueRef qref = DPCTLQueue_Create(cref, dref, NULL, 0)
550+
cdef DPCTLSyclQueueRef qref = NULL
546551

552+
qref = DPCTLQueue_Create(
553+
cref,
554+
dref,
555+
<error_handler_callback *>&default_async_error_handler,
556+
props
557+
)
547558
if qref is NULL:
548559
raise SyclQueueCreationError("Queue creation failed.")
549560
ret._queue_ref = qref
@@ -644,8 +655,12 @@ cdef class SyclQueue(_SyclQueue):
644655
else:
645656
return False
646657

647-
def get_sycl_backend(self):
648-
""" Returns the Sycl backend associated with the queue.
658+
@property
659+
def backend(self):
660+
""" Returns the backend_type enum value for this queue.
661+
662+
Returns:
663+
backend_type: The backend for the queue.
649664
"""
650665
cdef _backend_type BE = DPCTLQueue_GetBackend(self._queue_ref)
651666
if BE == _backend_type._OPENCL:
@@ -685,7 +700,7 @@ cdef class SyclQueue(_SyclQueue):
685700
The address of the ``DPCTLSyclQueueRef`` object used to create this
686701
:class:`dpctl.SyclQueue` cast to a ``size_t``.
687702
"""
688-
return int(<size_t>self._queue_ref)
703+
return <size_t>self._queue_ref
689704

690705
cpdef SyclEvent submit(
691706
self,
@@ -843,8 +858,8 @@ cdef class SyclQueue(_SyclQueue):
843858
else:
844859
raise TypeError("Parameter `mem` should have type _Memory")
845860

846-
if (count <=0 or count > self.nbytes):
847-
count = self.nbytes
861+
if (count <=0 or count > mem.nbytes):
862+
count = mem.nbytes
848863

849864
ERef = DPCTLQueue_Prefetch(self._queue_ref, ptr, count)
850865
if (ERef is NULL):
@@ -863,8 +878,8 @@ cdef class SyclQueue(_SyclQueue):
863878
else:
864879
raise TypeError("Parameter `mem` should have type _Memory")
865880

866-
if (count <=0 or count > self.nbytes):
867-
count = self.nbytes
881+
if (count <=0 or count > mem.nbytes):
882+
count = mem.nbytes
868883

869884
ERef = DPCTLQueue_MemAdvise(self._queue_ref, ptr, count, advice)
870885
if (ERef is NULL):
@@ -959,16 +974,6 @@ cdef class SyclQueue(_SyclQueue):
959974

960975
return SyclEvent._create(ERef, [])
961976

962-
@property
963-
def backend(self):
964-
"""Returns the backend_type enum value for the device
965-
associated with this queue.
966-
967-
Returns:
968-
backend_type: The backend for the device.
969-
"""
970-
return self.sycl_device.backend
971-
972977
@property
973978
def name(self):
974979
"""Returns the device name for the device

dpctl/_sycl_queue_manager.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ cdef class _SyclQueueManager:
7878
Returns:
7979
backend_type: The SYCL backend for the currently selected queue.
8080
"""
81-
return self.get_current_queue().get_sycl_backend()
81+
return self.get_current_queue().backend
8282

8383
cpdef get_current_device_type(self):
8484
"""
@@ -88,7 +88,7 @@ cdef class _SyclQueueManager:
8888
device_type: The SYCL device type for the currently selected queue.
8989
Possible values can be gpu, cpu, accelerator, or host.
9090
"""
91-
return self.get_current_queue().get_sycl_device().device_type
91+
return self.get_current_queue().sycl_device.device_type
9292

9393
cpdef SyclQueue get_current_queue(self):
9494
"""

0 commit comments

Comments
 (0)