Skip to content

Commit c8053d7

Browse files
Feature/memory queue=none (#382)
* Modified queue=None behavior for Memory objects queue=None is now understood as use `dpctl.SyclQueue()` queue. * use raise newError from oldError syntax * Use explicit queue= argument in memory buffer constructors, now that it no longer uses get_current_queue
1 parent 8dd05e6 commit c8053d7

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

dpctl/_sycl_device.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ cdef class SyclDevice(_SyclDevice):
762762
partition = int(partition)
763763
return self.create_sub_devices_equally(partition)
764764
except Exception as e:
765-
raise TypeError("Unsupported type of sub-device argument")
765+
raise TypeError("Unsupported type of sub-device argument") from e
766766

767767
@property
768768
def parent_device(self):

dpctl/memory/_memory.pyx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ from dpctl._backend cimport *
2828
from .._sycl_context cimport SyclContext
2929
from .._sycl_device cimport SyclDevice
3030
from .._sycl_queue cimport SyclQueue
31-
from .._sycl_queue_manager cimport get_current_queue
3231

3332
from cpython cimport Py_buffer
3433
from cpython.bytes cimport PyBytes_AS_STRING, PyBytes_FromStringAndSize
@@ -222,7 +221,7 @@ cdef class _Memory:
222221

223222
if (nbytes > 0):
224223
if queue is None:
225-
queue = get_current_queue()
224+
queue = dpctl.SyclQueue()
226225

227226
if (ptr_type == b"shared"):
228227
if alignment > 0:
@@ -493,7 +492,7 @@ cdef class MemoryUSMShared(_Memory):
493492
USM shared memory.
494493
495494
Non-positive alignments are not used (malloc_shared is used instead).
496-
The queue=None the current `dpctl.get_current_queue()` is used to allocate memory.
495+
For the queue=None cast the `dpctl.SyclQueue()` is used to allocate memory.
497496
498497
MemoryUSMShared(usm_obj) constructor create instance from `usm_obj` expected to
499498
implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of
@@ -525,7 +524,7 @@ cdef class MemoryUSMHost(_Memory):
525524
USM host memory.
526525
527526
Non-positive alignments are not used (malloc_host is used instead).
528-
The queue=None the current `dpctl.get_current_queue()` is used to allocate memory.
527+
For the queue=None case `dpctl.SyclQueue()` is used to allocate memory.
529528
530529
MemoryUSMDevice(usm_obj) constructor create instance from `usm_obj` expected to
531530
implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of
@@ -557,7 +556,7 @@ cdef class MemoryUSMDevice(_Memory):
557556
USM device memory.
558557
559558
Non-positive alignments are not used (malloc_device is used instead).
560-
The queue=None the current `dpctl.get_current_queue()` is used to allocate memory.
559+
For the queue=None cast the `dpctl.SyclQueue()` is used to allocate memory.
561560
562561
MemoryUSMDevice(usm_obj) constructor create instance from `usm_obj` expected to
563562
implement `__sycl_usm_array_interface__` protocol and exposing a contiguous block of

dpctl/tests/test_sycl_kernel_submit.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,32 @@ def test_create_program_from_source(self):
3434
size_t index = get_global_id(0); \
3535
c[index] = d*a[index] + b[index]; \
3636
}"
37-
with dpctl.device_context("opencl:gpu:0"):
38-
q = dpctl.get_current_queue()
39-
prog = dpctl_prog.create_program_from_source(q, oclSrc)
40-
axpyKernel = prog.get_sycl_kernel("axpy")
37+
q = dpctl.SyclQueue("opencl:gpu")
38+
prog = dpctl_prog.create_program_from_source(q, oclSrc)
39+
axpyKernel = prog.get_sycl_kernel("axpy")
4140

42-
abuf = dpctl_mem.MemoryUSMShared(1024 * np.dtype("i").itemsize)
43-
bbuf = dpctl_mem.MemoryUSMShared(1024 * np.dtype("i").itemsize)
44-
cbuf = dpctl_mem.MemoryUSMShared(1024 * np.dtype("i").itemsize)
45-
a = np.ndarray((1024), buffer=abuf, dtype="i")
46-
b = np.ndarray((1024), buffer=bbuf, dtype="i")
47-
c = np.ndarray((1024), buffer=cbuf, dtype="i")
48-
a[:] = np.arange(1024)
49-
b[:] = np.arange(1024, 0, -1)
50-
c[:] = 0
51-
d = 2
52-
args = []
41+
bufBytes = 1024 * np.dtype("i").itemsize
42+
abuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
43+
bbuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
44+
cbuf = dpctl_mem.MemoryUSMShared(bufBytes, queue=q)
45+
a = np.ndarray((1024), buffer=abuf, dtype="i")
46+
b = np.ndarray((1024), buffer=bbuf, dtype="i")
47+
c = np.ndarray((1024), buffer=cbuf, dtype="i")
48+
a[:] = np.arange(1024)
49+
b[:] = np.arange(1024, 0, -1)
50+
c[:] = 0
51+
d = 2
52+
args = []
5353

54-
args.append(a.base)
55-
args.append(b.base)
56-
args.append(c.base)
57-
args.append(ctypes.c_int(d))
54+
args.append(a.base)
55+
args.append(b.base)
56+
args.append(c.base)
57+
args.append(ctypes.c_int(d))
5858

59-
r = [1024]
59+
r = [1024]
6060

61-
q.submit(axpyKernel, args, r)
62-
self.assertTrue(np.allclose(c, a * d + b))
61+
q.submit(axpyKernel, args, r)
62+
self.assertTrue(np.allclose(c, a * d + b))
6363

6464

6565
if __name__ == "__main__":

dpctl/tests/test_sycl_queue_memcpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_memcpy_copy_usm_to_usm(self):
5151
)
5252
def test_memcpy_type_error(self):
5353
mobj = self._create_memory()
54-
q = dpctl.get_current_queue()
54+
q = mobj._queue
5555

5656
with self.assertRaises(TypeError) as cm:
5757
q.memcpy(None, mobj, 3)

0 commit comments

Comments
 (0)