Skip to content
Draft
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
7 changes: 7 additions & 0 deletions dpnp/tests/third_party/cupy/core_tests/test_dlpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ def pool(self):
# cupy.cuda.set_allocator(old_pool.malloc)
pass

@pytest.mark.parametrize("shape", [(), (5,), (3, 4), (2, 3, 4), (0, 3)])
def test_memory_size(self, shape):
array = cupy.empty(shape, dtype=cupy.float32)
out = cupy.from_dlpack(array)
# dpnp allocates at least one element for an empty array
assert out.data.size == max(array.nbytes, array.itemsize)

@pytest.mark.parametrize("max_version", [None, (1, 0)])
# @pytest.mark.thread_unsafe(reason="modifies pool and tracks allocations")
def test_deleter(self, pool, max_version):
Expand Down
6 changes: 1 addition & 5 deletions dpnp/tests/third_party/cupy/core_tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import dpnp as cupy

# from cupy._core import core
# from cupy.cuda import compiler
# from cupy.cuda import runtime
from dpnp.tests.third_party.cupy import testing

pytest.skip(
Expand All @@ -16,9 +14,7 @@


def _compile_func(kernel_name, code):
# workaround for hipRTC
extra_source = core._get_header_source() if runtime.is_hip else None
mod = compiler._compile_module_with_cache(code, extra_source=extra_source)
mod = compiler._compile_module_with_cache(code)
return mod.get_function(kernel_name)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ def test_min_inf(self, exclude_cutensor, xp, dtype, order):
a = xp.array([float("inf"), float("inf")], dtype, order=order)
return a.min()

@pytest.mark.parametrize("has_out", [False, True])
@pytest.mark.parametrize(
"axis,out_shape",
[(None, ()), (0, (3, 4)), (1, (2, 4)), (2, (2, 3)), ((1, 2), (2,))],
)
@pytest.mark.parametrize("func", ["max", "min"])
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(contiguous_check=False)
def test_minmax_out(self, xp, dtype, order, func, axis, out_shape, has_out):
# See gh-9032
a = testing.shaped_random((2, 3, 4), xp, dtype, order=order)
if not has_out:
return getattr(a, func)(axis=axis)
out = xp.zeros(out_shape, dtype=dtype)
ret = getattr(a, func)(axis=axis, out=out)
assert ret is out
return out

@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(contiguous_check=False)
def test_argmax_all(self, xp, dtype, order):
Expand Down
8 changes: 6 additions & 2 deletions dpnp/tests/third_party/cupy/core_tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,10 @@ def test_get_function_failure(self, configure):
cupy.cuda.runtime.is_hip,
reason="ROCm/HIP does not support dynamic parallelism",
)
def test_dynamical_parallelism(self, backend, jitify):
@pytest.mark.thread_unsafe(reason="Changes header-cache policy")
def test_dynamical_parallelism(
self, backend, jitify, allow_full_header_cache
):
self._check_ptx_loadable("nvrtc")
ker = cupy.RawKernel(
_test_source4,
Expand Down Expand Up @@ -1553,7 +1556,8 @@ def test_jitify4(self, jitify):
# if Jitify could redirect its output, we would be able to check
# the error log here as well (NVIDIA/jitify#79)

def test_jitify5(self, configure, jitify):
@pytest.mark.thread_unsafe(reason="Changes strict header-cache checking")
def test_jitify5(self, configure, jitify, allow_full_header_cache):
temp_dir = configure
# If including a header that does not exist, Jitify would attempt to
# comment it out and proceed. If this header is actually unused, then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
# DiskKernelCacheBackend,
# _hash_length,
# _default_cache_dir,
# _hash_hexdigest,
# )


def test_hash_hexdigest_chunks():
chunks = ("", b"a", "\u03b2", b"", "c")
assert _hash_hexdigest(*chunks) == _hash_hexdigest(b"\0a\0\xce\xb2\0\0c")
assert _hash_hexdigest(*chunks, sep=None) == _hash_hexdigest(b"a\xce\xb2c")


class TestDiskKernelCacheBackend:
"""Tests for DiskKernelCacheBackend implementation."""

Expand Down
17 changes: 13 additions & 4 deletions dpnp/tests/third_party/cupy/fft_tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import queue
import threading
import unittest
import warnings

import pytest

Expand Down Expand Up @@ -280,8 +281,12 @@ def test_LRU_cache7(self, gpus=None):
assert cache1.get_curr_size() == 0 <= cache1.get_size()

# do a multi-GPU FFT
config.use_multi_gpus = True
config.set_cufft_gpus([0, 1])
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Multi-GPU FFT is deprecated", DeprecationWarning
)
config.use_multi_gpus = True
config.set_cufft_gpus([0, 1])
c = testing.shaped_random((128,), cupy, cupy.complex64)
cupy.fft.fft(c)
assert cache0.get_curr_size() == 2 <= cache0.get_size()
Expand Down Expand Up @@ -309,8 +314,12 @@ def test_LRU_cache7(self, gpus=None):
assert plan1 is not next(iter(cache1))[1].plan

# now use it again to make it the most recent
config.use_multi_gpus = True
config.set_cufft_gpus([0, 1])
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Multi-GPU FFT is deprecated", DeprecationWarning
)
config.use_multi_gpus = True
config.set_cufft_gpus([0, 1])
c = testing.shaped_random((128,), cupy, cupy.complex64)
cupy.fft.fft(c)
assert cache0.get_curr_size() == 2 <= cache0.get_size()
Expand Down
40 changes: 34 additions & 6 deletions dpnp/tests/third_party/cupy/fft_tests/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ def test_func(self, *args, **kw):
try:
nGPUs = len(gpus)
assert nGPUs >= 2, "Must use at least two gpus"
config.use_multi_gpus = True
config.set_cufft_gpus(gpus)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
"Multi-GPU FFT is deprecated",
DeprecationWarning,
)
config.use_multi_gpus = True
config.set_cufft_gpus(gpus)

impl(self, *args, **kw)
except Exception:
Expand All @@ -113,6 +119,24 @@ def test_func(self, *args, **kw):
return decorator


@pytest.mark.skip("multi GPU is not supported")
@pytest.mark.filterwarnings("ignore:.* is experimental:FutureWarning")
def test_multi_gpu_config_deprecated():
use_multi_gpus = config._use_multi_gpus.get()
_devices = config._devices.get()
try:
with pytest.warns(DeprecationWarning, match="Multi-GPU FFT"):
config.use_multi_gpus = True
with pytest.warns(DeprecationWarning, match="Multi-GPU FFT"):
config.set_cufft_gpus([0, 1])
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
config.use_multi_gpus = False
finally:
config._use_multi_gpus.set(use_multi_gpus)
config._devices.set(_devices)


@testing.with_requires("numpy>=2.0")
@pytest.mark.usefixtures("skip_forward_backward")
@testing.parameterize(
Expand Down Expand Up @@ -770,10 +794,14 @@ def test_plan_nd_init_api(api):
a.shape, CUFFT_R2C, axes=axes, order="C", out_size=5
)
# But additionally pass order, last_axis, and last_size to test old API.
if api == "old":
plan = PlanNd(*relevant_args, "C", 2, 5)
else:
plan = PlanNd(*relevant_args)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Direct instantiation", DeprecationWarning
)
if api == "old":
plan = PlanNd(*relevant_args, "C", 2, 5)
else:
plan = PlanNd(*relevant_args)

# These are not relevant and could probably be removed:
assert plan.order == ("C" if api == "old" else None)
Expand Down
27 changes: 16 additions & 11 deletions dpnp/tests/third_party/cupy/lib_tests/test_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,14 @@ def test_poly_ndim(self, dtype):
xp.poly(a)

@testing.for_all_dtypes(no_bool=True)
def test_poly_zero_dim(self, dtype):
for xp in (numpy, cupy):
a = testing.shaped_arange((), xp, dtype)
with pytest.raises(TypeError):
numpy.poly(a)
@testing.numpy_cupy_array_equal()
def test_poly_zero_dim(self, xp, dtype):
# NumPy currently accepts 0-D inputs, although that is debatable.
a = testing.shaped_arange((), xp, dtype)
if xp is numpy and testing.installed("numpy<2.6.0.dev0"):
# NumPy < 2.6 rejects 0-D inputs in the dispatcher.
a = a.ravel()
return xp.poly(a)

@testing.for_all_dtypes()
@testing.numpy_cupy_equal()
Expand Down Expand Up @@ -945,13 +948,15 @@ def test_roots_zero_sized(self, xp, dtype):
a = xp.zeros((0,), dtype)
return xp.roots(a)

@testing.with_requires("numpy>1.17")
@testing.for_all_dtypes(no_bool=True)
def test_roots_zero_dim(self, dtype):
for xp in (numpy, cupy):
a = testing.shaped_random((), xp, dtype)
with pytest.raises(TypeError):
xp.roots(a)
@testing.numpy_cupy_array_equal()
def test_roots_zero_dim(self, xp, dtype):
# NumPy currently accepts 0-D inputs, although that is debatable.
a = testing.shaped_random((), xp, dtype)
if xp is numpy and testing.installed("numpy<2.6.0.dev0"):
# NumPy < 2.6 rejects 0-D inputs in the dispatcher.
a = a.ravel()
return xp.roots(a)

@testing.for_all_dtypes(no_bool=True)
def test_roots_ndim(self, dtype):
Expand Down
31 changes: 19 additions & 12 deletions dpnp/tests/third_party/cupy/linalg_tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
from dpnp.tests.third_party.cupy import testing
from dpnp.tests.third_party.cupy.testing._helper import skip_if_after_baseline

# both numpy.dot (NumPy 2.6+) and dpnp.dot warn for a.ndim >= 2 and b.ndim > 2
_ignore_dot_nd_deprecation = pytest.mark.filterwarnings(
"ignore:.*dot received arrays with a.ndim >= 2:DeprecationWarning"
)


@testing.parameterize(
*testing.product(
Expand Down Expand Up @@ -50,9 +45,9 @@
class TestDot(unittest.TestCase):
# no_int8=True is added to avoid overflow for shape=((2, 3, 4), (3, 4, 2))
# and ((2, 3), (3, 4)) cases on cpu
@_ignore_dot_nd_deprecation
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"], no_int8=True)
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
@pytest.mark.filterwarnings("ignore:.*a.ndim.*b.ndim:DeprecationWarning")
def test_dot(self, xp, dtype_a, dtype_b):
shape_a, shape_b = self.shape
if self.trans_a:
Expand All @@ -65,11 +60,11 @@ def test_dot(self, xp, dtype_a, dtype_b):
b = testing.shaped_arange(shape_b, xp, dtype_b)
return xp.dot(a, b)

@_ignore_dot_nd_deprecation
@testing.for_float_dtypes(name="dtype_a")
@testing.for_float_dtypes(name="dtype_b")
@testing.for_float_dtypes(name="dtype_c")
@testing.numpy_cupy_allclose(accept_error=ValueError)
@pytest.mark.filterwarnings("ignore:.*a.ndim.*b.ndim:DeprecationWarning")
def test_dot_with_out(self, xp, dtype_a, dtype_b, dtype_c):
shape_a, shape_b = self.shape
if self.trans_a:
Expand Down Expand Up @@ -252,26 +247,38 @@ def test_dot_vec3(self, xp, dtype):
b = testing.shaped_arange((2,), xp, dtype)
return xp.dot(a, b)

@_ignore_dot_nd_deprecation
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_transposed_dot(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
b = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(0, 2, 1)
return xp.dot(a, b)
if xp is numpy and testing.numpy_satisfies("<2.6"):
res = xp.dot(a, b)
else:
# NumPy 2.6 deprecated this pointing at tensordot, we do too
with pytest.warns(DeprecationWarning, match="a.ndim.*b.ndim"):
res = xp.dot(a, b)

return res

@_ignore_dot_nd_deprecation
@testing.for_all_dtypes(no_int8=True)
@testing.numpy_cupy_allclose()
def test_transposed_dot_with_out(self, xp, dtype):
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
b = testing.shaped_arange((4, 2, 3), xp, dtype).transpose(2, 0, 1)
c = xp.ndarray((3, 2, 3, 2), dtype=dtype)
xp.dot(a, b, out=c)
if xp is numpy and testing.numpy_satisfies("<2.6"):
xp.dot(a, b, out=c)
else:
# NumPy 2.6 deprecated this pointing at tensordot, we do too
with pytest.warns(DeprecationWarning, match="a.ndim.*b.ndim"):
xp.dot(a, b, out=c)

return c

@_ignore_dot_nd_deprecation
@testing.for_all_dtypes()
# Note that CuPy doesn't warn here (it errors first)
@pytest.mark.filterwarnings("ignore:.*a.ndim.*b.ndim:DeprecationWarning")
def test_transposed_dot_with_out_f_contiguous(self, dtype):
for xp in (numpy, cupy):
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
Expand Down
17 changes: 6 additions & 11 deletions dpnp/tests/third_party/cupy/logic_tests/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,13 @@ def test_binary_array_pyscalar_int_and_float(self, xp, scalar, op, dtype):
b = scalar
return [op(a, b), op(b, a)]

@pytest.mark.skip("dpnp follows NumPy")
@pytest.mark.parametrize(
"scalar,safe_scalar",
[(2**63, 2), (2**63 + 100, 2), (-(2**63), -1)],
)
@pytest.mark.parametrize("scalar", [2**63, 2**63 + 100, -(2**63)])
@pytest.mark.parametrize("op", operators)
def test_binary_array_pyscalar_int_and_bool(self, scalar, safe_scalar, op):
# As of 2.5, NumPy uses the default integer and fails for very large
# Python scalars. But CuPy uses uint64 and succeeds.
a = cupy.array([True, False])
testing.assert_array_equal(op(a, scalar), op(a, safe_scalar))
testing.assert_array_equal(op(scalar, a), op(safe_scalar, a))
@pytest.mark.parametrize("reverse", [False, True])
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
def test_binary_array_pyscalar_int_and_bool(self, xp, scalar, op, reverse):
a = xp.array([True, False])
return op(scalar, a) if reverse else op(a, scalar)


class TestArrayEqual(unittest.TestCase):
Expand Down
13 changes: 6 additions & 7 deletions dpnp/tests/third_party/cupy/logic_tests/test_type_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy
import pytest

import dpnp as cupy
from dpnp.tests.third_party.cupy import testing


Expand Down Expand Up @@ -73,13 +74,11 @@ def setUp(self):
)
class TestIsFortran(unittest.TestCase):

# both numpy.isfortran (NumPy 2.6+) and dpnp.isfortran are deprecated
@pytest.mark.filterwarnings(
"ignore:.*isfortran is deprecated:DeprecationWarning"
)
@testing.numpy_cupy_equal()
def test(self, xp):
return xp.isfortran(xp.asarray(self.value))
def test(self):
a = cupy.asarray(self.value)
with pytest.warns(DeprecationWarning, match="isfortran is deprecated"):
result = cupy.isfortran(a)
assert result == self.value.flags.fnc


@testing.parameterize(
Expand Down
Loading
Loading