From 81f631a0a17bbe7c95e089012cb413a48ff798f8 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Tue, 24 Oct 2023 11:38:52 -0500 Subject: [PATCH] Add unit tests --- numba_dpex/tests/experimental/__init__.py | 3 ++ .../experimental/test_kernel_dispatcher.py | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 numba_dpex/tests/experimental/__init__.py create mode 100644 numba_dpex/tests/experimental/test_kernel_dispatcher.py diff --git a/numba_dpex/tests/experimental/__init__.py b/numba_dpex/tests/experimental/__init__.py new file mode 100644 index 0000000000..3a217e6325 --- /dev/null +++ b/numba_dpex/tests/experimental/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 diff --git a/numba_dpex/tests/experimental/test_kernel_dispatcher.py b/numba_dpex/tests/experimental/test_kernel_dispatcher.py new file mode 100644 index 0000000000..b64dda13b6 --- /dev/null +++ b/numba_dpex/tests/experimental/test_kernel_dispatcher.py @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: 2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +import dpctl +import dpnp + +import numba_dpex.experimental as exp_dpex +from numba_dpex import NdRange, Range, config, dpjit + + +@exp_dpex.kernel( + release_gil=False, + no_compile=True, + no_cpython_wrapper=True, + no_cfunc_wrapper=True, +) +def add(a, b, c): + c[0] = b[0] + a[0] + + +def test_call_kernel_from_cpython(): + """ + Negative test to verify that NumPy arrays cannot be passed to a kernel. + """ + + q = dpctl.SyclQueue("gpu") + a = dpnp.ones(100, sycl_queue=q) + b = dpnp.ones_like(a, sycl_queue=q) + c = dpnp.zeros_like(a, sycl_queue=q) + r = Range(100) + ndr = NdRange(global_size=(100,), local_size=(1,)) + + exp_dpex.call_kernel(add, r, a, b, c) + + assert c[0] == b[0] + a[0] + + exp_dpex.call_kernel(add, ndr, a, b, c) + + assert c[0] == b[0] + a[0]