Skip to content

Added support for stream other than None #906

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

Merged
merged 2 commits into from
Sep 13, 2022
Merged
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
13 changes: 7 additions & 6 deletions dpctl/tensor/_usmarray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,14 @@ cdef class usm_ndarray:
NotImplementedError: when non-default value of `stream` keyword
is used.
"""
if stream is None:
return c_dlpack.to_dlpack_capsule(self)
_caps = c_dlpack.to_dlpack_capsule(self)
if (stream is None or type(stream) is not dpctl.SyclQueue or
stream == self.sycl_queue):
pass
else:
raise NotImplementedError(
"Only stream=None is supported. "
"Use `dpctl.SyclQueue.submit_barrier` to synchronize queues."
)
ev = self.sycl_queue.submit_barrier()
stream.submit_barrier(dependent_events=[ev])
return _caps

def __dlpack_device__(self):
"""
Expand Down
12 changes: 12 additions & 0 deletions dpctl/tests/test_usm_ndarray_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def test_dlpack_exporter(typestr, usm_type):
assert caps_fn(caps2, b"dltensor")


def test_dlpack_exporter_stream():
try:
q1 = dpctl.SyclQueue()
q2 = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Could not create default queues")
X = dpt.empty((64,), dtype="u1", sycl_queue=q1)
cap1 = X.__dlpack__(stream=q1)
cap2 = X.__dlpack__(stream=q2)
assert type(cap1) is type(cap2)


@pytest.mark.parametrize("shape", [tuple(), (2,), (3, 0, 1), (2, 2, 2)])
def test_from_dlpack(shape, typestr, usm_type):
all_root_devices = dpctl.get_devices()
Expand Down