forked from data-apis/array-api-compat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cupy.py
More file actions
45 lines (37 loc) · 1.26 KB
/
test_cupy.py
File metadata and controls
45 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pytest
from array_api_compat import device, to_device
xp = pytest.importorskip("array_api_compat.cupy")
from cupy.cuda import 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()
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:
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