Skip to content
Merged
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
45 changes: 34 additions & 11 deletions tests/test_cupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,41 @@
from cupy.cuda import Stream


def test_to_device_with_stream():
@pytest.mark.parametrize(
"make_stream",
[
lambda: Stream(),
lambda: Stream(non_blocking=True),
lambda: Stream(null=True),
lambda: Stream(ptds=True),
],
)
def test_to_device_with_stream(make_stream):
devices = xp.__array_namespace_info__().devices()
streams = [
Stream(),
Stream(non_blocking=True),
Stream(null=True),
Stream(ptds=True),
123, # dlpack stream
]

a = xp.asarray([1, 2, 3])
for dev in devices:
for stream in streams:
b = to_device(a, dev, stream=stream)
assert device(b) == dev
# Streams are device-specific and must be created within
# the context of the device...
with dev:
stream = make_stream()
# ... however, to_device() does not need to be inside the
# device context.
b = to_device(a, dev, stream=stream)
assert device(b) == dev


def test_to_device_with_dlpack_stream():
devices = xp.__array_namespace_info__().devices()

a = xp.asarray([1, 2, 3])
for dev in devices:
# Streams are device-specific and must be created within
# the context of the device...
with dev:
s1 = Stream()

# ... however, to_device() does not need to be inside the
# device context.
b = to_device(a, dev, stream=s1.ptr)
assert device(b) == dev
Loading