Skip to content

Commit 0a79e66

Browse files
Avoid using dpnp.random in cupy tests on CUDA
1 parent f1c5eaf commit 0a79e66

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

dpnp/tests/third_party/cupy/creation_tests/test_from_data.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
import dpnp as cupy
9-
from dpnp.tests.helper import has_support_aspect64
9+
from dpnp.tests.helper import has_support_aspect64, is_cuda_device
1010
from dpnp.tests.third_party.cupy import testing
1111

1212

@@ -521,7 +521,13 @@ def test_copy_multigpu(self, dtype, order):
521521
q1 = dpctl.SyclQueue()
522522
q2 = dpctl.SyclQueue()
523523

524-
src = cupy.random.uniform(-1, 1, (2, 3), device=q1).astype(dtype)
524+
# TODO: remove it once the issue with CUDA support is resolved
525+
# for dpnp.random
526+
if is_cuda_device():
527+
src_np = numpy.random.uniform(-1, 1, (2, 3)).astype(dtype)
528+
src = cupy.array(src_np, device=q1)
529+
else:
530+
src = cupy.random.uniform(-1, 1, (2, 3), device=q1).astype(dtype)
525531
dst = cupy.copy(src, order, device=q2)
526532
testing.assert_allclose(src, dst, rtol=0, atol=0)
527533

dpnp/tests/third_party/cupy/math_tests/test_rational.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import unittest
22

3+
import numpy
34
import pytest
45

56
import dpnp as cupy
7+
from dpnp.tests.helper import is_cuda_device
68
from dpnp.tests.third_party.cupy import testing
79

810

911
class TestRational(unittest.TestCase):
1012
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
1113
@testing.for_dtypes(["?", "e", "f", "d", "F", "D"])
1214
def test_gcd_dtype_check(self, dtype):
13-
a = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
14-
b = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
15+
# TODO: remove it once the issue with CUDA support is resolved
16+
# for dpnp.random
17+
if is_cuda_device():
18+
a = cupy.asarray(
19+
numpy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
20+
)
21+
b = cupy.asarray(
22+
numpy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
23+
)
24+
else:
25+
a = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
26+
b = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
1527
with pytest.raises(ValueError):
1628
cupy.gcd(a, b)
1729

@@ -25,8 +37,16 @@ def test_gcd_check_boundary_cases(self, xp, dtype):
2537
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
2638
@testing.for_dtypes(["?", "e", "f", "d", "F", "D"])
2739
def test_lcm_dtype_check(self, dtype):
28-
a = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
29-
b = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
40+
if is_cuda_device():
41+
a = cupy.asarray(
42+
numpy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
43+
)
44+
b = cupy.asarray(
45+
numpy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
46+
)
47+
else:
48+
a = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
49+
b = cupy.random.randint(-10, 10, size=(10, 10)).astype(dtype)
3050
with pytest.raises(ValueError):
3151
cupy.lcm(a, b)
3252

dpnp/tests/third_party/cupy/testing/_random.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy
99

1010
import dpnp as cupy
11+
from dpnp.tests.helper import is_cuda_device
1112

1213
_old_python_random_state = None
1314
_old_numpy_random_state = None
@@ -33,11 +34,15 @@ def do_setup(deterministic=True):
3334
if not deterministic:
3435
random.seed()
3536
numpy.random.seed()
36-
cupy.random.seed()
37+
# TODO: remove it once the issue with CUDA support is resolved
38+
# for dpnp.random
39+
if not is_cuda_device():
40+
cupy.random.seed()
3741
else:
3842
random.seed(99)
3943
numpy.random.seed(100)
40-
cupy.random.seed(101)
44+
if not is_cuda_device():
45+
cupy.random.seed(101)
4146

4247

4348
def do_teardown():

0 commit comments

Comments
 (0)