Skip to content

Commit

Permalink
Merge e3aef64 into 1ec2809
Browse files Browse the repository at this point in the history
  • Loading branch information
1e-to committed Dec 2, 2021
2 parents 1ec2809 + e3aef64 commit 921292a
Show file tree
Hide file tree
Showing 43 changed files with 237 additions and 628 deletions.
29 changes: 17 additions & 12 deletions numba_dppy/tests/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,24 @@ def platform_not_supported(device_type):
return False


def skip_test(device_type):
skip = False
try:
with dpctl.device_context(device_type):
pass
except Exception:
skip = True

if not skip:
if platform_not_supported(device_type):
skip = True
skip_no_opencl_gpu = pytest.mark.skipif(
not has_opencl_gpu(),
reason="No opencl GPU platforms available",
)
skip_no_opencl_cpu = pytest.mark.skipif(
not has_opencl_cpu(),
reason="No opencl CPU platforms available",
)
skip_no_level_zero_gpu = pytest.mark.skipif(
not has_level_zero(),
reason="No level-zero GPU platforms available",
)

return skip
filter_strings = [
pytest.param("level_zero:gpu:0", marks=skip_no_level_zero_gpu),
pytest.param("opencl:gpu:0", marks=skip_no_opencl_gpu),
pytest.param("opencl:cpu:0", marks=skip_no_opencl_cpu),
]


skip_no_opencl_gpu = pytest.mark.skipif(
Expand Down
31 changes: 12 additions & 19 deletions numba_dppy/tests/integration/test_dpnp_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import pytest

import numba_dppy as dppy
from numba_dppy.tests._helper import ensure_dpnp, skip_test
from numba_dppy.tests._helper import filter_strings
from numba_dppy.tests.njit_tests.dpnp.dpnp_skip_test import skip_no_dpnp

list_of_dtype = [
np.int32,
Expand All @@ -44,37 +45,29 @@ def usm_type(request):
return request.param


def test_dpnp_create_array_in_context(offload_device, dtype):
if not ensure_dpnp():
pytest.skip("No DPNP")

@skip_no_dpnp
@pytest.mark.parametrize("filter_str", filter_strings)
def test_dpnp_create_array_in_context(filter_str, dtype):
import dpnp

if skip_test(offload_device):
pytest.skip("No device for " + offload_device)

if (
"opencl" not in dpctl.get_current_queue().sycl_device.filter_string
and "opencl" in offload_device
and "opencl" in filter_str
):
pytest.skip("Bug in DPNP. See: IntelPython/dpnp#723")

with dpctl.device_context(offload_device):
with dpctl.device_context(filter_str):
a = dpnp.arange(1024, dtype=dtype) # noqa


def test_consuming_array_from_dpnp(offload_device, dtype):
if not ensure_dpnp():
pytest.skip("No DPNP")

@skip_no_dpnp
@pytest.mark.parametrize("filter_str", filter_strings)
def test_consuming_array_from_dpnp(filter_str, dtype):
import dpnp

if skip_test(offload_device):
pytest.skip("No device for " + offload_device)

if (
"opencl" not in dpctl.get_current_queue().sycl_device.filter_string
and "opencl" in offload_device
and "opencl" in filter_str
):
pytest.skip("Bug in DPNP. See: IntelPython/dpnp#723")

Expand All @@ -88,7 +81,7 @@ def data_parallel_sum(a, b, c):

global_size = 1021

with dpctl.device_context(offload_device):
with dpctl.device_context(filter_str):
a = dppy.asarray(dpnp.arange(global_size, dtype=dtype))
b = dppy.asarray(dpnp.arange(global_size, dtype=dtype))
c = dppy.asarray(dpnp.ones_like(a))
Expand Down
10 changes: 4 additions & 6 deletions numba_dppy/tests/integration/test_usm_ndarray_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from numba import njit

import numba_dppy as dppy
from numba_dppy.tests._helper import skip_test
from numba_dppy.tests._helper import filter_strings

list_of_dtype = [
np.int32,
Expand All @@ -46,10 +46,8 @@ def usm_type(request):
return request.param


def test_consuming_usm_ndarray(offload_device, dtype, usm_type):
if skip_test(offload_device):
pytest.skip()

@pytest.mark.parametrize("filter_str", filter_strings)
def test_consuming_usm_ndarray(filter_str, dtype, usm_type):
@dppy.kernel
def data_parallel_sum(a, b, c):
"""
Expand All @@ -66,7 +64,7 @@ def data_parallel_sum(a, b, c):

got = np.ones_like(a)

with dpctl.device_context(offload_device) as gpu_queue:
with dpctl.device_context(filter_str) as gpu_queue:
da = dpt.usm_ndarray(
a.shape,
dtype=a.dtype,
Expand Down
18 changes: 2 additions & 16 deletions numba_dppy/tests/kernel_tests/test_arg_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pytest

import numba_dppy as dppy
from numba_dppy.tests._helper import skip_test
from numba_dppy.tests._helper import filter_strings


def call_kernel(global_size, local_size, A, B, C, func):
Expand All @@ -34,18 +34,6 @@ def sum_kernel(a, b, c):
c[i] = a[i] + b[i]


list_of_filter_strs = [
"opencl:gpu:0",
"level_zero:gpu:0",
"opencl:cpu:0",
]


@pytest.fixture(params=list_of_filter_strs)
def filter_str(request):
return request.param


list_of_dtypes = [
np.float32,
np.float64,
Expand All @@ -72,10 +60,8 @@ def kernel(request):
return dppy.kernel(access_types=request.param)(sum_kernel)


@pytest.mark.parametrize("filter_str", filter_strings)
def test_kernel_arg_accessor(filter_str, input_arrays, kernel):
if skip_test(filter_str):
pytest.skip()

a, b, actual = input_arrays
expected = a + b
device = dpctl.SyclDevice(filter_str)
Expand Down
22 changes: 3 additions & 19 deletions numba_dppy/tests/kernel_tests/test_arg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pytest

import numba_dppy as dppy
from numba_dppy.tests._helper import skip_test
from numba_dppy.tests._helper import filter_strings

global_size = 1054
local_size = 1
Expand All @@ -29,18 +29,6 @@ def mul_kernel(a, b, c):
b[i] = a[i] * c


list_of_filter_strs = [
"opencl:gpu:0",
"level_zero:gpu:0",
"opencl:cpu:0",
]


@pytest.fixture(params=list_of_filter_strs)
def filter_str(request):
return request.param


list_of_dtypes = [
np.int32,
np.int64,
Expand All @@ -57,10 +45,8 @@ def input_arrays(request):
return a, b, c[0]


@pytest.mark.parametrize("filter_str", filter_strings)
def test_kernel_arg_types(filter_str, input_arrays):
if skip_test(filter_str):
pytest.skip()

kernel = dppy.kernel(mul_kernel)
a, actual, c = input_arrays
expected = a * c
Expand All @@ -77,10 +63,8 @@ def check_bool_kernel(A, test):
A[0] = 222


@pytest.mark.parametrize("filter_str", filter_strings)
def test_bool_type(filter_str):
if skip_test(filter_str):
pytest.skip()

kernel = dppy.kernel(check_bool_kernel)
a = np.array([2], np.int64)

Expand Down
48 changes: 13 additions & 35 deletions numba_dppy/tests/kernel_tests/test_atomic_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,12 @@

import numba_dppy as dppy
from numba_dppy import config
from numba_dppy.tests._helper import skip_test
from numba_dppy.tests._helper import filter_strings

global_size = 100
N = global_size


list_of_filter_strs = [
"opencl:gpu:0",
"level_zero:gpu:0",
"opencl:cpu:0",
]


@pytest.fixture(params=list_of_filter_strs)
def filter_str(request):
return request.param


list_of_i_dtypes = [
np.int32,
np.int64,
Expand Down Expand Up @@ -86,22 +74,15 @@ def f(a):
return dppy.kernel(f), request.param[1]


def atomic_skip_test(device_type):
skip = False
if skip_test(device_type):
skip = True

if not skip:
if not dppy.ocl.atomic_support_present():
skip = True

return skip
skip_atomic = pytest.mark.skipif(
not dppy.ocl.atomic_support_present(),
reason="No atomic support",
)


@skip_atomic
@pytest.mark.parametrize("filter_str", filter_strings)
def test_kernel_atomic_simple(filter_str, input_arrays, kernel_result_pair):
if atomic_skip_test(filter_str):
pytest.skip()

a, dtype = input_arrays
kernel, expected = kernel_result_pair
device = dpctl.SyclDevice(filter_str)
Expand All @@ -124,10 +105,9 @@ def f(a):
return f


@skip_atomic
@pytest.mark.parametrize("filter_str", filter_strings)
def test_kernel_atomic_local(filter_str, input_arrays, return_list_of_op):
if atomic_skip_test(filter_str):
pytest.skip()

a, dtype = input_arrays
op_type, expected = return_list_of_op
f = get_func_local(op_type, dtype)
Expand Down Expand Up @@ -165,12 +145,11 @@ def f(a):
return dppy.kernel(f)


@skip_atomic
@pytest.mark.parametrize("filter_str", filter_strings)
def test_kernel_atomic_multi_dim(
filter_str, return_list_of_op, return_list_of_dim, return_dtype
):
if atomic_skip_test(filter_str):
pytest.skip()

op_type, expected = return_list_of_op
dim = return_list_of_dim
kernel = get_kernel_multi_dim(op_type, len(dim))
Expand All @@ -189,16 +168,15 @@ def addrspace(request):
return request.param


@skip_atomic
@pytest.mark.parametrize("filter_str", filter_strings)
def test_atomic_fp_native(filter_str, return_list_of_op, fdtype, addrspace):
LLVM_SPIRV_ROOT = os.environ.get("NUMBA_DPPY_LLVM_SPIRV_ROOT")
if LLVM_SPIRV_ROOT == "" or LLVM_SPIRV_ROOT is None:
pytest.skip(
"Please set envar NUMBA_DPPY_LLVM_SPIRV_ROOT to run this test"
)

if atomic_skip_test(filter_str):
pytest.skip()

a = np.array([0], fdtype)

op_type, expected = return_list_of_op
Expand Down
24 changes: 4 additions & 20 deletions numba_dppy/tests/kernel_tests/test_barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,15 @@
import pytest

import numba_dppy as dppy
from numba_dppy.tests._helper import skip_test

list_of_filter_strs = [
"opencl:gpu:0",
"level_zero:gpu:0",
"opencl:cpu:0",
]


@pytest.fixture(params=list_of_filter_strs)
def filter_str(request):
return request.param
from numba_dppy.tests._helper import filter_strings


def skip_if_win():
return platform.system == "Windows"


@pytest.mark.parametrize("filter_str", filter_strings)
def test_proper_lowering(filter_str):
if skip_test(filter_str):
pytest.skip()

# We perform eager compilation at the site of
# @dppy.kernel. This takes the default dpctl
# queue which is level_zero backed. Level_zero
Expand Down Expand Up @@ -70,10 +57,8 @@ def twice(A):
np.testing.assert_allclose(orig * 2, arr)


@pytest.mark.parametrize("filter_str", filter_strings)
def test_no_arg_barrier_support(filter_str):
if skip_test(filter_str):
pytest.skip()

if skip_if_win():
pytest.skip()

Expand All @@ -96,9 +81,8 @@ def twice(A):
np.testing.assert_allclose(orig * 2, arr)


@pytest.mark.parametrize("filter_str", filter_strings)
def test_local_memory(filter_str):
if skip_test(filter_str):
pytest.skip()
blocksize = 10

if skip_if_win():
Expand Down
Loading

0 comments on commit 921292a

Please sign in to comment.