Skip to content

Commit

Permalink
Updated tests to run on Iris Xe. (#1548)
Browse files Browse the repository at this point in the history
* Updated tests to run on Iris Xe

* Update sycl_queue tests for run on Iris Xe
  • Loading branch information
npolina4 authored Sep 8, 2023
1 parent 239cca7 commit b5764e2
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 492 deletions.
2 changes: 1 addition & 1 deletion dpnp/dpnp_algo/dpnp_algo_mathematical.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ cpdef utils.dpnp_descriptor dpnp_gradient(utils.dpnp_descriptor y1, int dx=1):
# ceate result array with type given by FPTR data
cdef shape_type_c result_shape = utils._object_to_tuple(size)
cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(result_shape,
dpnp.float64,
dpnp.default_float_type(y1_obj.sycl_queue),
None,
device=y1_obj.sycl_device,
usm_type=y1_obj.usm_type,
Expand Down
419 changes: 1 addition & 418 deletions tests/skipped_tests_gpu_no_fp64.tbl

Large diffs are not rendered by default.

53 changes: 25 additions & 28 deletions tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def vvsort(val, vec, size, xp):
ids=[device.filter_string for device in valid_devices],
)
def test_array_creation(func, arg, kwargs, device):
numpy_array = getattr(numpy, func)(*arg, **kwargs)

dpnp_kwargs = dict(kwargs)
dpnp_kwargs["device"] = device
dpnp_array = getattr(dpnp, func)(*arg, **dpnp_kwargs)

assert_allclose(numpy_array, dpnp_array)
numpy_array = getattr(numpy, func)(*arg, dtype=dpnp_array.dtype, **kwargs)

assert_dtype_allclose(dpnp_array, numpy_array)
assert dpnp_array.sycl_device == device


Expand Down Expand Up @@ -766,11 +766,12 @@ def test_eig(device):
)

size = 4
a = numpy.arange(size * size, dtype="float64").reshape((size, size))
dtype = dpnp.default_float_type(device)
a = numpy.arange(size * size, dtype=dtype).reshape((size, size))
symm_orig = (
numpy.tril(a)
+ numpy.tril(a, -1).T
+ numpy.diag(numpy.full((size,), size * size, dtype="float64"))
+ numpy.diag(numpy.full((size,), size * size, dtype=dtype))
)
numpy_data = symm_orig
dpnp_symm_orig = dpnp.array(numpy_data, device=device)
Expand Down Expand Up @@ -815,11 +816,12 @@ def test_eig(device):
)
def test_eigh(device):
size = 4
a = numpy.arange(size * size, dtype=numpy.float64).reshape((size, size))
dtype = dpnp.default_float_type(device)
a = numpy.arange(size * size, dtype=dtype).reshape((size, size))
symm_orig = (
numpy.tril(a)
+ numpy.tril(a, -1).T
+ numpy.diag(numpy.full((size,), size * size, dtype=numpy.float64))
+ numpy.diag(numpy.full((size,), size * size, dtype=dtype))
)
numpy_data = symm_orig
dpnp_symm_orig = dpnp.array(numpy_data, device=device)
Expand Down Expand Up @@ -911,10 +913,9 @@ def test_matrix_rank(device):
ids=[device.filter_string for device in valid_devices],
)
def test_qr(device):
tol = 1e-11
data = [[1, 2, 3], [1, 2, 3]]
numpy_data = numpy.array(data)
data = [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
dpnp_data = dpnp.array(data, device=device)
numpy_data = numpy.array(data, dtype=dpnp_data.dtype)

np_q, np_r = numpy.linalg.qr(numpy_data, "reduced")
dpnp_q, dpnp_r = dpnp.linalg.qr(dpnp_data, "reduced")
Expand All @@ -924,8 +925,8 @@ def test_qr(device):
assert dpnp_q.shape == np_q.shape
assert dpnp_r.shape == np_r.shape

assert_allclose(dpnp_q, np_q, rtol=tol, atol=tol)
assert_allclose(dpnp_r, np_r, rtol=tol, atol=tol)
assert_dtype_allclose(dpnp_q, np_q)
assert_dtype_allclose(dpnp_r, np_r)

expected_queue = dpnp_data.get_array().sycl_queue
dpnp_q_queue = dpnp_q.get_array().sycl_queue
Expand All @@ -942,10 +943,13 @@ def test_qr(device):
ids=[device.filter_string for device in valid_devices],
)
def test_svd(device):
tol = 1e-12
shape = (2, 2)
numpy_data = numpy.arange(shape[0] * shape[1]).reshape(shape)
dpnp_data = dpnp.arange(shape[0] * shape[1], device=device).reshape(shape)
dtype = dpnp.default_float_type(device)
numpy_data = numpy.arange(shape[0] * shape[1], dtype=dtype).reshape(shape)
dpnp_data = dpnp.arange(
shape[0] * shape[1], dtype=dtype, device=device
).reshape(shape)

np_u, np_s, np_vt = numpy.linalg.svd(numpy_data)
dpnp_u, dpnp_s, dpnp_vt = dpnp.linalg.svd(dpnp_data)

Expand All @@ -962,11 +966,8 @@ def test_svd(device):
dpnp_diag_s[i, i] = dpnp_s[i]

# check decomposition
assert_allclose(
dpnp_data,
dpnp.dot(dpnp_u, dpnp.dot(dpnp_diag_s, dpnp_vt)),
rtol=tol,
atol=tol,
assert_dtype_allclose(
dpnp_data, dpnp.dot(dpnp_u, dpnp.dot(dpnp_diag_s, dpnp_vt))
)

for i in range(min(shape[0], shape[1])):
Expand All @@ -975,13 +976,9 @@ def test_svd(device):
np_vt[i, :] = -np_vt[i, :]

# compare vectors for non-zero values
for i in range(numpy.count_nonzero(np_s > tol)):
assert_allclose(
dpnp.asnumpy(dpnp_u)[:, i], np_u[:, i], rtol=tol, atol=tol
)
assert_allclose(
dpnp.asnumpy(dpnp_vt)[i, :], np_vt[i, :], rtol=tol, atol=tol
)
for i in range(numpy.count_nonzero(np_s)):
assert_dtype_allclose(dpnp_u[:, i], np_u[:, i])
assert_dtype_allclose(dpnp_vt[i, :], np_vt[i, :])

expected_queue = dpnp_data.get_array().sycl_queue
dpnp_u_queue = dpnp_u.get_array().sycl_queue
Expand All @@ -1007,7 +1004,7 @@ def test_svd(device):
def test_to_device(device_from, device_to):
data = [1.0, 1.0, 1.0, 1.0, 1.0]

x = dpnp.array(data, device=device_from)
x = dpnp.array(data, dtype=dpnp.float32, device=device_from)
y = x.to_device(device_to)

assert y.get_array().sycl_device == device_to
Expand Down
37 changes: 20 additions & 17 deletions tests/third_party/cupy/creation_tests/test_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

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


Expand Down Expand Up @@ -60,7 +61,7 @@ def test_arange9(self):
def test_arange_no_dtype_int(self, xp):
return xp.arange(1, 11, 2)

@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_arange_no_dtype_float(self, xp):
return xp.arange(1.0, 11.0, 2.0)

Expand Down Expand Up @@ -120,11 +121,11 @@ def test_linspace_with_retstep(self, xp, dtype):
self.assertEqual(step, 2.5)
return x

@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_linspace_no_dtype_int(self, xp):
return xp.linspace(0, 10, 50)

@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_linspace_no_dtype_float(self, xp):
return xp.linspace(0.0, 10.0, 50)

Expand All @@ -139,21 +140,23 @@ def test_linspace_neg_num(self):

@testing.numpy_cupy_allclose()
def test_linspace_float_overflow(self, xp):
return xp.linspace(0.0, sys.float_info.max / 5, 10, dtype=float)
dtype = cupy.default_float_type()
return xp.linspace(0.0, numpy.finfo(dtype).max / 5, 10, dtype=dtype)

@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose()
def test_linspace_float_underflow(self, xp):
# find minimum subnormal number
x = sys.float_info.min
dtype = cupy.default_float_type()
x = numpy.finfo(dtype).min
while x / 2 > 0:
x /= 2
return xp.linspace(0.0, x, 10, dtype=float)
return xp.linspace(0.0, x, 10, dtype=dtype)

@testing.with_requires("numpy>=1.16")
@testing.for_all_dtypes_combination(
names=("dtype_range", "dtype_out"), no_bool=True, no_complex=True
)
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-04)
def test_linspace_array_start_stop(self, xp, dtype_range, dtype_out):
start = xp.array([0, 120], dtype=dtype_range)
stop = xp.array([100, 0], dtype=dtype_range)
Expand All @@ -163,7 +166,7 @@ def test_linspace_array_start_stop(self, xp, dtype_range, dtype_out):
@testing.for_all_dtypes_combination(
names=("dtype_range", "dtype_out"), no_bool=True, no_complex=True
)
@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose(rtol=1e-04)
def test_linspace_mixed_start_stop(self, xp, dtype_range, dtype_out):
start = 0.0
if xp.dtype(dtype_range).kind in "u":
Expand All @@ -176,7 +179,7 @@ def test_linspace_mixed_start_stop(self, xp, dtype_range, dtype_out):
@testing.for_all_dtypes_combination(
names=("dtype_range", "dtype_out"), no_bool=True, no_complex=True
)
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-04)
def test_linspace_mixed_start_stop2(self, xp, dtype_range, dtype_out):
if xp.dtype(dtype_range).kind in "u":
start = xp.array([160, 120], dtype=dtype_range)
Expand Down Expand Up @@ -205,7 +208,7 @@ def test_linspace_complex_start_stop(self, xp, dtype):

@testing.with_requires("numpy>=1.16")
@testing.for_all_dtypes(no_bool=True)
@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose(rtol=1e-04)
def test_linspace_start_stop_list(self, xp, dtype):
start = [0, 0]
stop = [100, 16]
Expand Down Expand Up @@ -241,12 +244,12 @@ def test_logspace_no_endpoint(self, xp, dtype):
return xp.logspace(0, 2, 5, dtype=dtype, endpoint=False)

@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_logspace_no_dtype_int(self, xp):
return xp.logspace(0, 2)

@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_logspace_no_dtype_float(self, xp):
return xp.logspace(0.0, 2.0)

Expand All @@ -262,7 +265,7 @@ def test_logspace_neg_num(self):

@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@testing.for_all_dtypes(no_bool=True)
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(rtol=1e-04)
def test_logspace_base(self, xp, dtype):
return xp.logspace(0, 2, 5, base=2.0, dtype=dtype)

Expand Down Expand Up @@ -323,7 +326,7 @@ def test_mgrid0(self, xp):
def test_mgrid1(self, xp):
return xp.mgrid[-10:10]

@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_mgrid2(self, xp):
return xp.mgrid[-10:10:10j]

Expand All @@ -333,7 +336,7 @@ def test_mgrid3(self, xp):
y = xp.ones(10)[:, None]
return xp.mgrid[x:y:10j]

@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_mgrid4(self, xp):
# check len(keys) > 1
return xp.mgrid[-10:10:10j, -10:10:10j]
Expand All @@ -356,7 +359,7 @@ def test_ogrid0(self, xp):
def test_ogrid1(self, xp):
return xp.ogrid[-10:10]

@testing.numpy_cupy_array_equal()
@testing.numpy_cupy_allclose(rtol=1e-4, type_check=has_support_aspect64())
def test_ogrid2(self, xp):
return xp.ogrid[-10:10:10j]

Expand Down
4 changes: 4 additions & 0 deletions tests/third_party/cupy/fft_tests/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TestFft2(unittest.TestCase):
atol=1e-7,
accept_error=ValueError,
type_check=has_support_aspect64(),
contiguous_check=False,
)
def test_fft2(self, xp, dtype):
a = testing.shaped_random(self.shape, xp, dtype)
Expand All @@ -98,6 +99,7 @@ def test_fft2(self, xp, dtype):
atol=1e-7,
accept_error=ValueError,
type_check=has_support_aspect64(),
contiguous_check=False,
)
def test_ifft2(self, xp, dtype):
a = testing.shaped_random(self.shape, xp, dtype)
Expand Down Expand Up @@ -141,6 +143,7 @@ class TestFftn(unittest.TestCase):
atol=1e-7,
accept_error=ValueError,
type_check=has_support_aspect64(),
contiguous_check=False,
)
def test_fftn(self, xp, dtype):
a = testing.shaped_random(self.shape, xp, dtype)
Expand All @@ -154,6 +157,7 @@ def test_fftn(self, xp, dtype):
atol=1e-7,
accept_error=ValueError,
type_check=has_support_aspect64(),
contiguous_check=False,
)
def test_ifftn(self, xp, dtype):
a = testing.shaped_random(self.shape, xp, dtype)
Expand Down
10 changes: 8 additions & 2 deletions tests/third_party/cupy/linalg_tests/test_eigenvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

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


Expand All @@ -29,7 +30,12 @@ def _wrap_as_numpy_array(xp, a):
)
class TestEigenvalue(unittest.TestCase):
@testing.for_all_dtypes()
@testing.numpy_cupy_allclose(rtol=1e-3, atol=1e-4, contiguous_check=False)
@testing.numpy_cupy_allclose(
rtol=1e-3,
atol=1e-4,
type_check=has_support_aspect64(),
contiguous_check=False,
)
def test_eigh(self, xp, dtype):
if xp == numpy and dtype == numpy.float16:
# NumPy's eigh does not support float16
Expand Down Expand Up @@ -186,7 +192,7 @@ def test_eigvalsh_complex_batched(self, xp, dtype):
)
class TestEigenvalueEmpty(unittest.TestCase):
@testing.for_dtypes("ifdFD")
@testing.numpy_cupy_allclose()
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
def test_eigh(self, xp, dtype):
a = xp.empty(self.shape, dtype=dtype)
assert a.size == 0
Expand Down
5 changes: 4 additions & 1 deletion tests/third_party/cupy/linalg_tests/test_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

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


Expand Down Expand Up @@ -310,7 +311,9 @@ def setUp(self):
self.operands = operands

@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@testing.numpy_cupy_allclose(contiguous_check=False)
@testing.numpy_cupy_allclose(
type_check=has_support_aspect64(), contiguous_check=False
)
def test_einsum(self, xp):
# TODO(kataoka): support memory efficient cupy.einsum
with warnings.catch_warnings(record=True) as ws:
Expand Down
5 changes: 4 additions & 1 deletion tests/third_party/cupy/linalg_tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

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


Expand Down Expand Up @@ -101,7 +102,9 @@ def test_dot_with_out(self, xp, dtype_a, dtype_b, dtype_c):
class TestCrossProduct(unittest.TestCase):
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"])
# TODO: remove 'contiguous_check=False' once fixed in dpnp.cross()
@testing.numpy_cupy_allclose(contiguous_check=False)
@testing.numpy_cupy_allclose(
type_check=has_support_aspect64(), contiguous_check=False
)
def test_cross(self, xp, dtype_a, dtype_b):
if dtype_a == dtype_b == numpy.bool_:
# cross does not support bool-bool inputs.
Expand Down
4 changes: 2 additions & 2 deletions tests/third_party/cupy/sorting_tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ def test_invalid_sorter(self):

def test_nonint_sorter(self):
for xp in (numpy, cupy):
x = testing.shaped_arange((12,), xp, xp.float64)
x = testing.shaped_arange((12,), xp, xp.float32)
bins = xp.array([10, 4, 2, 1, 8])
sorter = xp.array([], dtype=xp.float64)
sorter = xp.array([], dtype=xp.float32)
with pytest.raises(TypeError):
xp.searchsorted(bins, x, sorter=sorter)
Loading

0 comments on commit b5764e2

Please sign in to comment.