Skip to content

Commit

Permalink
Merge pull request #1251 from IntelPython/remove/deprecated_launch_pa…
Browse files Browse the repository at this point in the history
…rams

Removes the deprecated feature of providing kernel launch params as lists and tuple
  • Loading branch information
ZzEeKkAa authored Dec 26, 2023
2 parents a8e1e2e + b539970 commit 1f0e316
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 195 deletions.
91 changes: 15 additions & 76 deletions numba_dpex/core/kernel_interface/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,88 +293,27 @@ def __getitem__(self, args):
"""
if isinstance(args, Range):
# we need inversions, see github issue #889
# Index inversion is done here as numba-dpex first compiles a native
# kernel (OpenCL or Level Zero) and then generates a SYCL
# interoperability kernel from it. The convention for unit stride
# dimensions is opposite for OpenCL and SYCL
# refer: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:opencl:kernel-conventions-sycl
# For this reason, although numba-dpex follows SYCL like indexing in
# the kernel front-end while launching the kernel the indexing is
# reversed.
#
# TODO[1]: It needs to be investigated if we need the index reversal
# if we use SYCL-like LLVM IR indexing intrinsic instead of
# OpenCL-like LLVM IR intrinsic functions.
#
# TODO[2]: Do we need to do this when the backend is LevelZero
self._global_range = list(args)[::-1]
elif isinstance(args, NdRange):
# we need inversions, see github issue #889
self._global_range = list(args.global_range)[::-1]
self._local_range = list(args.local_range)[::-1]
else:
if (
isinstance(args, tuple)
and len(args) == 2
and isinstance(args[0], int)
and isinstance(args[1], int)
):
warn(
"Ambiguous kernel launch paramters. If your data have "
+ "dimensions > 1, include a default/empty local_range:\n"
+ " <function>[(X,Y), numba_dpex.DEFAULT_LOCAL_RANGE]"
"(<params>)\n"
+ "otherwise your code might produce erroneous results.",
DeprecationWarning,
stacklevel=2,
)
self._global_range = [args[0]]
self._local_range = [args[1]]
return self

warn(
"The current syntax for specification of kernel launch "
+ "parameters is deprecated. Users should set the kernel "
+ "parameters through Range/NdRange classes.\n"
+ "Example:\n"
+ " from numba_dpex import Range,NdRange\n\n"
+ " # for global range only\n"
+ " <function>[Range(X,Y)](<parameters>)\n"
+ " # or,\n"
+ " # for both global and local ranges\n"
+ " <function>[NdRange((X,Y), (P,Q))](<parameters>)",
DeprecationWarning,
stacklevel=2,
)

args = [args] if not isinstance(args, Iterable) else args
nargs = len(args)

# Check if the kernel enquing arguments are sane
if nargs < 1 or nargs > 2:
raise InvalidKernelLaunchArgsError(kernel_name=self.kernel_name)

g_range = (
[args[0]] if not isinstance(args[0], Iterable) else args[0]
)
# If the optional local size argument is provided
l_range = None
if nargs == 2:
if args[1] != []:
l_range = (
[args[1]]
if not isinstance(args[1], Iterable)
else args[1]
)
else:
warn(
"Empty local_range calls are deprecated. Please use "
"Range/NdRange to specify the kernel launch parameters:"
"\n"
+ "Example:\n"
+ " from numba_dpex import Range,NdRange\n\n"
+ " # for global range only\n"
+ " <function>[Range(X,Y)](<parameters>)\n"
+ " # or,\n"
+ " # for both global and local ranges\n"
+ " <function>[NdRange((X,Y), (P,Q))](<parameters>)",
DeprecationWarning,
stacklevel=2,
)

if len(g_range) < 1:
raise IllegalRangeValueError(kernel_name=self.kernel_name)

# we need inversions, see github issue #889
self._global_range = list(g_range)[::-1]
self._local_range = list(l_range)[::-1] if l_range else None
raise InvalidKernelLaunchArgsError(self.kernel_name)

return self

Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/tests/kernel_tests/test_atomic_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_kernel_atomic_local(input_arrays, return_list_of_op):
op_type, expected = return_list_of_op
f = get_func_local(op_type, dtype)
kernel = dpex.kernel(f)
kernel[dpex.Range(N), dpex.Range(N)](a)
kernel[dpex.NdRange(dpex.Range(N), dpex.Range(N))](a)
assert a[0] == expected


Expand Down
10 changes: 4 additions & 6 deletions numba_dpex/tests/kernel_tests/test_barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
#
# SPDX-License-Identifier: Apache-2.0

import dpctl
import dpctl.tensor as dpt
import numpy as np
import pytest

import numba_dpex as dpex
from numba_dpex import float32, usm_ndarray, void
from numba_dpex import NdRange, Range, float32, usm_ndarray, void

f32arrty = usm_ndarray(ndim=1, dtype=float32, layout="C")

Expand All @@ -27,7 +25,7 @@ def twice(A):
orig = dpt.asnumpy(arr)
global_size = (N,)
local_size = (N // 2,)
twice[global_size, local_size](arr)
twice[NdRange(global_size, local_size)](arr)
after = dpt.asnumpy(arr)
# The computation is correct?
np.testing.assert_allclose(orig * 2, after)
Expand All @@ -45,7 +43,7 @@ def twice(A):
N = 256
arr = dpt.arange(N, dtype=dpt.float32)
orig = dpt.asnumpy(arr)
twice[N](arr)
twice[Range(N)](arr)
after = dpt.asnumpy(arr)
# The computation is correct?
np.testing.assert_allclose(orig * 2, after)
Expand All @@ -68,7 +66,7 @@ def reverse_array(A):

arr = dpt.arange(blocksize, dtype=dpt.float32)
orig = dpt.asnumpy(arr)
reverse_array[(blocksize,), (blocksize,)](arr)
reverse_array[NdRange(Range(blocksize), Range(blocksize))](arr)
after = dpt.asnumpy(arr)
expected = orig[::-1] + orig
np.testing.assert_allclose(expected, after)
3 changes: 1 addition & 2 deletions numba_dpex/tests/kernel_tests/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import dpctl.tensor as dpt
import numpy as np
import pytest

import numba_dpex as dpex
from numba_dpex.core.caching import LRUCache
Expand Down Expand Up @@ -130,7 +129,7 @@ def data_parallel_sum(x, y, z):

d = JitKernel(data_parallel_sum)

d_launcher = d[100]
d_launcher = d[dpex.Range(100)]

N = 10
for i in range(N):
Expand Down
110 changes: 0 additions & 110 deletions numba_dpex/tests/kernel_tests/test_kernel_launch_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,98 +21,18 @@ def vecadd(a, b, c):
a[i] = b[i] + c[i]


def test_1D_global_range_as_int():
with pytest.deprecated_call():
k = vecadd[10]
assert k._global_range == [10]
assert k._local_range is None


def test_1D_global_range_as_one_tuple():
k = vecadd[Range(10)]
assert k._global_range == [10]
assert k._local_range is None


def test_1D_global_range_as_list():
with pytest.deprecated_call():
k = vecadd[[10]]
assert k._global_range == [10]
assert k._local_range is None


def test_1D_global_range_and_1D_local_range1():
with pytest.deprecated_call():
k = vecadd[[10, 10]]
assert k._global_range == [10]
assert k._local_range == [10]


def test_1D_global_range_and_1D_local_range2():
with pytest.deprecated_call():
k = vecadd[(10,), (10,)]
assert k._global_range == [10]
assert k._local_range == [10]


def test_2D_global_range_and_2D_local_range1():
with pytest.deprecated_call():
k = vecadd[(10, 10), (10, 10)]
assert k._global_range == [10, 10]
assert k._local_range == [10, 10]


def test_2D_global_range_and_2D_local_range2():
with pytest.deprecated_call():
k = vecadd[[10, 10], (10, 10)]
assert k._global_range == [10, 10]
assert k._local_range == [10, 10]


def test_2D_global_range_and_2D_local_range3():
with pytest.deprecated_call():
k = vecadd[(10, 10), [10, 10]]
assert k._global_range == [10, 10]
assert k._local_range == [10, 10]


def test_2D_global_range_and_2D_local_range4():
k = vecadd[dpex.NdRange((10, 10), (10, 10))]
assert k._global_range == [10, 10]
assert k._local_range == [10, 10]


def test_deprecation_warning_for_empty_local_range1():
with pytest.deprecated_call():
k = vecadd[[10, 10], []]
assert k._global_range == [10, 10]
assert k._local_range is None


def test_deprecation_warning_for_empty_local_range2():
with pytest.deprecated_call():
k = vecadd[10, []]
assert k._global_range == [10]
assert k._local_range is None


def test_ambiguous_kernel_launch_params():
with pytest.deprecated_call():
k = vecadd[10, 10]
assert k._global_range == [10]
assert k._local_range == [10]

with pytest.deprecated_call():
k = vecadd[(10, 10)]
assert k._global_range == [10]
assert k._local_range == [10]

with pytest.deprecated_call():
k = vecadd[((10), (10))]
assert k._global_range == [10]
assert k._local_range == [10]


def test_unknown_global_range_error():
device = dpctl.select_default_device()
a = dpt.ones(10, dtype=dpt.int16, device=device)
Expand All @@ -124,35 +44,5 @@ def test_unknown_global_range_error():
assert "No global range" in e.message


def test_illegal_kernel_launch_arg1():
with pytest.raises(InvalidKernelLaunchArgsError):
with pytest.deprecated_call():
vecadd[()]


def test_illegal_kernel_launch_arg2():
with pytest.raises(InvalidKernelLaunchArgsError):
with pytest.deprecated_call():
vecadd[10, 10, []]


def test_illegal_range_error1():
with pytest.raises(IllegalRangeValueError):
with pytest.deprecated_call():
vecadd[[], []]


def test_illegal_range_error2():
with pytest.raises(IllegalRangeValueError):
with pytest.deprecated_call():
vecadd[[], 10]


def test_illegal_range_error3():
with pytest.raises(IllegalRangeValueError):
with pytest.deprecated_call():
vecadd[(), 10]


if __name__ == "__main__":
test_unknown_global_range_error()

0 comments on commit 1f0e316

Please sign in to comment.