Skip to content

Commit

Permalink
Added dpnp.empty() tests.
Browse files Browse the repository at this point in the history
Added runtime tests.
  • Loading branch information
mingjie-intel committed Feb 14, 2023
1 parent 253be29 commit b554084
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 28 deletions.
6 changes: 6 additions & 0 deletions numba_dpex/tests/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

from .._helper import *
from . import *
32 changes: 32 additions & 0 deletions numba_dpex/tests/core/runtime/test_llvm_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0


import llvmlite.binding as llb

from numba_dpex.core import runtime


def test_llvm_symbol_registered():
""" "Register the helper function in _dpexrt_python so that we can insert calls to them via llvmlite.
1. DPEXRT_sycl_usm_ndarray_from_python
2.DPEXRT_sycl_usm_ndarray_to_python_acqref
"""
assert (
llb.address_of_symbol("DPEXRT_sycl_usm_ndarray_from_python")
== runtime._dpexrt_python.DPEXRT_sycl_usm_ndarray_from_python
)

assert (
llb.address_of_symbol("DPEXRT_sycl_usm_ndarray_to_python_acqref")
== runtime._dpexrt_python.DPEXRT_sycl_usm_ndarray_to_python_acqref
)

assert (
llb.address_of_symbol("NRT_ExternalAllocator_new_for_usm")
== runtime._dpexrt_python.NRT_ExternalAllocator_new_for_usm
)
19 changes: 19 additions & 0 deletions numba_dpex/tests/core/runtime/test_runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0


from numba_dpex.core.runtime import _dpexrt_python


def test_pointers_exposed():
"""This test is to check attributts in _dpexrt_python."""

def exposed(function_name):
assert hasattr(_dpexrt_python, function_name)
assert isinstance(getattr(_dpexrt_python, function_name), int)

exposed("DPEXRT_sycl_usm_ndarray_from_python")
exposed("DPEXRT_sycl_usm_ndarray_to_python_acqref")
exposed("DPEXRT_MemInfo_alloc")
exposed("NRT_ExternalAllocator_new_for_usm")
32 changes: 32 additions & 0 deletions numba_dpex/tests/core/test_dpjit_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

"""Tests for class DpexTargetContext."""


import pytest
from numba.core import typing
from numba.core.codegen import JITCPUCodegen

from numba_dpex.core.targets.dpjit_target import DpexTargetContext

ctx = typing.Context()
dpexctx = DpexTargetContext(ctx)


def test_dpjit_target():
assert dpexctx.lower_extensions == {}
assert dpexctx.is32bit is False
assert dpexctx.dpexrt is not None
assert (
isinstance(dpexctx._internal_codegen, type(JITCPUCodegen("numba.exec")))
== 1
)


def test_dpjit_target_refresh():
try:
dpexctx.refresh
except KeyError:
pytest.fail("Unexpected KeyError in dpjit_target.")
6 changes: 6 additions & 0 deletions numba_dpex/tests/dpjit_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

from .._helper import *
from . import *
36 changes: 36 additions & 0 deletions numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty_dpjit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

"""Tests for dpnp ndarray constructors."""

import dpnp
import pytest

from numba_dpex import dpjit

shapes = [10, (2, 5)]
dtypes = [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64]
usm_types = ["device", "shared", "host"]
devices = ["cpu", "unknown"]


@pytest.mark.parametrize("shape", shapes)
@pytest.mark.parametrize("dtype", dtypes)
@pytest.mark.parametrize("usm_type", usm_types)
@pytest.mark.parametrize("device", devices)
def test_dpnp_empty(shape, dtype, usm_type, device):
@dpjit
def func(shape):
dpnp.empty(shape=shape, dtype=dtype, usm_type=usm_type, device=device)

@dpjit
def func1(shape):
c = dpnp.empty(
shape=shape, dtype=dtype, usm_type=usm_type, device=device
)
return c

func(shape)

func1(shape)
28 changes: 0 additions & 28 deletions numba_dpex/tests/njit_tests/dpnp_ndarray/test_dpnp_empty.py

This file was deleted.

31 changes: 31 additions & 0 deletions numba_dpex/tests/test_usm_ndarray_type_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: 2020 - 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

"""This is to test USMNdArray raising correct exceptions."""

import dpnp
import pytest
from numba import njit
from numba.core.errors import TypingError

from numba_dpex.dpctl_iface import get_current_queue

arguments = [
("shape=10", 'device="cpu"', "queue=a.sycl_queue"),
("shape=10", "device=10", "queue=a.sycl_queue"),
("shape=10", 'device="cpu"', "queue=test"),
("shape=10", 'device="dpu"'),
]


@pytest.mark.parametrize("argument", arguments)
def test_usm_ndarray_type_exceptions(argument):
a = dpnp.ndarray(10)

@njit
def func(a):
dpnp.empty(argument)

with pytest.raises(TypingError):
func(a)

0 comments on commit b554084

Please sign in to comment.