From e463ed6135e221e580b248be5aa778ba9feffda0 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Sat, 23 Sep 2023 16:37:11 -0500 Subject: [PATCH 1/3] Rename helper function to clearly indicate its usage --- numba_dpex/core/typing/typeof.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/numba_dpex/core/typing/typeof.py b/numba_dpex/core/typing/typeof.py index f4cd6da6e3..862a350645 100644 --- a/numba_dpex/core/typing/typeof.py +++ b/numba_dpex/core/typing/typeof.py @@ -5,7 +5,6 @@ from dpctl import SyclQueue from dpctl.tensor import usm_ndarray from dpnp import ndarray -from numba.core import types from numba.extending import typeof_impl from numba.np import numpy_support @@ -16,7 +15,7 @@ from ..types.usm_ndarray_type import USMNdArray -def _typeof_helper(val, array_class_type): +def _array_typeof_helper(val, array_class_type): """Creates a Numba type of the specified ``array_class_type`` for ``val``.""" try: dtype = numpy_support.from_dtype(val.dtype) @@ -74,7 +73,7 @@ def typeof_usm_ndarray(val, c): Returns: The Numba type corresponding to dpctl.tensor.usm_ndarray """ - return _typeof_helper(val, USMNdArray) + return _array_typeof_helper(val, USMNdArray) @typeof_impl.register(ndarray) @@ -92,7 +91,7 @@ def typeof_dpnp_ndarray(val, c): Returns: The Numba type corresponding to dpnp.ndarray """ - return _typeof_helper(val, DpnpNdArray) + return _array_typeof_helper(val, DpnpNdArray) @typeof_impl.register(SyclQueue) From 08026332c3ac00f52cc6a4a7e067f360bd998ba0 Mon Sep 17 00:00:00 2001 From: Yevhenii Havrylko Date: Wed, 27 Sep 2023 10:29:19 -0400 Subject: [PATCH 2/3] Support tests on single point precision GPUs --- numba_dpex/tests/_helper.py | 114 ++++++++++++++++++ .../passes/test_parfor_legalize_cfd_pass.py | 14 ++- .../types/DpnpNdArray/test_boxing_unboxing.py | 6 +- .../USMNdArray/test_array_creation_errors.py | 20 +-- .../types/USMNdArray/test_usm_ndarray_type.py | 8 ++ .../tests/dpjit_tests/dpnp/test_dpnp_empty.py | 20 ++- .../dpjit_tests/dpnp/test_dpnp_empty_like.py | 20 ++- .../tests/dpjit_tests/dpnp/test_dpnp_full.py | 20 ++- .../dpjit_tests/dpnp/test_dpnp_full_like.py | 18 ++- .../tests/dpjit_tests/dpnp/test_dpnp_ones.py | 9 +- .../dpjit_tests/dpnp/test_dpnp_ones_like.py | 11 +- .../tests/dpjit_tests/dpnp/test_dpnp_zeros.py | 9 +- .../dpjit_tests/dpnp/test_dpnp_zeros_like.py | 11 +- .../dpjit_tests/parfors/test_builtin_ops.py | 10 +- .../parfors/test_dpnp_logic_ops.py | 10 +- .../test_dpnp_transcedental_functions.py | 9 +- .../test_dpnp_trigonometric_functions.py | 19 ++- .../test_dpjit_complex_arg_types.py | 12 +- .../tests/dpjit_tests/test_dpjit_reduction.py | 38 ++---- .../tests/kernel_tests/test_atomic_op.py | 34 +++--- .../tests/kernel_tests/test_complex_array.py | 10 +- .../tests/kernel_tests/test_math_functions.py | 8 +- .../kernel_tests/test_scalar_arg_types.py | 12 +- .../test_sycl_usm_array_iface_interop.py | 10 +- .../kernel_tests/test_usm_ndarray_interop.py | 18 +-- numba_dpex/tests/test_prange.py | 12 +- 26 files changed, 326 insertions(+), 156 deletions(-) diff --git a/numba_dpex/tests/_helper.py b/numba_dpex/tests/_helper.py index b87b562ee3..cb9a166f9b 100644 --- a/numba_dpex/tests/_helper.py +++ b/numba_dpex/tests/_helper.py @@ -8,6 +8,7 @@ import shutil import dpctl +import dpnp import pytest from numba_dpex import config, numba_sem_version @@ -138,3 +139,116 @@ def override_config(name, value, config=config): def _id(obj): return obj + + +def get_complex_dtypes(device=None): + """ + Build a list of complex types supported by DPNP based on device capabilities. + """ + + dev = dpctl.select_default_device() if device is None else device + + # add complex types + dtypes = [dpnp.complex64] + if dev.has_aspect_fp64: + dtypes.append(dpnp.complex128) + return dtypes + + +def get_float_dtypes(no_float16=True, device=None): + """ + Build a list of floating types supported by DPNP based on device capabilities. + """ + + dev = dpctl.select_default_device() if device is None else device + + # add floating types + dtypes = [] + if not no_float16 and dev.has_aspect_fp16: + dtypes.append(dpnp.float16) + + dtypes.append(dpnp.float32) + if dev.has_aspect_fp64: + dtypes.append(dpnp.float64) + return dtypes + + +def get_float_complex_dtypes(no_float16=True, device=None): + """ + Build a list of floating and complex types supported by DPNP based on device capabilities. + """ + + dtypes = get_float_dtypes(no_float16, device) + dtypes.extend(get_complex_dtypes(device)) + return dtypes + + +def get_all_dtypes( + no_bool=False, + no_int=False, + no_float16=True, + no_float=False, + no_complex=False, + no_none=False, + device=None, +): + """ + Build a list of types supported by DPNP based on input flags and device capabilities. + """ + + dev = dpctl.select_default_device() if device is None else device + + # add boolean type + dtypes = [dpnp.bool] if not no_bool else [] + + # add integer types + if not no_int: + dtypes.extend([dpnp.int32, dpnp.int64]) + + # add floating types + if not no_float: + dtypes.extend(get_float_dtypes(no_float16=no_float16, device=dev)) + + # add complex types + if not no_complex: + dtypes.extend(get_complex_dtypes(device=dev)) + + # add None value to validate a default dtype + if not no_none: + dtypes.append(None) + return dtypes + + +def get_queue_or_skip(args=tuple()): + try: + q = dpctl.SyclQueue(*args) + except dpctl.SyclQueueCreationError: + pytest.skip(f"Queue could not be created from {args}") + return q + + +def skip_if_dtype_not_supported(dt, q_or_dev): + import dpctl.tensor as dpt + + dt = dpt.dtype(dt) + if type(q_or_dev) is dpctl.SyclQueue: + dev = q_or_dev.sycl_device + elif type(q_or_dev) is dpctl.SyclDevice: + dev = q_or_dev + else: + raise TypeError( + "Expected dpctl.SyclQueue or dpctl.SyclDevice, " + f"got {type(q_or_dev)}" + ) + dev_has_dp = dev.has_aspect_fp64 + if dev_has_dp is False and dt in [dpt.float64, dpt.complex128]: + pytest.skip( + f"{dev.name} does not support double precision floating point types" + ) + dev_has_hp = dev.has_aspect_fp16 + if dev_has_hp is False and dt in [ + dpt.float16, + ]: + pytest.skip( + f"{dev.name} does not support half precision floating point type" + ) diff --git a/numba_dpex/tests/core/passes/test_parfor_legalize_cfd_pass.py b/numba_dpex/tests/core/passes/test_parfor_legalize_cfd_pass.py index 81ebfe32d6..fa1078b4d9 100644 --- a/numba_dpex/tests/core/passes/test_parfor_legalize_cfd_pass.py +++ b/numba_dpex/tests/core/passes/test_parfor_legalize_cfd_pass.py @@ -14,10 +14,13 @@ from numba_dpex import dpjit from numba_dpex.core.exceptions import ExecutionQueueInferenceError -from numba_dpex.tests._helper import skip_no_opencl_cpu, skip_no_opencl_gpu +from numba_dpex.tests._helper import ( + get_all_dtypes, + skip_no_opencl_cpu, + skip_no_opencl_gpu, +) shapes = [10, (2, 5)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] usm_types = ["device"] devices = ["gpu"] @@ -30,7 +33,12 @@ def func1(a, b): @skip_no_opencl_gpu @pytest.mark.parametrize("shape", shapes) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) @pytest.mark.parametrize("device", devices) def test_parfor_legalize_cfd_pass(shape, dtype, usm_type, device): diff --git a/numba_dpex/tests/core/types/DpnpNdArray/test_boxing_unboxing.py b/numba_dpex/tests/core/types/DpnpNdArray/test_boxing_unboxing.py index eb6c05fbd6..b7ca7f13e0 100644 --- a/numba_dpex/tests/core/types/DpnpNdArray/test_boxing_unboxing.py +++ b/numba_dpex/tests/core/types/DpnpNdArray/test_boxing_unboxing.py @@ -22,7 +22,7 @@ def test_boxing_unboxing(): def func(a): return a - a = dpnp.empty(10) + a = dpnp.empty(10, dtype=dpnp.float32) try: b = func(a) except: @@ -40,8 +40,8 @@ def test_stride_calc_at_unboxing(): def _tester(a): return a.strides - b = dpnp.empty((4, 16, 4)) + b = dpnp.empty((4, 16, 4), dtype=dpnp.float32) strides = dpjit(_tester)(b) # Numba computes strides as bytes - assert list(strides) == [512, 32, 8] + assert list(strides) == [256, 16, 4] diff --git a/numba_dpex/tests/core/types/USMNdArray/test_array_creation_errors.py b/numba_dpex/tests/core/types/USMNdArray/test_array_creation_errors.py index 7c0094cb02..343ad19906 100644 --- a/numba_dpex/tests/core/types/USMNdArray/test_array_creation_errors.py +++ b/numba_dpex/tests/core/types/USMNdArray/test_array_creation_errors.py @@ -1,14 +1,14 @@ import dpctl import pytest -from numba_dpex.core.types import USMNdArray, dpctl_types +from numba_dpex.core.types import USMNdArray, dpctl_types, float32 def test_usmndarray_negative_tests(): default_device = dpctl.SyclDevice().filter_string - usmarr1 = USMNdArray(1, device=None, queue=None) - assert usmarr1.dtype.name == "float64" + usmarr1 = USMNdArray(1, device=None, queue=None, dtype=float32) + assert usmarr1.dtype.name == "float32" assert usmarr1.ndim == 1 assert usmarr1.layout == "C" assert usmarr1.addrspace == 1 @@ -16,8 +16,8 @@ def test_usmndarray_negative_tests(): assert usmarr1.queue.sycl_device == default_device - usmarr2 = USMNdArray(1, device=default_device, queue=None) - assert usmarr2.dtype.name == "float64" + usmarr2 = USMNdArray(1, device=default_device, queue=None, dtype=float32) + assert usmarr2.dtype.name == "float32" assert usmarr2.ndim == 1 assert usmarr2.layout == "C" assert usmarr2.addrspace == 1 @@ -26,18 +26,18 @@ def test_usmndarray_negative_tests(): queue = dpctl_types.DpctlSyclQueue(dpctl.SyclQueue()) - usmarr3 = USMNdArray(1, device=None, queue=queue) - assert usmarr3.dtype.name == "float64" + usmarr3 = USMNdArray(1, device=None, queue=queue, dtype=float32) + assert usmarr3.dtype.name == "float32" assert usmarr3.ndim == 1 assert usmarr3.layout == "C" assert usmarr3.addrspace == 1 assert usmarr3.usm_type == "device" with pytest.raises(TypeError): - USMNdArray(1, device=default_device, queue=queue) + USMNdArray(1, device=default_device, queue=queue, dtype=float32) with pytest.raises(TypeError): - USMNdArray(1, queue=0) + USMNdArray(1, queue=0, dtype=float32) with pytest.raises(TypeError): - USMNdArray(1, device=0) + USMNdArray(1, device=0, dtype=float32) diff --git a/numba_dpex/tests/core/types/USMNdArray/test_usm_ndarray_type.py b/numba_dpex/tests/core/types/USMNdArray/test_usm_ndarray_type.py index 187f119161..c0c984317a 100644 --- a/numba_dpex/tests/core/types/USMNdArray/test_usm_ndarray_type.py +++ b/numba_dpex/tests/core/types/USMNdArray/test_usm_ndarray_type.py @@ -2,12 +2,17 @@ # # SPDX-License-Identifier: Apache-2.0 +import dpctl import dpctl.tensor as dpt import numpy as np import pytest from numba.misc.special import typeof from numba_dpex.core.types import USMNdArray +from numba_dpex.tests._helper import ( + get_queue_or_skip, + skip_if_dtype_not_supported, +) list_of_dtypes = [ np.int32, @@ -35,6 +40,9 @@ def usm_type(request): def test_usm_ndarray_type(dtype, usm_type): + q = get_queue_or_skip() + skip_if_dtype_not_supported(dtype, q) + a = np.array(np.random.random(10), dtype) da = dpt.usm_ndarray(a.shape, dtype=a.dtype, buffer=usm_type) diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty.py index 3bedc9e142..1a70aee498 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty.py @@ -10,9 +10,9 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (2, 5)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] usm_types = ["device", "shared", "host"] @@ -51,7 +51,12 @@ def func(shape): @pytest.mark.parametrize("shape", shapes) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_empty_from_device(shape, dtype, usm_type): """ "Use device only in dpnp.emtpy() inside dpjit.""" @@ -84,7 +89,12 @@ def func(shape): @pytest.mark.parametrize("shape", shapes) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_empty_from_queue(shape, dtype, usm_type): """ "Use queue only in dpnp.emtpy() inside dpjit.""" @@ -121,7 +131,9 @@ def test_dpnp_empty_exceptions(): @dpjit def func(shape, queue): - c = dpnp.empty(shape, sycl_queue=queue, device=device) + c = dpnp.empty( + shape, sycl_queue=queue, device=device, dtype=dpnp.float32 + ) return c with pytest.raises(errors.TypingError): diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty_like.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty_like.py index 7a1c0ec9d8..4d7e10547a 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty_like.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty_like.py @@ -12,9 +12,9 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [10, (2, 5)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] usm_types = ["device", "shared", "host"] @@ -53,7 +53,12 @@ def func(x): @pytest.mark.parametrize("shape", shapes) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_empty_like_from_device(shape, dtype, usm_type): """ "Use device only in dpnp.emtpy)like() inside dpjit.""" @@ -87,7 +92,12 @@ def func(x): @pytest.mark.parametrize("shape", shapes) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_empty_like_from_queue(shape, dtype, usm_type): """ "Use queue only in dpnp.emtpy_like() inside dpjit.""" @@ -146,7 +156,7 @@ def func1(x, queue): try: queue = dpctl.SyclQueue() - a = dpnp.ones(10) + a = dpnp.ones(10, dtype=dpnp.float32) func1(a, queue) except Exception as e: assert isinstance(e, errors.TypingError) @@ -175,7 +185,7 @@ def func(x): y = dpnp.empty_like(x) return y - a = numpy.empty(10) + a = numpy.empty(10, dtype=numpy.float32) with pytest.raises(Exception): func(a) diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full.py index f04b059e8f..298aeafbb0 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full.py @@ -14,9 +14,9 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (3, 7)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] usm_types = ["device", "shared", "host"] fill_values = [ 7, @@ -41,7 +41,7 @@ def test_dpnp_full_default(shape, fill_value): @dpjit def func(shape, fill_value): - c = dpnp.full(shape, fill_value) + c = dpnp.full(shape, fill_value, dtype=numpy.float32) return c try: @@ -54,7 +54,7 @@ def func(shape, fill_value): else: assert c.shape == shape - dummy = dpnp.full(shape, fill_value) + dummy = dpnp.full(shape, fill_value, dtype=dpnp.float32) if c.dtype != dummy.dtype: if sys.platform != "linux": @@ -80,7 +80,12 @@ def func(shape, fill_value): @pytest.mark.parametrize("shape", shapes) @pytest.mark.parametrize("fill_value", fill_values) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_full_from_device(shape, fill_value, dtype, usm_type): """ "Use device only in dpnp.full() inside dpjit.""" @@ -122,7 +127,12 @@ def func(shape, fill_value): @pytest.mark.parametrize("shape", shapes) @pytest.mark.parametrize("fill_value", fill_values) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_full_from_queue(shape, fill_value, dtype, usm_type): """ "Use queue only in dpnp.full() inside dpjit.""" diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full_like.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full_like.py index b36dc0d41b..fb998ebe57 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full_like.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_full_like.py @@ -15,9 +15,9 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (3, 7)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] usm_types = ["device", "shared", "host"] fill_values = [ 7, @@ -43,7 +43,7 @@ def func(x, fill_value): return y try: - a = dpnp.zeros(shape) + a = dpnp.zeros(shape, dtype=dpnp.float32) c = func(a, fill_value) except Exception: pytest.fail("Calling dpnp.full_like() inside dpjit failed.") @@ -78,7 +78,12 @@ def func(x, fill_value): @pytest.mark.parametrize("shape", shapes) @pytest.mark.parametrize("fill_value", fill_values) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_full_like_from_device(shape, fill_value, dtype, usm_type): """ "Use device only in dpnp.full_like() inside dpjit.""" @@ -121,7 +126,12 @@ def func(x, fill_value): @pytest.mark.parametrize("shape", shapes) @pytest.mark.parametrize("fill_value", fill_values) -@pytest.mark.parametrize("dtype", dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ), +) @pytest.mark.parametrize("usm_type", usm_types) def test_dpnp_full_like_from_queue(shape, fill_value, dtype, usm_type): """ "Use queue only in dpnp.full_like() inside dpjit.""" diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones.py index e9d41c6451..0370dbbedc 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones.py @@ -10,9 +10,12 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (3, 7)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] +dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) usm_types = ["device", "shared", "host"] @@ -22,7 +25,7 @@ def test_dpnp_ones_default(shape): @dpjit def func(shape): - c = dpnp.ones(shape) + c = dpnp.ones(shape, dtype=dpnp.float32) return c try: @@ -37,7 +40,7 @@ def func(shape): assert (c.asnumpy() == 1).all() - dummy = dpnp.ones(shape) + dummy = dpnp.ones(shape, dtype=dpnp.float32) assert c.dtype == dummy.dtype assert c.usm_type == dummy.usm_type diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones_like.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones_like.py index fd8ad5056d..174af5ce6b 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones_like.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones_like.py @@ -12,9 +12,12 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (3, 7)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] +dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) usm_types = ["device", "shared", "host"] @@ -28,7 +31,7 @@ def func(x): return y try: - a = dpnp.zeros(shape) + a = dpnp.zeros(shape, dtype=dpnp.float32) c = func(a) except Exception: pytest.fail("Calling dpnp.ones_like() inside dpjit failed.") @@ -151,7 +154,7 @@ def func1(x, queue): try: queue = dpctl.SyclQueue() - a = dpnp.zeros(10) + a = dpnp.zeros(10, dtype=dpnp.float32) func1(a, queue) except Exception as e: assert isinstance(e, errors.TypingError) @@ -180,7 +183,7 @@ def func(x): y = dpnp.ones_like(x) return y - a = numpy.ones(10) + a = numpy.ones(10, dtype=dpnp.float32) with pytest.raises(Exception): func(a) diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros.py index 8005f94876..fdf2d36131 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros.py @@ -10,9 +10,12 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (3, 7)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] +dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) usm_types = ["device", "shared", "host"] @@ -22,7 +25,7 @@ def test_dpnp_zeros_default(shape): @dpjit def func(shape): - c = dpnp.zeros(shape) + c = dpnp.zeros(shape, dtype=dpnp.float32) return c try: @@ -37,7 +40,7 @@ def func(shape): assert not c.asnumpy().any() - dummy = dpnp.zeros(shape) + dummy = dpnp.zeros(shape, dtype=dpnp.float32) assert c.dtype == dummy.dtype assert c.usm_type == dummy.usm_type diff --git a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros_like.py b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros_like.py index 2cb6e1daaf..1053394ca2 100644 --- a/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros_like.py +++ b/numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros_like.py @@ -12,9 +12,12 @@ from numba import errors from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes shapes = [11, (3, 7)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] +dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) usm_types = ["device", "shared", "host"] @@ -28,7 +31,7 @@ def func(x): return y try: - a = dpnp.ones(shape) + a = dpnp.ones(shape, dtype=dpnp.float32) c = func(a) except Exception: pytest.fail("Calling dpnp.zeros_like() inside dpjit failed.") @@ -152,7 +155,7 @@ def func1(x, queue): try: queue = dpctl.SyclQueue() - a = dpnp.ones(10) + a = dpnp.ones(10, dtype=dpnp.float32) func1(a, queue) except Exception as e: assert isinstance(e, errors.TypingError) @@ -181,7 +184,7 @@ def func(x): y = dpnp.zeros_like(x) return y - a = numpy.ones(10) + a = numpy.ones(10, dtype=dpnp.float32) with pytest.raises(Exception): func(a) diff --git a/numba_dpex/tests/dpjit_tests/parfors/test_builtin_ops.py b/numba_dpex/tests/dpjit_tests/parfors/test_builtin_ops.py index d793317f64..9434f35ba4 100644 --- a/numba_dpex/tests/dpjit_tests/parfors/test_builtin_ops.py +++ b/numba_dpex/tests/dpjit_tests/parfors/test_builtin_ops.py @@ -8,6 +8,7 @@ import pytest from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes def parfor_add(a, b): @@ -35,7 +36,9 @@ def parfor_exponent(a, b): shapes = [100, (25, 4)] -dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64] +dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) usm_types = ["device"] funcs = [ parfor_add, @@ -46,6 +49,11 @@ def parfor_exponent(a, b): parfor_exponent, ] +# TODO: fails for integer because it is being cast to float64 internally? +if dpnp.float64 not in dtypes: + funcs.remove(parfor_divide) + funcs.remove(parfor_exponent) + def parfor_floor(a, b): return a // b diff --git a/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_logic_ops.py b/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_logic_ops.py index af2022613c..34c1e993c6 100644 --- a/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_logic_ops.py +++ b/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_logic_ops.py @@ -9,6 +9,7 @@ import pytest from numba_dpex import dpjit +from numba_dpex.tests._helper import get_all_dtypes """ Following cases, dpnp raises NotImplementedError""" @@ -42,12 +43,9 @@ def unary_op(request): return request.param -list_of_dtypes = [ - dpnp.int32, - dpnp.int64, - dpnp.float32, - dpnp.float64, -] +list_of_dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) @pytest.fixture(params=list_of_dtypes) diff --git a/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_transcedental_functions.py b/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_transcedental_functions.py index 992939fdb8..7882f6c5d7 100644 --- a/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_transcedental_functions.py +++ b/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_transcedental_functions.py @@ -9,7 +9,7 @@ import pytest from numba_dpex import dpjit -from numba_dpex.tests._helper import is_gen12 +from numba_dpex.tests._helper import get_all_dtypes, is_gen12 """dpnp raise error on : mod, abs and remainder(float32)""" list_of_binary_ops = [ @@ -63,10 +63,9 @@ def unary_op(request): return request.param -list_of_dtypes = [ - dpnp.float32, - dpnp.float64, -] +list_of_dtypes = get_all_dtypes( + no_bool=True, no_int=True, no_float16=True, no_none=True, no_complex=True +) @pytest.fixture(params=list_of_dtypes) diff --git a/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_trigonometric_functions.py b/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_trigonometric_functions.py index 850b646293..9eb4c771d1 100644 --- a/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_trigonometric_functions.py +++ b/numba_dpex/tests/dpjit_tests/parfors/test_dpnp_trigonometric_functions.py @@ -9,7 +9,7 @@ import pytest from numba_dpex import dpjit -from numba_dpex.tests._helper import is_gen12 +from numba_dpex.tests._helper import get_all_dtypes, is_gen12 list_of_trig_ops = [ "sin", @@ -31,20 +31,17 @@ "radians", ] +list_of_dtypes = get_all_dtypes( + no_bool=True, no_int=True, no_float16=True, no_none=True, no_complex=True +) -@pytest.fixture(params=list_of_trig_ops) -def trig_op(request): - return request.param - - -list_of_dtypes = [ - dpnp.float32, - dpnp.float64, -] +# TODO: fails for float32 because it uses cast to float64 internally? +if dpnp.float64 not in list_of_dtypes: + list_of_trig_ops.remove("arctan2") @pytest.fixture(params=list_of_trig_ops) -def dtype(request): +def trig_op(request): return request.param diff --git a/numba_dpex/tests/dpjit_tests/test_dpjit_complex_arg_types.py b/numba_dpex/tests/dpjit_tests/test_dpjit_complex_arg_types.py index 13b9d3fdc1..43714689c1 100644 --- a/numba_dpex/tests/dpjit_tests/test_dpjit_complex_arg_types.py +++ b/numba_dpex/tests/dpjit_tests/test_dpjit_complex_arg_types.py @@ -8,6 +8,10 @@ import pytest import numba_dpex as dpex +from numba_dpex.tests._helper import ( + get_queue_or_skip, + skip_if_dtype_not_supported, +) N = 1024 @@ -34,6 +38,10 @@ def prange_array(a, b, c): @pytest.fixture(params=list_of_dtypes) def input_arrays(request): + q = get_queue_or_skip() + # TODO: looks like we are using float64 in complex64 lower... + skip_if_dtype_not_supported(request.param, q) + a = dpnp.ones(N, dtype=request.param) c = dpnp.zeros(N, dtype=request.param) b = dpnp.empty_like(a) @@ -46,8 +54,8 @@ def test_dpjit_scalar_arg_types(input_arrays): Args: input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. """ - s = 2 a, b, _ = input_arrays + s = a.dtype.type(2) prange_arg(a, b, s) @@ -63,8 +71,8 @@ def test_dpjit_arg_complex_scalar(input_arrays): Args: input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. """ - s = 2 + 1j a, b, _ = input_arrays + s = a.dtype.type(2 + 1j) prange_arg(a, b, s) diff --git a/numba_dpex/tests/dpjit_tests/test_dpjit_reduction.py b/numba_dpex/tests/dpjit_tests/test_dpjit_reduction.py index 06fb8f2671..ca0e33913c 100644 --- a/numba_dpex/tests/dpjit_tests/test_dpjit_reduction.py +++ b/numba_dpex/tests/dpjit_tests/test_dpjit_reduction.py @@ -8,14 +8,15 @@ import pytest import numba_dpex as dpex +from numba_dpex.tests._helper import get_all_dtypes N = 10 @dpex.dpjit def vecadd_prange1(a, b): - s = 0 - t = 0 + s = a.dtype.type(0) + t = a.dtype.type(0) for i in nb.prange(a.shape[0]): s += a[i] + b[i] for i in nb.prange(a.shape[0]): @@ -25,7 +26,7 @@ def vecadd_prange1(a, b): @dpex.dpjit def vecadd_prange2(a, b): - t = 0 + t = a.dtype.type(0) for i in nb.prange(a.shape[0]): t += a[i] * b[i] return t @@ -33,7 +34,7 @@ def vecadd_prange2(a, b): @dpex.dpjit def vecmul_prange(a, b): - t = 1 + t = a.dtype.type(1) for i in nb.prange(a.shape[0]): t *= a[i] + b[i] return t @@ -50,14 +51,11 @@ def vecadd_prange_float(a, b): return s - t -list_of_dtypes = [ - dpnp.int32, - dpnp.int64, - dpnp.float64, -] - - -@pytest.fixture(params=list_of_dtypes) +@pytest.fixture( + params=get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True + ) +) def input_arrays(request): a = dpnp.arange(N, dtype=request.param) b = dpnp.ones(N, dtype=request.param) @@ -107,19 +105,3 @@ def test_dpjit_array_arg_types_mul(input_arrays): c = vecmul_prange(a, b) assert s == c - - -def test_dpjit_array_arg_float32_types(input_arrays): - """Tests passing float32 type dpnp arrays to a dpjit - prange function.Local variable has to be casted to float32. - - Args: - input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. - """ - s = 9900 - a = dpnp.arange(100, dtype=dpnp.float32) - b = dpnp.arange(100, dtype=dpnp.float32) - - c = vecadd_prange_float(a, b) - - assert s == c diff --git a/numba_dpex/tests/kernel_tests/test_atomic_op.py b/numba_dpex/tests/kernel_tests/test_atomic_op.py index d4a28f8e1c..e80614c158 100644 --- a/numba_dpex/tests/kernel_tests/test_atomic_op.py +++ b/numba_dpex/tests/kernel_tests/test_atomic_op.py @@ -7,34 +7,23 @@ import numba_dpex as dpex from numba_dpex.core.descriptor import dpex_kernel_target -from numba_dpex.tests._helper import override_config +from numba_dpex.tests._helper import get_all_dtypes global_size = 100 N = global_size -list_of_i_dtypes = [ - np.int32, - np.int64, -] - -list_of_f_dtypes = [ - np.float32, - np.float64, -] +list_of_dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) -@pytest.fixture(params=list_of_i_dtypes + list_of_f_dtypes) +@pytest.fixture(params=list_of_dtypes) def return_dtype(request): return request.param -@pytest.fixture(params=list_of_f_dtypes) -def fdtype(request): - return request.param - - -@pytest.fixture(params=list_of_i_dtypes + list_of_f_dtypes) +@pytest.fixture(params=list_of_dtypes) def input_arrays(request): def _inpute_arrays(): a = np.array([0], request.param) @@ -159,7 +148,16 @@ def test_kernel_atomic_multi_dim( ("sub", "__spirv_AtomicFAddEXT"), ], ) -@pytest.mark.parametrize("dtype", list_of_f_dtypes) +@pytest.mark.parametrize( + "dtype", + get_all_dtypes( + no_bool=True, + no_int=True, + no_float16=True, + no_none=True, + no_complex=True, + ), +) def test_atomic_fp_native( function_generator, operator_name, diff --git a/numba_dpex/tests/kernel_tests/test_complex_array.py b/numba_dpex/tests/kernel_tests/test_complex_array.py index 3fba0eca60..d71e434d57 100644 --- a/numba_dpex/tests/kernel_tests/test_complex_array.py +++ b/numba_dpex/tests/kernel_tests/test_complex_array.py @@ -7,6 +7,7 @@ import pytest import numba_dpex as dpex +from numba_dpex.tests._helper import get_all_dtypes N = 1024 @@ -23,10 +24,9 @@ def kernel_array(a, b, c): b[i] = a[i] * c[i] -list_of_dtypes = [ - dpnp.complex64, - dpnp.complex128, -] +list_of_dtypes = get_all_dtypes( + no_bool=True, no_int=True, no_float=True, no_none=True +) list_of_usm_types = ["shared", "device", "host"] @@ -45,8 +45,8 @@ def test_numeric_kernel_arg_complex_scalar(input_arrays): Args: input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. """ - s = 2 + 1j a, b, _ = input_arrays + s = a.dtype.type(2 + 1j) kernel_scalar[dpex.Range(N)](a, b, s) diff --git a/numba_dpex/tests/kernel_tests/test_math_functions.py b/numba_dpex/tests/kernel_tests/test_math_functions.py index 7c9eb5c754..24ad66bd02 100644 --- a/numba_dpex/tests/kernel_tests/test_math_functions.py +++ b/numba_dpex/tests/kernel_tests/test_math_functions.py @@ -9,6 +9,7 @@ import pytest import numba_dpex as dpex +from numba_dpex.tests._helper import get_all_dtypes list_of_unary_ops = ["fabs", "exp", "log", "sqrt", "sin", "cos", "tan"] @@ -18,10 +19,9 @@ def unary_op(request): return request.param -list_of_dtypes = [ - dpnp.float32, - dpnp.float64, -] +list_of_dtypes = get_all_dtypes( + no_bool=True, no_int=True, no_float16=True, no_none=True, no_complex=True +) @pytest.fixture(params=list_of_dtypes) diff --git a/numba_dpex/tests/kernel_tests/test_scalar_arg_types.py b/numba_dpex/tests/kernel_tests/test_scalar_arg_types.py index 158ba6e320..8b1fb576cd 100644 --- a/numba_dpex/tests/kernel_tests/test_scalar_arg_types.py +++ b/numba_dpex/tests/kernel_tests/test_scalar_arg_types.py @@ -7,6 +7,7 @@ import pytest import numba_dpex as dpex +from numba_dpex.tests._helper import get_all_dtypes N = 1024 @@ -26,14 +27,7 @@ def kernel_with_bool_arg(a, b, test): b[i] = a[i] - a[i] -list_of_dtypes = [ - dpnp.int32, - dpnp.int64, - dpnp.float32, - dpnp.float64, - dpnp.complex64, - dpnp.complex128, -] +list_of_dtypes = get_all_dtypes(no_bool=True, no_float16=True, no_none=True) list_of_usm_types = ["shared", "device", "host"] @@ -52,8 +46,8 @@ def test_numeric_kernel_arg_types1(input_arrays): Args: input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. """ - s = 2 a, b = input_arrays + s = a.dtype.type(2) scaling_kernel[dpex.Range(N)](a, b, s) diff --git a/numba_dpex/tests/kernel_tests/test_sycl_usm_array_iface_interop.py b/numba_dpex/tests/kernel_tests/test_sycl_usm_array_iface_interop.py index 0ee27fba9f..bd89265bb7 100644 --- a/numba_dpex/tests/kernel_tests/test_sycl_usm_array_iface_interop.py +++ b/numba_dpex/tests/kernel_tests/test_sycl_usm_array_iface_interop.py @@ -7,6 +7,7 @@ from dpctl import tensor as dpt import numba_dpex as dpex +from numba_dpex.tests._helper import get_all_dtypes class DuckUSMArray: @@ -57,12 +58,9 @@ def vecadd(a, b, c): c[i] = a[i] + b[i] -dtypes = [ - "i4", - "i8", - "f4", - "f8", -] +dtypes = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) @pytest.fixture(params=dtypes) diff --git a/numba_dpex/tests/kernel_tests/test_usm_ndarray_interop.py b/numba_dpex/tests/kernel_tests/test_usm_ndarray_interop.py index 6289ed1679..a11a9d7e15 100644 --- a/numba_dpex/tests/kernel_tests/test_usm_ndarray_interop.py +++ b/numba_dpex/tests/kernel_tests/test_usm_ndarray_interop.py @@ -7,13 +7,17 @@ import pytest import numba_dpex as dpex - -list_of_dtype = [ - numpy.int32, - numpy.int64, - numpy.float32, - numpy.float64, -] +from numba_dpex.tests._helper import get_all_dtypes + +# list_of_dtype = [ +# numpy.int32, +# numpy.int64, +# numpy.float32, +# numpy.float64, +# ] +list_of_dtype = get_all_dtypes( + no_bool=True, no_float16=True, no_none=True, no_complex=True +) @pytest.fixture(params=list_of_dtype) diff --git a/numba_dpex/tests/test_prange.py b/numba_dpex/tests/test_prange.py index f884d07a3d..4e42db8cf6 100644 --- a/numba_dpex/tests/test_prange.py +++ b/numba_dpex/tests/test_prange.py @@ -167,15 +167,15 @@ def prange_example(a, b, c, d): device = dpctl.select_default_device() n = 10 - a = dpnp.ones((n), dtype=dpnp.float64, device=device) - b = dpnp.ones((n), dtype=dpnp.float64, device=device) - c = dpnp.zeros((n), dtype=dpnp.float64, device=device) - d = dpnp.zeros((n), dtype=dpnp.float64, device=device) + a = dpnp.ones((n), dtype=dpnp.float32, device=device) + b = dpnp.ones((n), dtype=dpnp.float32, device=device) + c = dpnp.zeros((n), dtype=dpnp.float32, device=device) + d = dpnp.zeros((n), dtype=dpnp.float32, device=device) prange_example(a, b, c, d) - np.testing.assert_equal(c.asnumpy(), np.ones((n), dtype=np.float64) * 2) - np.testing.assert_equal(d.asnumpy(), np.zeros((n), dtype=np.float64)) + np.testing.assert_equal(c.asnumpy(), np.ones((n), dtype=np.float32) * 2) + np.testing.assert_equal(d.asnumpy(), np.zeros((n), dtype=np.float32)) @pytest.mark.skip(reason="[i,:] like indexing is not supported yet.") From 2ff0da39ca8870bd1b672391c4ce04edf469f2b0 Mon Sep 17 00:00:00 2001 From: Yevhenii Havrylko Date: Thu, 28 Sep 2023 14:36:32 -0400 Subject: [PATCH 3/3] Update changelog for release 0.21.3 --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89046e060a..dbf0dc1ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,17 +4,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.21.3] - 2023-09-21 +## [0.21.3] - 2023-09-28 ### Fixed +* Pin CI conda channels (#1133) * Mangled kernel name generation (#1112) ### Added +* Support tests on single point precision GPUs (#1143) +* Initial work on Coverity scan CI (#1128) * Python 3.11 support (#1123) * Security policy (#1117) -* scikit-build to build native extensions (#1107, #1127) +* scikit-build to build native extensions (#1107, #1116, #1127, #1139, #1140) ### Changed +* Rename helper function to clearly indicate its usage (#1145) * The data model used by the DpnpNdArray type for kernel functions(#1118) ### Removed