Skip to content

Commit c4aaeb7

Browse files
Merge master into impl_common_type
2 parents 91c0933 + 771f9b2 commit c4aaeb7

File tree

12 files changed

+307
-464
lines changed

12 files changed

+307
-464
lines changed

dpnp/backend/extensions/blas/blas_py.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ PYBIND11_MODULE(_blas_impl, m)
6262
using event_vecT = std::vector<sycl::event>;
6363

6464
{
65-
dot_ns::init_dot_dispatch_vector<dot_impl_fn_ptr_t,
66-
blas_ns::DotContigFactory>(
65+
dot_ns::init_dot_dispatch_vector<blas_ns::DotContigFactory>(
6766
dot_dispatch_vector);
6867

6968
auto dot_pyapi = [&](sycl::queue &exec_q, const arrayT &src1,
@@ -81,8 +80,7 @@ PYBIND11_MODULE(_blas_impl, m)
8180
}
8281

8382
{
84-
dot_ns::init_dot_dispatch_vector<dot_impl_fn_ptr_t,
85-
blas_ns::DotcContigFactory>(
83+
dot_ns::init_dot_dispatch_vector<blas_ns::DotcContigFactory>(
8684
dotc_dispatch_vector);
8785

8886
auto dotc_pyapi = [&](sycl::queue &exec_q, const arrayT &src1,
@@ -101,8 +99,7 @@ PYBIND11_MODULE(_blas_impl, m)
10199
}
102100

103101
{
104-
dot_ns::init_dot_dispatch_vector<dot_impl_fn_ptr_t,
105-
blas_ns::DotuContigFactory>(
102+
dot_ns::init_dot_dispatch_vector<blas_ns::DotuContigFactory>(
106103
dotu_dispatch_vector);
107104

108105
auto dotu_pyapi = [&](sycl::queue &exec_q, const arrayT &src1,

dpnp/backend/extensions/blas/dot_common.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ typedef sycl::event (*dot_impl_fn_ptr_t)(sycl::queue &,
5050
namespace dpctl_td_ns = dpctl::tensor::type_dispatch;
5151
namespace py = pybind11;
5252

53-
template <typename dispatchT>
5453
std::pair<sycl::event, sycl::event>
5554
dot_func(sycl::queue &exec_q,
5655
const dpctl::tensor::usm_ndarray &vectorX,
5756
const dpctl::tensor::usm_ndarray &vectorY,
5857
const dpctl::tensor::usm_ndarray &result,
5958
const std::vector<sycl::event> &depends,
60-
const dispatchT &dot_dispatch_vector)
59+
const dot_impl_fn_ptr_t *dot_dispatch_vector)
6160
{
6261
const int vectorX_nd = vectorX.get_ndim();
6362
const int vectorY_nd = vectorY.get_ndim();
@@ -166,12 +165,10 @@ std::pair<sycl::event, sycl::event>
166165
return std::make_pair(args_ev, dot_ev);
167166
}
168167

169-
template <typename dispatchT,
170-
template <typename fnT, typename T>
171-
typename factoryT>
172-
void init_dot_dispatch_vector(dispatchT dot_dispatch_vector[])
168+
template <template <typename fnT, typename T> typename factoryT>
169+
void init_dot_dispatch_vector(dot_impl_fn_ptr_t dot_dispatch_vector[])
173170
{
174-
dpctl_td_ns::DispatchVectorBuilder<dispatchT, factoryT,
171+
dpctl_td_ns::DispatchVectorBuilder<dot_impl_fn_ptr_t, factoryT,
175172
dpctl_td_ns::num_types>
176173
contig;
177174
contig.populate_dispatch_vector(dot_dispatch_vector);

dpnp/backend/extensions/window/common.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@ sycl::event window_impl(sycl::queue &q,
6767
return window_ev;
6868
}
6969

70-
template <typename dispatchT>
7170
std::pair<sycl::event, sycl::event>
7271
py_window(sycl::queue &exec_q,
7372
const dpctl::tensor::usm_ndarray &result,
7473
const std::vector<sycl::event> &depends,
75-
const dispatchT &window_dispatch_vector)
74+
const window_fn_ptr_t *window_dispatch_vector)
7675
{
7776
dpctl::tensor::validation::CheckWritable::throw_if_not_writable(result);
7877

dpnp/tests/helper.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ def is_cuda_device(device=None):
346346
return dev.backend == dpctl.backend_type.cuda
347347

348348

349+
def is_gpu_device(device=None):
350+
"""
351+
Return True if a test is running on GPU device, False otherwise.
352+
"""
353+
dev = dpctl.select_default_device() if device is None else device
354+
return dev.has_aspect_gpu
355+
356+
349357
def is_win_platform():
350358
"""
351359
Return True if a test is running on Windows OS, False otherwise.

dpnp/tests/skipped_tests.tbl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,3 @@ tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.
1010
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
1111

1212
tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory
13-
14-
tests/test_umath.py::test_umaths[('divmod', 'ii')]
15-
tests/test_umath.py::test_umaths[('divmod', 'll')]
16-
tests/test_umath.py::test_umaths[('divmod', 'ff')]
17-
tests/test_umath.py::test_umaths[('divmod', 'dd')]
18-
tests/test_umath.py::test_umaths[('frexp', 'f')]
19-
tests/test_umath.py::test_umaths[('frexp', 'd')]

dpnp/tests/skipped_tests_cuda.tbl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
tests/test_arithmetic.py::TestArithmetic::test_modf_part1
55
tests/test_arithmetic.py::TestArithmetic::test_modf_part2
66
tests/test_sycl_queue.py::test_modf[cuda:gpu:0]
7-
tests/test_umath.py::test_umaths[('modf', 'f')]
8-
tests/test_umath.py::test_umaths[('modf', 'd')]
97
tests/third_party/cupy/math_tests/test_arithmetic.py::TestArithmeticModf::test_modf
108

119
# random

dpnp/tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,4 @@ tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: (dpnp
1717
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray([(i, i) for i in x], [("a", object), ("b", dpnp.int32)])]]
1818
tests/test_random.py::TestPermutationsTestShuffle::test_shuffle1[lambda x: dpnp.asarray(x).astype(dpnp.int8)]
1919

20-
tests/test_umath.py::test_umaths[('divmod', 'ii')]
21-
tests/test_umath.py::test_umaths[('divmod', 'll')]
22-
tests/test_umath.py::test_umaths[('divmod', 'ff')]
23-
tests/test_umath.py::test_umaths[('divmod', 'dd')]
24-
tests/test_umath.py::test_umaths[('floor_divide', 'ff')]
25-
tests/test_umath.py::test_umaths[('frexp', 'f')]
26-
tests/test_umath.py::test_umaths[('frexp', 'd')]
27-
2820
tests/third_party/intel/test_zero_copy_test1.py::test_dpnp_interaction_with_dpctl_memory

dpnp/tests/skipped_tests_gpu_no_fp64.tbl

Lines changed: 0 additions & 1 deletion
This file was deleted.

dpnp/tests/test_binary_ufuncs.py

Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from .helper import (
1515
assert_dtype_allclose,
16+
generate_random_numpy_array,
1617
get_abs_array,
1718
get_all_dtypes,
1819
get_complex_dtypes,
@@ -22,10 +23,6 @@
2223
has_support_aspect16,
2324
numpy_version,
2425
)
25-
from .test_umath import (
26-
_get_numpy_arrays_2in_1out,
27-
_get_output_data_type,
28-
)
2926

3027
"""
3128
The scope includes tests with only functions which are instances of
@@ -39,7 +36,9 @@ class TestAdd:
3936

4037
@pytest.mark.parametrize("dtype", ALL_DTYPES)
4138
def test_add(self, dtype):
42-
a, b, expected = _get_numpy_arrays_2in_1out("add", dtype, [-5, 5, 10])
39+
a = generate_random_numpy_array(10, dtype)
40+
b = generate_random_numpy_array(10, dtype)
41+
expected = numpy.add(a, b)
4342

4443
ia, ib = dpnp.array(a), dpnp.array(b)
4544
iout = dpnp.empty(expected.shape, dtype=dtype)
@@ -139,91 +138,63 @@ def test_invalid_out(self, xp, out):
139138
assert_raises(TypeError, xp.add, a, 2, out)
140139

141140

141+
@pytest.mark.parametrize("func", ["fmax", "fmin", "maximum", "minimum"])
142142
class TestBoundFuncs:
143-
@pytest.fixture(
144-
params=[
145-
{"func_name": "fmax", "input_values": [-5, 5, 10]},
146-
{"func_name": "fmin", "input_values": [-5, 5, 10]},
147-
{"func_name": "maximum", "input_values": [-5, 5, 10]},
148-
{"func_name": "minimum", "input_values": [-5, 5, 10]},
149-
],
150-
ids=[
151-
"fmax",
152-
"fmin",
153-
"maximum",
154-
"minimum",
155-
],
156-
)
157-
def func_params(self, request):
158-
return request.param
159-
160-
@pytest.mark.parametrize(
161-
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
162-
)
163-
def test_out(self, func_params, dtype):
164-
func_name = func_params["func_name"]
165-
input_values = func_params["input_values"]
166-
a, b, expected = _get_numpy_arrays_2in_1out(
167-
func_name, dtype, input_values
168-
)
143+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
144+
def test_out(self, func, dtype):
145+
a = generate_random_numpy_array(10, dtype)
146+
b = generate_random_numpy_array(10, dtype)
147+
expected = getattr(numpy, func)(a, b)
169148

170149
ia, ib = dpnp.array(a), dpnp.array(b)
171150
iout = dpnp.empty(expected.shape, dtype=dtype)
172-
result = getattr(dpnp, func_name)(ia, ib, out=iout)
151+
result = getattr(dpnp, func)(ia, ib, out=iout)
173152

174153
assert result is iout
175154
assert_dtype_allclose(result, expected)
176155

177156
@pytest.mark.parametrize(
178-
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
157+
"dtype", get_all_dtypes(no_none=True, no_bool=True)
179158
)
180-
def test_out_overlap(self, func_params, dtype):
181-
func_name = func_params["func_name"]
159+
def test_out_overlap(self, func, dtype):
182160
size = 15
183161
a = numpy.arange(2 * size, dtype=dtype)
184162
ia = dpnp.array(a)
185163

186-
getattr(dpnp, func_name)(ia[size::], ia[::2], out=ia[:size:])
187-
getattr(numpy, func_name)(a[size::], a[::2], out=a[:size:])
164+
getattr(dpnp, func)(ia[size::], ia[::2], out=ia[:size:])
165+
getattr(numpy, func)(a[size::], a[::2], out=a[:size:])
188166

189167
assert_dtype_allclose(ia, a)
190168

191169
@pytest.mark.parametrize("shape", [(0,), (15,), (2, 2)])
192-
def test_invalid_shape(self, func_params, shape):
193-
func_name = func_params["func_name"]
170+
def test_invalid_shape(self, func, shape):
194171
a, b = dpnp.arange(10), dpnp.arange(10)
195172
out = dpnp.empty(shape)
196173

197174
with pytest.raises(ValueError):
198-
getattr(dpnp, func_name)(a, b, out=out)
175+
getattr(dpnp, func)(a, b, out=out)
199176

200177
@pytest.mark.parametrize("xp", [dpnp, numpy])
201178
@pytest.mark.parametrize(
202179
"out",
203180
[4, (), [], (3, 7), [2, 4]],
204181
ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"],
205182
)
206-
def test_invalid_out(self, func_params, xp, out):
207-
func_name = func_params["func_name"]
183+
def test_invalid_out(self, func, xp, out):
208184
a = xp.arange(10)
209-
assert_raises(TypeError, getattr(xp, func_name), a, 2, out)
185+
assert_raises(TypeError, getattr(xp, func), a, 2, out)
210186

211187

212188
class TestDivide:
213189
@pytest.mark.usefixtures("suppress_divide_invalid_numpy_warnings")
214-
@pytest.mark.parametrize(
215-
"dtype", get_all_dtypes(no_none=True, no_bool=True)
216-
)
190+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
217191
def test_divide(self, dtype):
218-
a, b, expected = _get_numpy_arrays_2in_1out(
219-
"divide", dtype, [-5, 5, 10]
220-
)
192+
a = generate_random_numpy_array(10, dtype)
193+
b = generate_random_numpy_array(10, dtype)
194+
expected = numpy.divide(a, b)
221195

222196
ia, ib = dpnp.array(a), dpnp.array(b)
223-
if numpy.issubdtype(dtype, numpy.integer):
224-
out_dtype = map_dtype_to_device(dpnp.float64, ia.sycl_device)
225-
else:
226-
out_dtype = _get_output_data_type(dtype)
197+
out_dtype = map_dtype_to_device(expected.dtype, ia.sycl_device)
227198
iout = dpnp.empty(expected.shape, dtype=out_dtype)
228199
result = dpnp.divide(ia, ib, out=iout)
229200

@@ -318,7 +289,9 @@ def do_inplace_op(self, base, other, func):
318289
@pytest.mark.usefixtures("suppress_divide_numpy_warnings")
319290
@pytest.mark.parametrize("dtype", ALL_DTYPES)
320291
def test_basic(self, func, dtype):
321-
a, b, expected = _get_numpy_arrays_2in_1out(func, dtype, [-5, 5, 10])
292+
a = generate_random_numpy_array(10, dtype)
293+
b = generate_random_numpy_array(10, dtype)
294+
expected = getattr(numpy, func)(a, b)
322295

323296
ia, ib = dpnp.array(a), dpnp.array(b)
324297
iout = dpnp.empty(expected.shape, dtype=dtype)
@@ -398,9 +371,9 @@ def test_invalid_out(self, func, xp, out):
398371
assert_raises(TypeError, getattr(xp, func), a, 2, out)
399372

400373

374+
@pytest.mark.parametrize("func", ["fmax", "fmin"])
401375
class TestFmaxFmin:
402376
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
403-
@pytest.mark.parametrize("func", ["fmax", "fmin"])
404377
def test_half(self, func):
405378
a = numpy.array([0, 1, 2, 4, 2], dtype=numpy.float16)
406379
b = numpy.array([-2, 5, 1, 4, 3], dtype=numpy.float16)
@@ -415,7 +388,6 @@ def test_half(self, func):
415388
expected = getattr(numpy, func)(b, c)
416389
assert_equal(result, expected)
417390

418-
@pytest.mark.parametrize("func", ["fmax", "fmin"])
419391
@pytest.mark.parametrize("dtype", get_float_dtypes())
420392
def test_float_nans(self, func, dtype):
421393
a = numpy.array([0, numpy.nan, numpy.nan], dtype=dtype)
@@ -426,7 +398,6 @@ def test_float_nans(self, func, dtype):
426398
expected = getattr(numpy, func)(a, b)
427399
assert_equal(result, expected)
428400

429-
@pytest.mark.parametrize("func", ["fmax", "fmin"])
430401
@pytest.mark.parametrize("dtype", get_complex_dtypes())
431402
@pytest.mark.parametrize(
432403
"nan_val",
@@ -446,7 +417,6 @@ def test_complex_nans(self, func, dtype, nan_val):
446417
expected = getattr(numpy, func)(a, b)
447418
assert_equal(result, expected)
448419

449-
@pytest.mark.parametrize("func", ["fmax", "fmin"])
450420
@pytest.mark.parametrize("dtype", get_float_dtypes(no_float16=False))
451421
def test_precision(self, func, dtype):
452422
dtmin = numpy.finfo(dtype).min
@@ -602,9 +572,9 @@ class TestMultiply:
602572

603573
@pytest.mark.parametrize("dtype", ALL_DTYPES)
604574
def test_multiply(self, dtype):
605-
a, b, expected = _get_numpy_arrays_2in_1out(
606-
"multiply", dtype, [0, 10, 10]
607-
)
575+
a = generate_random_numpy_array(10, dtype)
576+
b = generate_random_numpy_array(10, dtype)
577+
expected = numpy.multiply(a, b)
608578

609579
ia, ib = dpnp.array(a), dpnp.array(b)
610580
iout = dpnp.empty(expected.shape, dtype=dtype)
@@ -853,8 +823,9 @@ def test_basic(self, array, val, data_type, val_type):
853823

854824
@pytest.mark.parametrize("dtype", ALL_DTYPES)
855825
def test_power(self, dtype):
856-
numpy.random.seed(42)
857-
a, b, expected = _get_numpy_arrays_2in_1out("power", dtype, [0, 10, 10])
826+
a = generate_random_numpy_array(10, dtype, low=0)
827+
b = generate_random_numpy_array(10, dtype, low=0)
828+
expected = numpy.power(a, b)
858829

859830
ia, ib = dpnp.array(a), dpnp.array(b)
860831
out_dtype = numpy.int8 if dtype == numpy.bool_ else dtype
@@ -1075,9 +1046,9 @@ class TestSubtract:
10751046

10761047
@pytest.mark.parametrize("dtype", ALL_DTYPES)
10771048
def test_add(self, dtype):
1078-
a, b, expected = _get_numpy_arrays_2in_1out(
1079-
"subtract", dtype, [-5, 5, 10]
1080-
)
1049+
a = generate_random_numpy_array(10, dtype)
1050+
b = generate_random_numpy_array(10, dtype)
1051+
expected = numpy.subtract(a, b)
10811052

10821053
ia, ib = dpnp.array(a), dpnp.array(b)
10831054
iout = dpnp.empty(expected.shape, dtype=dtype)

0 commit comments

Comments
 (0)