Skip to content

Commit 81dec55

Browse files
author
Diptorup Deb
committed
Updates to kernel tests.
1 parent c719d7f commit 81dec55

File tree

5 files changed

+48
-76
lines changed

5 files changed

+48
-76
lines changed

numba_dpex/tests/kernel_tests/test_func_qualname_disambiguation.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import dpctl
65
import dpctl.tensor as dpt
6+
import dpnp
77
import numpy as np
8-
import pytest
98

109
import numba_dpex as ndpx
11-
from numba_dpex.tests._helper import filter_strings
1210

1311

1412
def make_write_values_kernel(n_rows):
@@ -80,8 +78,7 @@ def write_values_inner(array_in, row_idx):
8078
return write_values_inner
8179

8280

83-
@pytest.mark.parametrize("offload_device", filter_strings)
84-
def test_qualname_basic(offload_device):
81+
def test_qualname_basic():
8582
"""A basic test function to test
8683
qualified name disambiguation.
8784
"""
@@ -92,32 +89,11 @@ def test_qualname_basic(offload_device):
9289
else:
9390
ans[i, 0] = 1
9491

95-
a = np.zeros((10, 10), dtype=dpt.int64)
96-
97-
device = dpctl.SyclDevice(offload_device)
98-
queue = dpctl.SyclQueue(device)
99-
100-
da = dpt.usm_ndarray(
101-
a.shape,
102-
dtype=a.dtype,
103-
buffer="device",
104-
buffer_ctor_kwargs={"queue": queue},
105-
)
106-
da.usm_data.copy_from_host(a.reshape((-1)).view("|u1"))
92+
a = dpnp.zeros((10, 10), dtype=dpt.int64)
10793

10894
kernel = make_write_values_kernel(10)
109-
kernel(da)
110-
111-
result = np.zeros_like(a)
112-
da.usm_data.copy_to_host(result.reshape((-1)).view("|u1"))
113-
114-
print(ans)
115-
print(result)
116-
117-
assert np.array_equal(result, ans)
95+
kernel(a)
11896

97+
result = dpnp.zeros_like(a)
11998

120-
if __name__ == "__main__":
121-
test_qualname_basic("level_zero:gpu:0")
122-
test_qualname_basic("opencl:gpu:0")
123-
test_qualname_basic("opencl:cpu:0")
99+
assert np.array_equal(dpnp.asnumpy(result), ans)

numba_dpex/tests/kernel_tests/test_func_specialization.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import dpctl.tensor as dpt
5+
import dpnp
66
import numpy as np
77
import pytest
88

@@ -32,12 +32,12 @@ def kernel_function(a, b):
3232

3333
k = dpex.kernel(kernel_function)
3434

35-
a = dpt.ones(N)
36-
b = dpt.ones(N)
35+
a = dpnp.ones(N)
36+
b = dpnp.ones(N)
3737

38-
k[N](a, b)
38+
k[dpex.Range(N)](a, b)
3939

40-
assert np.array_equal(dpt.asnumpy(b), dpt.asnumpy(a) + 1)
40+
assert np.array_equal(dpnp.asnumpy(b), dpnp.asnumpy(a) + 1)
4141

4242

4343
def test_single_signature():
@@ -53,19 +53,19 @@ def kernel_function(a, b):
5353
k = dpex.kernel(kernel_function)
5454

5555
# Test with int32, should work
56-
a = dpt.ones(N, dtype=dpt.int32)
57-
b = dpt.ones(N, dtype=dpt.int32)
56+
a = dpnp.ones(N, dtype=dpnp.int32)
57+
b = dpnp.ones(N, dtype=dpnp.int32)
5858

59-
k[N](a, b)
59+
k[dpex.Range(N)](a, b)
6060

61-
assert np.array_equal(dpt.asnumpy(b), dpt.asnumpy(a) + 1)
61+
assert np.array_equal(dpnp.asnumpy(b), dpnp.asnumpy(a) + 1)
6262

6363
# Test with int64, should fail
64-
a = dpt.ones(N, dtype=dpt.int64)
65-
b = dpt.ones(N, dtype=dpt.int64)
64+
a = dpnp.ones(N, dtype=dpnp.int64)
65+
b = dpnp.ones(N, dtype=dpnp.int64)
6666

6767
with pytest.raises(Exception) as e:
68-
k[N](a, b)
68+
k[dpex.Range(N)](a, b)
6969

7070
assert " >>> <unknown function>(int64)" in e.value.args[0]
7171

@@ -83,26 +83,26 @@ def kernel_function(a, b):
8383
k = dpex.kernel(kernel_function)
8484

8585
# Test with int32, should work
86-
a = dpt.ones(N, dtype=dpt.int32)
87-
b = dpt.ones(N, dtype=dpt.int32)
86+
a = dpnp.ones(N, dtype=dpnp.int32)
87+
b = dpnp.ones(N, dtype=dpnp.int32)
8888

89-
k[N](a, b)
89+
k[dpex.Range(N)](a, b)
9090

91-
assert np.array_equal(dpt.asnumpy(b), dpt.asnumpy(a) + 1)
91+
assert np.array_equal(dpnp.asnumpy(b), dpnp.asnumpy(a) + 1)
9292

9393
# Test with float32, should work
94-
a = dpt.ones(N, dtype=dpt.float32)
95-
b = dpt.ones(N, dtype=dpt.float32)
94+
a = dpnp.ones(N, dtype=dpnp.float32)
95+
b = dpnp.ones(N, dtype=dpnp.float32)
9696

97-
k[N](a, b)
97+
k[dpex.Range(N)](a, b)
9898

99-
assert np.array_equal(dpt.asnumpy(b), dpt.asnumpy(a) + 1)
99+
assert np.array_equal(dpnp.asnumpy(b), dpnp.asnumpy(a) + 1)
100100

101101
# Test with int64, should fail
102-
a = dpt.ones(N, dtype=dpt.int64)
103-
b = dpt.ones(N, dtype=dpt.int64)
102+
a = dpnp.ones(N, dtype=dpnp.int64)
103+
b = dpnp.ones(N, dtype=dpnp.int64)
104104

105105
with pytest.raises(Exception) as e:
106-
k[N](a, b)
106+
k[dpex.Range(N)](a, b)
107107

108108
assert " >>> <unknown function>(int64)" in e.value.args[0]

numba_dpex/tests/kernel_tests/test_kernel_has_return_value_error.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import dpctl.tensor as dpt
6-
import numpy as np
5+
import dpnp
76
import pytest
87

98
import numba_dpex as dpex
@@ -28,8 +27,8 @@ def sig(request):
2827

2928

3029
def test_return(sig):
31-
a = dpt.arange(1024, dtype=dpt.int32, device="0")
30+
a = dpnp.arange(1024, dtype=dpnp.int32)
3231

3332
with pytest.raises(dpex.core.exceptions.KernelHasReturnValueError):
34-
kernel = dpex.kernel(sig)(f)
35-
kernel[a.size, dpex.DEFAULT_LOCAL_SIZE](a)
33+
kernel_fn = dpex.kernel(sig)(f)
34+
kernel_fn[dpex.Range(a.size)](a)

numba_dpex/tests/kernel_tests/test_math_functions.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
import math
66

7-
import dpctl
8-
import numpy as np
7+
import dpnp
8+
import numpy
99
import pytest
1010

1111
import numba_dpex as dpex
12-
from numba_dpex.tests._helper import filter_strings
1312

1413
list_of_unary_ops = ["fabs", "exp", "log", "sqrt", "sin", "cos", "tan"]
1514

@@ -20,35 +19,35 @@ def unary_op(request):
2019

2120

2221
list_of_dtypes = [
23-
np.float32,
24-
np.float64,
22+
dpnp.float32,
23+
dpnp.float64,
2524
]
2625

2726

2827
@pytest.fixture(params=list_of_dtypes)
2928
def input_arrays(request):
3029
# The size of input and out arrays to be used
3130
N = 2048
32-
a = np.array(np.random.random(N), request.param)
33-
b = np.array(np.random.random(N), request.param)
31+
a = dpnp.arange(N, dtype=request.param)
32+
b = dpnp.arange(N, dtype=request.param)
3433
return a, b
3534

3635

37-
@pytest.mark.parametrize("filter_str", filter_strings)
38-
def test_binary_ops(filter_str, unary_op, input_arrays):
39-
a, actual = input_arrays
36+
def test_binary_ops(unary_op, input_arrays):
37+
a, b = input_arrays
4038
uop = getattr(math, unary_op)
41-
np_uop = getattr(np, unary_op)
39+
dpnp_uop = getattr(dpnp, unary_op)
4240

4341
@dpex.kernel
4442
def f(a, b):
4543
i = dpex.get_global_id(0)
4644
b[i] = uop(a[i])
4745

48-
device = dpctl.SyclDevice(filter_str)
49-
with dpctl.device_context(device):
50-
f[a.size, dpex.DEFAULT_LOCAL_SIZE](a, actual)
46+
f[dpex.Range(a.size)](a, b)
5147

52-
expected = np_uop(a)
48+
expected = dpnp_uop(a)
5349

54-
np.testing.assert_allclose(actual, expected, rtol=1e-5, atol=0)
50+
np_expected = dpnp.asnumpy(expected)
51+
np_actual = dpnp.asnumpy(b)
52+
53+
assert numpy.allclose(np_expected, np_actual)

numba_dpex/tests/kernel_tests/test_scalar_arg_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import dpctl
6-
import dpctl.tensor as dpt
75
import dpnp
86
import numpy
97
import pytest

0 commit comments

Comments
 (0)