-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Diptorup Deb
committed
Oct 24, 2023
1 parent
203e7e5
commit 52b356a
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-FileCopyrightText: 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 |
105 changes: 105 additions & 0 deletions
105
numba_dpex/tests/experimental/test_kernel_dispatcher.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# 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, 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] | ||
|
||
|
||
@exp_dpex.kernel( | ||
release_gil=False, | ||
no_compile=True, | ||
no_cpython_wrapper=True, | ||
no_cfunc_wrapper=True, | ||
) | ||
def sq(a, b): | ||
a[0] = b[0] * b[0] | ||
|
||
|
||
def test_call_kernel_from_cpython(): | ||
""" | ||
Tests if we can call a kernel function from CPython using the call_kernel | ||
dpjit function. | ||
""" | ||
|
||
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] | ||
|
||
|
||
def test_call_kernel_from_dpjit(): | ||
""" | ||
Tests if we can call a kernel function from a dpjit function using the | ||
call_kernel dpjit function. | ||
""" | ||
|
||
@dpjit | ||
def range_kernel_caller(q, a, b, c): | ||
r = Range(100) | ||
exp_dpex.call_kernel(add, r, a, b, c) | ||
return c | ||
|
||
@dpjit | ||
def ndrange_kernel_caller(q, a, b, c): | ||
gr = Range(100) | ||
lr = Range(1) | ||
ndr = NdRange(gr, lr) | ||
exp_dpex.call_kernel(add, ndr, a, b, c) | ||
return c | ||
|
||
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) | ||
|
||
range_kernel_caller(q, a, b, c) | ||
|
||
assert c[0] == b[0] + a[0] | ||
|
||
ndrange_kernel_caller(q, a, b, c) | ||
|
||
assert c[0] == b[0] + a[0] | ||
|
||
|
||
def test_call_multiple_kernels(): | ||
""" | ||
Tests if the call_kernel dpjit function supports calling different types of | ||
kernel with different number of arguments. | ||
""" | ||
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) | ||
|
||
exp_dpex.call_kernel(add, r, a, b, c) | ||
|
||
assert c[0] == b[0] + a[0] | ||
|
||
exp_dpex.call_kernel(sq, r, a, c) | ||
|
||
assert a[0] == c[0] * c[0] |