Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Diptorup Deb committed Dec 12, 2023
1 parent 837109e commit d175a3b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions numba_dpex/tests/experimental/kernel_iface/__init__.py
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# SPDX-FileCopyrightText: 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

import dpnp

import numba_dpex.experimental as exp_dpex
from numba_dpex import Range
from numba_dpex.experimental.kernel_iface import (
AddressSpace,
MemoryOrder,
MemoryScope,
)


def test_compilation_of_memory_order():
"""Tests if a MemoryOrder flags can be used inside a kernel function."""

@exp_dpex.kernel
def store_memory_order_flag(a):
a[0] = MemoryOrder.RELAXED
a[1] = MemoryOrder.CONSUME_UNSUPPORTED
a[2] = MemoryOrder.ACQ_REL
a[3] = MemoryOrder.ACQUIRE
a[4] = MemoryOrder.RELEASE
a[5] = MemoryOrder.SEQ_CST

a = dpnp.ones(10, dtype=dpnp.int64)
exp_dpex.call_kernel(store_memory_order_flag, Range(10), a)

assert a[0] == MemoryOrder.RELAXED
assert a[1] == MemoryOrder.CONSUME_UNSUPPORTED
assert a[2] == MemoryOrder.ACQ_REL
assert a[3] == MemoryOrder.ACQUIRE
assert a[4] == MemoryOrder.RELEASE
assert a[5] == MemoryOrder.SEQ_CST


def test_compilation_of_memory_scope():
"""Tests if a MemoryScope flags can be used inside a kernel function."""

@exp_dpex.kernel
def store_memory_scope_flag(a):
a[0] = MemoryScope.DEVICE
a[1] = MemoryScope.SUB_GROUP
a[2] = MemoryScope.WORK_GROUP
a[3] = MemoryScope.SYSTEM
a[4] = MemoryScope.WORK_ITEM

a = dpnp.ones(10, dtype=dpnp.int64)
exp_dpex.call_kernel(store_memory_scope_flag, Range(10), a)

assert a[0] == MemoryScope.DEVICE
assert a[1] == MemoryScope.SUB_GROUP
assert a[2] == MemoryScope.WORK_GROUP
assert a[3] == MemoryScope.SYSTEM
assert a[4] == MemoryScope.WORK_ITEM


def test_compilation_of_address_space():
"""Tests if a AddressSpace flags can be used inside a kernel function."""

@exp_dpex.kernel
def store_address_space_flag(a):
a[0] = AddressSpace.CONSTANT
a[1] = AddressSpace.GENERIC
a[2] = AddressSpace.GLOBAL
a[3] = AddressSpace.LOCAL
a[4] = AddressSpace.PRIVATE

a = dpnp.ones(10, dtype=dpnp.int64)
exp_dpex.call_kernel(store_address_space_flag, Range(10), a)

assert a[0] == AddressSpace.CONSTANT
assert a[1] == AddressSpace.GENERIC
assert a[2] == AddressSpace.GLOBAL
assert a[3] == AddressSpace.LOCAL
assert a[4] == AddressSpace.PRIVATE

0 comments on commit d175a3b

Please sign in to comment.