Skip to content

Commit

Permalink
Test with CFD and usm_ndarray
Browse files Browse the repository at this point in the history
  • Loading branch information
chudur-budur committed Feb 10, 2023
1 parent e6c9cd1 commit 59da1d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
2 changes: 0 additions & 2 deletions numba_dpex/core/kernel_interface/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,6 @@ def __call__(self, *args):
tuple(argtypes),
self.pyfunc,
dpex_kernel_target.target_context.codegen(),
# backend=backend,
# device_type=exec_queue.sycl_device,
exec_queue=exec_queue,
)

Expand Down
68 changes: 54 additions & 14 deletions numba_dpex/tests/kernel_tests/test_arg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

import dpctl
import dpctl.tensor as dpt
import numpy as np
import pytest

Expand Down Expand Up @@ -39,13 +40,39 @@ def input_arrays(request):

@pytest.mark.parametrize("filter_str", filter_strings)
def test_kernel_arg_types(filter_str, input_arrays):
kernel = dpex.kernel(mul_kernel)
a, actual, c = input_arrays
usm_type = "device"

a, b, c = input_arrays
expected = a * c

device = dpctl.SyclDevice(filter_str)
with dpctl.device_context(device):
kernel[global_size, local_size](a, actual, c)
np.testing.assert_allclose(actual, expected, rtol=1e-5, atol=0)
queue = dpctl.SyclQueue(device)

da = dpt.usm_ndarray(
a.shape,
dtype=a.dtype,
buffer=usm_type,
buffer_ctor_kwargs={"queue": queue},
)
da.usm_data.copy_from_host(a.reshape((-1)).view("|u1"))

db = dpt.usm_ndarray(
b.shape,
dtype=b.dtype,
buffer=usm_type,
buffer_ctor_kwargs={"queue": queue},
)
db.usm_data.copy_from_host(b.reshape((-1)).view("|u1"))

kernel = dpex.kernel(mul_kernel)
kernel[dpex.NdRange(dpex.Range(global_size), dpex.Range(local_size))](
da, db, c
)

result = np.zeros_like(b)
db.usm_data.copy_to_host(result.reshape((-1)).view("|u1"))

np.testing.assert_allclose(result, expected, rtol=1e-5, atol=0)


def check_bool_kernel(A, test):
Expand All @@ -55,17 +82,30 @@ def check_bool_kernel(A, test):
A[0] = 222


@pytest.mark.skipif(
sys.platform.startswith("win"), reason="failing on teamcity windows CI"
)
@pytest.mark.parametrize("filter_str", filter_strings)
def test_bool_type(filter_str):
kernel = dpex.kernel(check_bool_kernel)
usm_type = "device"
a = np.array([2], np.int64)

device = dpctl.SyclDevice(filter_str)
with dpctl.device_context(device):
kernel[a.size, dpex.DEFAULT_LOCAL_SIZE](a, True)
assert a[0] == 111
kernel[a.size, dpex.DEFAULT_LOCAL_SIZE](a, False)
assert a[0] == 222
queue = dpctl.SyclQueue(device)

da = dpt.usm_ndarray(
a.shape,
dtype=a.dtype,
buffer=usm_type,
buffer_ctor_kwargs={"queue": queue},
)
da.usm_data.copy_from_host(a.reshape((-1)).view("|u1"))

kernel = dpex.kernel(check_bool_kernel)

kernel[dpex.Range(a.size)](da, True)
result = np.zeros_like(a)
da.usm_data.copy_to_host(result.reshape((-1)).view("|u1"))
assert result[0] == 111

kernel[dpex.Range(a.size)](da, False)
result = np.zeros_like(a)
da.usm_data.copy_to_host(result.reshape((-1)).view("|u1"))
assert result[0] == 222

0 comments on commit 59da1d9

Please sign in to comment.