Skip to content

Commit

Permalink
Removed filter_string from pytest in parfor tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mingjie-intel committed Mar 5, 2023
1 parent 8230e5a commit 548f014
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 46 deletions.
38 changes: 38 additions & 0 deletions drivier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import dpctl
import dpnp
import numpy

from numba_dpex import dpjit

# def parfor_divide(a, b):
# return a / b

# def test_built_in_operators(shape=(25, 4), dtype=dpnp.int32, usm_type="shared", func=parfor_divide):
# queue = dpctl.SyclQueue()
# a = dpnp.zeros(
# shape=shape, dtype=dtype, usm_type=usm_type, sycl_queue=queue
# )
# b = dpnp.ones(shape=shape, dtype=dtype, usm_type=usm_type, sycl_queue=queue)

# c = dpjit(func)(a, b)


# if len(c.shape) == 1:
# assert c.shape[0] == shape
# else:
# assert c.shape == shape

# print(c.dtype)
# print(c.usm_type)

# assert c.usm_type == usm_type

# assert c.sycl_device.filter_string == queue.sycl_device.filter_string

# expected = dpnp.asnumpy(func(a, b))
# nc = dpnp.asnumpy(c)

# numpy.allclose(nc, expected)


# test_built_in_operators()
52 changes: 46 additions & 6 deletions numba_dpex/tests/dpjit_tests/parfors/test_builtin_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parfor_exponent(a, b):

shapes = [100, (25, 4)]
dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64]
usm_types = ["device", "shared", "host"]
usm_types = ["device"]
funcs = [
parfor_add,
parfor_sub,
Expand All @@ -55,26 +55,66 @@ def parfor_floor(a, b):
@pytest.mark.parametrize("dtype", dtypes)
@pytest.mark.parametrize("usm_type", usm_types)
@pytest.mark.parametrize("func", funcs)
def test_built_in_operators(shape, dtype, usm_type, func):
def test_built_in_operators1(shape, dtype, usm_type, func):
queue = dpctl.SyclQueue()
a = dpnp.zeros(
shape=shape, dtype=dtype, usm_type=usm_type, sycl_queue=queue
)
b = dpnp.ones(shape=shape, dtype=dtype, usm_type=usm_type, sycl_queue=queue)
try:
c = dpjit(func)(a, b)
op = dpjit(func)
c = op(a, b)
del op
except Exception:
pytest.fail("Running Parfor CFD Pass check failed")
pytest.fail("Failed to compile.")

if len(c.shape) == 1:
assert c.shape[0] == shape
else:
assert c.shape == shape

assert c.dtype == dtype
if func != parfor_divide:
assert c.dtype == dtype
assert c.usm_type == usm_type

assert c.sycl_device.filter_string == queue.device.filter_string
assert c.sycl_device.filter_string == queue.sycl_device.filter_string

expected = dpnp.asnumpy(func(a, b))
nc = dpnp.asnumpy(c)

numpy.allclose(nc, expected)


usm_types = ["host", "shared"]


@pytest.mark.parametrize("shape", shapes)
@pytest.mark.parametrize("dtype", dtypes)
@pytest.mark.parametrize("usm_type", usm_types)
@pytest.mark.parametrize("func", funcs)
def test_built_in_operators2(shape, dtype, usm_type, func):
queue = dpctl.SyclQueue()
a = dpnp.zeros(
shape=shape, dtype=dtype, usm_type=usm_type, sycl_queue=queue
)
b = dpnp.ones(shape=shape, dtype=dtype, usm_type=usm_type, sycl_queue=queue)
try:
op = dpjit(func)
c = op(a, b)
del op
except Exception:
pytest.fail("Failed to compile.")

if len(c.shape) == 1:
assert c.shape[0] == shape
else:
assert c.shape == shape

if func != parfor_divide:
assert c.dtype == dtype
assert c.usm_type == usm_type

assert c.sycl_device.filter_string == queue.sycl_device.filter_string

expected = dpnp.asnumpy(func(a, b))
nc = dpnp.asnumpy(c)
Expand Down
7 changes: 2 additions & 5 deletions numba_dpex/tests/dpjit_tests/parfors/test_dpnp_bitwise_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pytest

from numba_dpex import dpjit
from numba_dpex.tests._helper import assert_auto_offloading, filter_strings

list_of_binary_ops = [
"bitwise_and",
Expand Down Expand Up @@ -51,8 +50,7 @@ def input_arrays(request):
return a, b


@pytest.mark.parametrize("filter_str", filter_strings)
def test_binary_ops(filter_str, binary_op, input_arrays):
def test_binary_ops(binary_op, input_arrays):
a, b = input_arrays
binop = getattr(dpnp, binary_op)
actual = dpnp.empty(shape=a.shape, dtype=a.dtype)
Expand All @@ -73,8 +71,7 @@ def f(a, b):
)


@pytest.mark.parametrize("filter_str", filter_strings)
def test_unary_ops(filter_str, unary_op, input_arrays):
def test_unary_ops(unary_op, input_arrays):
a = input_arrays[0]
uop = getattr(dpnp, unary_op)
actual = np.empty(shape=a.shape, dtype=a.dtype)
Expand Down
7 changes: 2 additions & 5 deletions numba_dpex/tests/dpjit_tests/parfors/test_dpnp_logic_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pytest

from numba_dpex import dpjit
from numba_dpex.tests._helper import assert_auto_offloading, filter_strings

""" Following cases, dpnp raises NotImplementedError"""

Expand Down Expand Up @@ -61,8 +60,7 @@ def input_arrays(request):


@pytest.mark.xfail
@pytest.mark.parametrize("filter_str", filter_strings)
def test_binary_ops(filter_str, binary_op, input_arrays):
def test_binary_ops(binary_op, input_arrays):
a, b = input_arrays
binop = getattr(dpnp, binary_op)
actual = dpnp.empty(shape=a.shape, dtype=a.dtype)
Expand All @@ -84,8 +82,7 @@ def f(a, b):


@pytest.mark.xfail
@pytest.mark.parametrize("filter_str", filter_strings)
def test_unary_ops(filter_str, unary_op, input_arrays):
def test_unary_ops(unary_op, input_arrays):
a = input_arrays[0]
uop = getattr(dpnp, unary_op)
actual = dpnp.empty(shape=a.shape, dtype=a.dtype)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import pytest

from numba_dpex import dpjit
from numba_dpex.tests._helper import (
assert_auto_offloading,
filter_strings,
is_gen12,
)
from numba_dpex.tests._helper import is_gen12

"""dpnp raise error on : mod, abs and remainder(float32)"""
list_of_binary_ops = [
Expand Down Expand Up @@ -82,8 +78,7 @@ def input_arrays(request):
return a, b


@pytest.mark.parametrize("filter_str", filter_strings)
def test_binary_ops(filter_str, binary_op, input_arrays):
def test_binary_ops(binary_op, input_arrays):
a, b = input_arrays
binop = getattr(dpnp, binary_op)
actual = dpnp.empty(shape=a.shape, dtype=a.dtype)
Expand All @@ -105,10 +100,10 @@ def f(a, b):
)


@pytest.mark.parametrize("filter_str", filter_strings)
def test_unary_ops(filter_str, unary_op, input_arrays):
def test_unary_ops(unary_op, input_arrays):
skip_ops = ["abs", "sign", "log", "log2", "log10", "expm1"]
if unary_op in skip_ops and is_gen12(filter_str):
device = dpctl.SyclDevice()
if unary_op in skip_ops and is_gen12(device.filter_string):
pytest.skip()

a = input_arrays[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,7 @@
import pytest

from numba_dpex import dpjit
from numba_dpex.tests._helper import (
assert_auto_offloading,
filter_strings,
is_gen12,
)

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_dpex.tests._helper import is_gen12

list_of_trig_ops = [
"sin",
Expand Down Expand Up @@ -74,10 +58,10 @@ def input_arrays(request):
return a, b


@pytest.mark.parametrize("filter_str", filter_strings)
def test_trigonometric_fn(filter_str, trig_op, input_arrays):
def test_trigonometric_fn(trig_op, input_arrays):
# FIXME: Why does archcosh fail on Gen12 discrete graphics card?
if trig_op == "arccosh" and is_gen12(filter_str):
device = dpctl.SyclDevice()
if trig_op == "arccosh" and is_gen12(device.filter_string):
pytest.skip()

a, b = input_arrays
Expand Down

0 comments on commit 548f014

Please sign in to comment.