Skip to content

Commit 5aaf492

Browse files
authored
Merge pull request #1150 from IntelPython/main
Merge main into GOLD
2 parents 4990ffa + 8d0457b commit 5aaf492

28 files changed

+335
-162
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [0.21.3] - 2023-09-21
7+
## [0.21.3] - 2023-09-28
88

99
### Fixed
10+
* Pin CI conda channels (#1133)
1011
* Mangled kernel name generation (#1112)
1112

1213
### Added
14+
* Support tests on single point precision GPUs (#1143)
15+
* Initial work on Coverity scan CI (#1128)
1316
* Python 3.11 support (#1123)
1417
* Security policy (#1117)
15-
* scikit-build to build native extensions (#1107, #1127)
18+
* scikit-build to build native extensions (#1107, #1116, #1127, #1139, #1140)
1619

1720
### Changed
21+
* Rename helper function to clearly indicate its usage (#1145)
1822
* The data model used by the DpnpNdArray type for kernel functions(#1118)
1923

2024
### Removed

numba_dpex/core/typing/typeof.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dpctl import SyclQueue
66
from dpctl.tensor import usm_ndarray
77
from dpnp import ndarray
8-
from numba.core import types
98
from numba.extending import typeof_impl
109
from numba.np import numpy_support
1110

@@ -16,7 +15,7 @@
1615
from ..types.usm_ndarray_type import USMNdArray
1716

1817

19-
def _typeof_helper(val, array_class_type):
18+
def _array_typeof_helper(val, array_class_type):
2019
"""Creates a Numba type of the specified ``array_class_type`` for ``val``."""
2120
try:
2221
dtype = numpy_support.from_dtype(val.dtype)
@@ -74,7 +73,7 @@ def typeof_usm_ndarray(val, c):
7473
7574
Returns: The Numba type corresponding to dpctl.tensor.usm_ndarray
7675
"""
77-
return _typeof_helper(val, USMNdArray)
76+
return _array_typeof_helper(val, USMNdArray)
7877

7978

8079
@typeof_impl.register(ndarray)
@@ -92,7 +91,7 @@ def typeof_dpnp_ndarray(val, c):
9291
9392
Returns: The Numba type corresponding to dpnp.ndarray
9493
"""
95-
return _typeof_helper(val, DpnpNdArray)
94+
return _array_typeof_helper(val, DpnpNdArray)
9695

9796

9897
@typeof_impl.register(SyclQueue)

numba_dpex/tests/_helper.py

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

1010
import dpctl
11+
import dpnp
1112
import pytest
1213

1314
from numba_dpex import config, numba_sem_version
@@ -138,3 +139,116 @@ def override_config(name, value, config=config):
138139

139140
def _id(obj):
140141
return obj
142+
143+
144+
def get_complex_dtypes(device=None):
145+
"""
146+
Build a list of complex types supported by DPNP based on device capabilities.
147+
"""
148+
149+
dev = dpctl.select_default_device() if device is None else device
150+
151+
# add complex types
152+
dtypes = [dpnp.complex64]
153+
if dev.has_aspect_fp64:
154+
dtypes.append(dpnp.complex128)
155+
return dtypes
156+
157+
158+
def get_float_dtypes(no_float16=True, device=None):
159+
"""
160+
Build a list of floating types supported by DPNP based on device capabilities.
161+
"""
162+
163+
dev = dpctl.select_default_device() if device is None else device
164+
165+
# add floating types
166+
dtypes = []
167+
if not no_float16 and dev.has_aspect_fp16:
168+
dtypes.append(dpnp.float16)
169+
170+
dtypes.append(dpnp.float32)
171+
if dev.has_aspect_fp64:
172+
dtypes.append(dpnp.float64)
173+
return dtypes
174+
175+
176+
def get_float_complex_dtypes(no_float16=True, device=None):
177+
"""
178+
Build a list of floating and complex types supported by DPNP based on device capabilities.
179+
"""
180+
181+
dtypes = get_float_dtypes(no_float16, device)
182+
dtypes.extend(get_complex_dtypes(device))
183+
return dtypes
184+
185+
186+
def get_all_dtypes(
187+
no_bool=False,
188+
no_int=False,
189+
no_float16=True,
190+
no_float=False,
191+
no_complex=False,
192+
no_none=False,
193+
device=None,
194+
):
195+
"""
196+
Build a list of types supported by DPNP based on input flags and device capabilities.
197+
"""
198+
199+
dev = dpctl.select_default_device() if device is None else device
200+
201+
# add boolean type
202+
dtypes = [dpnp.bool] if not no_bool else []
203+
204+
# add integer types
205+
if not no_int:
206+
dtypes.extend([dpnp.int32, dpnp.int64])
207+
208+
# add floating types
209+
if not no_float:
210+
dtypes.extend(get_float_dtypes(no_float16=no_float16, device=dev))
211+
212+
# add complex types
213+
if not no_complex:
214+
dtypes.extend(get_complex_dtypes(device=dev))
215+
216+
# add None value to validate a default dtype
217+
if not no_none:
218+
dtypes.append(None)
219+
return dtypes
220+
221+
222+
def get_queue_or_skip(args=tuple()):
223+
try:
224+
q = dpctl.SyclQueue(*args)
225+
except dpctl.SyclQueueCreationError:
226+
pytest.skip(f"Queue could not be created from {args}")
227+
return q
228+
229+
230+
def skip_if_dtype_not_supported(dt, q_or_dev):
231+
import dpctl.tensor as dpt
232+
233+
dt = dpt.dtype(dt)
234+
if type(q_or_dev) is dpctl.SyclQueue:
235+
dev = q_or_dev.sycl_device
236+
elif type(q_or_dev) is dpctl.SyclDevice:
237+
dev = q_or_dev
238+
else:
239+
raise TypeError(
240+
"Expected dpctl.SyclQueue or dpctl.SyclDevice, "
241+
f"got {type(q_or_dev)}"
242+
)
243+
dev_has_dp = dev.has_aspect_fp64
244+
if dev_has_dp is False and dt in [dpt.float64, dpt.complex128]:
245+
pytest.skip(
246+
f"{dev.name} does not support double precision floating point types"
247+
)
248+
dev_has_hp = dev.has_aspect_fp16
249+
if dev_has_hp is False and dt in [
250+
dpt.float16,
251+
]:
252+
pytest.skip(
253+
f"{dev.name} does not support half precision floating point type"
254+
)

numba_dpex/tests/core/passes/test_parfor_legalize_cfd_pass.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414

1515
from numba_dpex import dpjit
1616
from numba_dpex.core.exceptions import ExecutionQueueInferenceError
17-
from numba_dpex.tests._helper import skip_no_opencl_cpu, skip_no_opencl_gpu
17+
from numba_dpex.tests._helper import (
18+
get_all_dtypes,
19+
skip_no_opencl_cpu,
20+
skip_no_opencl_gpu,
21+
)
1822

1923
shapes = [10, (2, 5)]
20-
dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64]
2124
usm_types = ["device"]
2225
devices = ["gpu"]
2326

@@ -30,7 +33,12 @@ def func1(a, b):
3033

3134
@skip_no_opencl_gpu
3235
@pytest.mark.parametrize("shape", shapes)
33-
@pytest.mark.parametrize("dtype", dtypes)
36+
@pytest.mark.parametrize(
37+
"dtype",
38+
get_all_dtypes(
39+
no_bool=True, no_float16=True, no_none=True, no_complex=True
40+
),
41+
)
3442
@pytest.mark.parametrize("usm_type", usm_types)
3543
@pytest.mark.parametrize("device", devices)
3644
def test_parfor_legalize_cfd_pass(shape, dtype, usm_type, device):

numba_dpex/tests/core/types/DpnpNdArray/test_boxing_unboxing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_boxing_unboxing():
2222
def func(a):
2323
return a
2424

25-
a = dpnp.empty(10)
25+
a = dpnp.empty(10, dtype=dpnp.float32)
2626
try:
2727
b = func(a)
2828
except:
@@ -40,8 +40,8 @@ def test_stride_calc_at_unboxing():
4040
def _tester(a):
4141
return a.strides
4242

43-
b = dpnp.empty((4, 16, 4))
43+
b = dpnp.empty((4, 16, 4), dtype=dpnp.float32)
4444
strides = dpjit(_tester)(b)
4545

4646
# Numba computes strides as bytes
47-
assert list(strides) == [512, 32, 8]
47+
assert list(strides) == [256, 16, 4]
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import dpctl
22
import pytest
33

4-
from numba_dpex.core.types import USMNdArray, dpctl_types
4+
from numba_dpex.core.types import USMNdArray, dpctl_types, float32
55

66

77
def test_usmndarray_negative_tests():
88
default_device = dpctl.SyclDevice().filter_string
99

10-
usmarr1 = USMNdArray(1, device=None, queue=None)
11-
assert usmarr1.dtype.name == "float64"
10+
usmarr1 = USMNdArray(1, device=None, queue=None, dtype=float32)
11+
assert usmarr1.dtype.name == "float32"
1212
assert usmarr1.ndim == 1
1313
assert usmarr1.layout == "C"
1414
assert usmarr1.addrspace == 1
1515
assert usmarr1.usm_type == "device"
1616

1717
assert usmarr1.queue.sycl_device == default_device
1818

19-
usmarr2 = USMNdArray(1, device=default_device, queue=None)
20-
assert usmarr2.dtype.name == "float64"
19+
usmarr2 = USMNdArray(1, device=default_device, queue=None, dtype=float32)
20+
assert usmarr2.dtype.name == "float32"
2121
assert usmarr2.ndim == 1
2222
assert usmarr2.layout == "C"
2323
assert usmarr2.addrspace == 1
@@ -26,18 +26,18 @@ def test_usmndarray_negative_tests():
2626

2727
queue = dpctl_types.DpctlSyclQueue(dpctl.SyclQueue())
2828

29-
usmarr3 = USMNdArray(1, device=None, queue=queue)
30-
assert usmarr3.dtype.name == "float64"
29+
usmarr3 = USMNdArray(1, device=None, queue=queue, dtype=float32)
30+
assert usmarr3.dtype.name == "float32"
3131
assert usmarr3.ndim == 1
3232
assert usmarr3.layout == "C"
3333
assert usmarr3.addrspace == 1
3434
assert usmarr3.usm_type == "device"
3535

3636
with pytest.raises(TypeError):
37-
USMNdArray(1, device=default_device, queue=queue)
37+
USMNdArray(1, device=default_device, queue=queue, dtype=float32)
3838

3939
with pytest.raises(TypeError):
40-
USMNdArray(1, queue=0)
40+
USMNdArray(1, queue=0, dtype=float32)
4141

4242
with pytest.raises(TypeError):
43-
USMNdArray(1, device=0)
43+
USMNdArray(1, device=0, dtype=float32)

numba_dpex/tests/core/types/USMNdArray/test_usm_ndarray_type.py

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

5+
import dpctl
56
import dpctl.tensor as dpt
67
import numpy as np
78
import pytest
89
from numba.misc.special import typeof
910

1011
from numba_dpex.core.types import USMNdArray
12+
from numba_dpex.tests._helper import (
13+
get_queue_or_skip,
14+
skip_if_dtype_not_supported,
15+
)
1116

1217
list_of_dtypes = [
1318
np.int32,
@@ -35,6 +40,9 @@ def usm_type(request):
3540

3641

3742
def test_usm_ndarray_type(dtype, usm_type):
43+
q = get_queue_or_skip()
44+
skip_if_dtype_not_supported(dtype, q)
45+
3846
a = np.array(np.random.random(10), dtype)
3947
da = dpt.usm_ndarray(a.shape, dtype=a.dtype, buffer=usm_type)
4048

numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from numba import errors
1111

1212
from numba_dpex import dpjit
13+
from numba_dpex.tests._helper import get_all_dtypes
1314

1415
shapes = [11, (2, 5)]
15-
dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64]
1616
usm_types = ["device", "shared", "host"]
1717

1818

@@ -51,7 +51,12 @@ def func(shape):
5151

5252

5353
@pytest.mark.parametrize("shape", shapes)
54-
@pytest.mark.parametrize("dtype", dtypes)
54+
@pytest.mark.parametrize(
55+
"dtype",
56+
get_all_dtypes(
57+
no_bool=True, no_float16=True, no_none=True, no_complex=True
58+
),
59+
)
5560
@pytest.mark.parametrize("usm_type", usm_types)
5661
def test_dpnp_empty_from_device(shape, dtype, usm_type):
5762
""" "Use device only in dpnp.emtpy() inside dpjit."""
@@ -84,7 +89,12 @@ def func(shape):
8489

8590

8691
@pytest.mark.parametrize("shape", shapes)
87-
@pytest.mark.parametrize("dtype", dtypes)
92+
@pytest.mark.parametrize(
93+
"dtype",
94+
get_all_dtypes(
95+
no_bool=True, no_float16=True, no_none=True, no_complex=True
96+
),
97+
)
8898
@pytest.mark.parametrize("usm_type", usm_types)
8999
def test_dpnp_empty_from_queue(shape, dtype, usm_type):
90100
""" "Use queue only in dpnp.emtpy() inside dpjit."""
@@ -121,7 +131,9 @@ def test_dpnp_empty_exceptions():
121131

122132
@dpjit
123133
def func(shape, queue):
124-
c = dpnp.empty(shape, sycl_queue=queue, device=device)
134+
c = dpnp.empty(
135+
shape, sycl_queue=queue, device=device, dtype=dpnp.float32
136+
)
125137
return c
126138

127139
with pytest.raises(errors.TypingError):

0 commit comments

Comments
 (0)