Skip to content

Commit

Permalink
Move dpcpp/llvm-spirv from runtime to testing dependency (#659)
Browse files Browse the repository at this point in the history
* Refactor test for native FP atomics
* Move dpcpp dependency from runtime to testing environment
* Use llvm-spirv from dpcpp package and enable native FP atomics
* Install dpcpp package in test env in public CI
* Non need for setting llvm-spirv path
* Remove unused functions
  • Loading branch information
PokhodenkoSA authored Dec 2, 2021
1 parent 31f3031 commit 3a9dc25
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:
- name: Install numba-dppy
run: |
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
conda install $PACKAGE_NAME pytest python=${{ matrix.python }} numba=${{ matrix.numba }} ${{ matrix.dependencies }} $CHANNELS
conda install $PACKAGE_NAME pytest dpcpp_linux-64 python=${{ matrix.python }} numba=${{ matrix.numba }} ${{ matrix.dependencies }} $CHANNELS
# Test installed packages
conda list
- name: Run tests
Expand Down Expand Up @@ -240,7 +240,7 @@ jobs:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
- name: Install numba-dppy
run: |
conda install ${{ env.PACKAGE_NAME }} pytest python=${{ matrix.python }} ${{ matrix.dependencies }} -c $env:GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}
conda install ${{ env.PACKAGE_NAME }} pytest dpcpp_win-64 python=${{ matrix.python }} ${{ matrix.dependencies }} -c $env:GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}
# Test installed packages
conda list
- name: Install opencl_rt
Expand Down
4 changes: 2 additions & 2 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ requirements:
- numba 0.54*|0.55*
- dpctl 0.11*
- spirv-tools
- llvm-spirv 11.* # [osx]
- {{ compiler('dpcpp') }} # [not osx]
- llvm-spirv 11.*
- dpnp 0.8*|0.9* # [linux]
- packaging

test:
requires:
- pytest
- {{ compiler('dpcpp') }} # [not osx]

about:
home: https://github.com/IntelPython/numba-dppy
Expand Down
5 changes: 3 additions & 2 deletions conda-recipe/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ if [[ -v ONEAPI_ROOT ]]; then
export NUMBA_DPPY_LLVM_SPIRV_ROOT="${ONEAPI_ROOT}/compiler/latest/linux/bin"
echo "Using llvm-spirv from oneAPI"
else
export NUMBA_DPPY_LLVM_SPIRV_ROOT="${CONDA_PREFIX}/bin-llvm"
echo "Using llvm-spirv from conda environment"
echo "Using llvm-spirv from dpcpp package in conda testing environment"
fi

export NUMBA_DPPY_ACTIVATE_ATOMICS_FP_NATIVE=1

pytest -q -ra --disable-warnings -vv \
--pyargs numba_dppy.tests.kernel_tests.test_atomic_op::test_atomic_fp_native

Expand Down
101 changes: 48 additions & 53 deletions numba_dppy/tests/kernel_tests/test_atomic_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numba_dppy as dppy
from numba_dppy import config
from numba_dppy.tests._helper import skip_test
from numba_dppy.tests._helper import override_config, skip_test

global_size = 100
N = global_size
Expand Down Expand Up @@ -110,7 +110,24 @@ def test_kernel_atomic_simple(filter_str, input_arrays, kernel_result_pair):
assert a[0] == expected


def get_func_global(op_type, dtype):
"""Generate function for global address space
Used as `generator(op_type, dtype)`.
"""
op = getattr(dppy.atomic, op_type)

def f(a):
op(a, 0, 1)

return f


def get_func_local(op_type, dtype):
"""Generate function for local address space
Used as `generator(op_type, dtype)`.
"""
op = getattr(dppy.atomic, op_type)

def f(a):
Expand Down Expand Up @@ -181,61 +198,39 @@ def test_kernel_atomic_multi_dim(
assert a[0] == expected


list_of_addrspace = ["global", "local"]


@pytest.fixture(params=list_of_addrspace)
def addrspace(request):
return request.param


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")

@pytest.mark.skipif(not config.NATIVE_FP_ATOMICS, reason="Native FP atomics disabled")
@pytest.mark.parametrize(
"NATIVE_FP_ATOMICS, expected_native_atomic_for_device",
[
(1, lambda device: device != "opencl:cpu:0"),
(0, lambda device: False),
],
)
@pytest.mark.parametrize("function_generator", [get_func_global, get_func_local])
@pytest.mark.parametrize("operator_name", map(lambda x: x[0], list_of_op))
@pytest.mark.parametrize("dtype", list_of_f_dtypes)
def test_atomic_fp_native(
filter_str,
NATIVE_FP_ATOMICS,
expected_native_atomic_for_device,
function_generator,
operator_name,
dtype,
):
if atomic_skip_test(filter_str):
pytest.skip()
pytest.skip(f"No atomic support present for device {filter_str}")

a = np.array([0], fdtype)
function = function_generator(operator_name, dtype)
kernel = dppy.kernel(function)
argtypes = kernel._get_argtypes(np.array([0], dtype))

op_type, expected = return_list_of_op

if addrspace == "global":
op = getattr(dppy.atomic, op_type)
with override_config("NATIVE_FP_ATOMICS", NATIVE_FP_ATOMICS):

def f(a):
op(a, 0, 1)
with dpctl.device_context(filter_str) as sycl_queue:

elif addrspace == "local":
f = get_func_local(op_type, fdtype)
specialized_kernel = kernel[
global_size, dppy.DEFAULT_LOCAL_SIZE
].specialize(argtypes, sycl_queue)

kernel = dppy.kernel(f)

NATIVE_FP_ATOMICS_old_val = config.NATIVE_FP_ATOMICS
config.NATIVE_FP_ATOMICS = 1

LLVM_SPIRV_ROOT_old_val = config.LLVM_SPIRV_ROOT
config.LLVM_SPIRV_ROOT = LLVM_SPIRV_ROOT

with dpctl.device_context(filter_str) as sycl_queue:
kern = kernel[global_size, dppy.DEFAULT_LOCAL_SIZE].specialize(
kernel._get_argtypes(a), sycl_queue
)
if filter_str != "opencl:cpu:0":
assert "__spirv_AtomicFAddEXT" in kern.assembly
else:
assert "__spirv_AtomicFAddEXT" not in kern.assembly

config.NATIVE_FP_ATOMICS = 0

# To bypass caching
kernel = dppy.kernel(f)
with dpctl.device_context(filter_str) as sycl_queue:
kern = kernel[global_size, dppy.DEFAULT_LOCAL_SIZE].specialize(
kernel._get_argtypes(a), sycl_queue
)
assert "__spirv_AtomicFAddEXT" not in kern.assembly

config.NATIVE_FP_ATOMICS = NATIVE_FP_ATOMICS_old_val
config.LLVM_SPIRV_ROOT = LLVM_SPIRV_ROOT_old_val
is_native_atomic = "__spirv_AtomicFAddEXT" in specialized_kernel.assembly
assert is_native_atomic == expected_native_atomic_for_device(filter_str)

0 comments on commit 3a9dc25

Please sign in to comment.