Skip to content

Commit e84ddce

Browse files
author
Diptorup Deb
authored
Merge pull request #1385 from IntelPython/feature/inline_threashold
Feature/inline threshold
2 parents 0490fb0 + cf9d335 commit e84ddce

File tree

9 files changed

+38
-57
lines changed

9 files changed

+38
-57
lines changed

.github/workflows/conda-package.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,21 @@ jobs:
224224
env:
225225
NUMBA_DPEX_USE_MLIR: ${{ matrix.use_mlir && '1' || '0' }}
226226
run: |
227-
pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv
227+
pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv -k "not test_1d_strided_dpnp_array_in_kernel[2]"
228+
229+
- name: Run backendless optimization tests
230+
# Running tests that have been found to fail on AMD CPUs with
231+
# -cl-opt-disable. The test failures do not happen on other platforms
232+
# and are possibly due to some driver/opencl compiler bug.
233+
if: ${{ matrix.scope == 'tests' }}
234+
env:
235+
NUMBA_DPEX_USE_MLIR: ${{ matrix.use_mlir && '1' || '0' }}
236+
# Disabling device driver optimization to prevent catching bugs
237+
# from driver compiler.
238+
ONEAPI_DEVICE_SELECTOR: "opencl:cpu"
239+
NUMBA_DPEX_BUILD_KERNEL_OPTIONS: "-cl-opt-disable"
240+
run: |
241+
pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv -k "test_1d_strided_dpnp_array_in_kernel[2]"
228242
229243
- name: Run examples
230244
if: ${{ matrix.scope == 'examples' }}

.github/workflows/coverage.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ jobs:
5555
conda env export > /tmp/env-cov.yml
5656
cat /tmp/env-cov.yml
5757
58+
# Ignoring test due to opencl driver optimization bug
5859
- name: Run tests with coverage
5960
run: |
60-
pytest -q --cov --cov-report term-missing --pyargs numba_dpex
61+
pytest -q --cov --cov-report term-missing --pyargs numba_dpex \
62+
-k 'not test_1d_strided_dpnp_array_in_kernel[2]'
6163
6264
- name: Install coveralls
6365
shell: bash -l {0}

numba_dpex/core/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def __getattr__(name):
7373
# a kernel decorated function
7474
DEBUG_KERNEL_LAUNCHER = _readenv("NUMBA_DPEX_DEBUG_KERNEL_LAUNCHER", int, 0)
7575

76+
# Sets build kernel options for the kernel compilation on the device side.
77+
# For available OpenCL options refer
78+
# https://intel.github.io/llvm-docs/clang/ClangCommandLineReference.html#opencl-options
79+
BUILD_KERNEL_OPTIONS = _readenv("NUMBA_DPEX_BUILD_KERNEL_OPTIONS", str, "")
80+
7681
# Flag to enable caching, set NUMBA_DPEX_ENABLE_CACHE=0 to turn it off.
7782
ENABLE_CACHE = _readenv("NUMBA_DPEX_ENABLE_CACHE", int, 1)
7883
# To specify the default cache size, 20 by default.
@@ -96,6 +101,6 @@ def __getattr__(name):
96101

97102
DPEX_OPT = _readenv("NUMBA_DPEX_OPT", int, 2)
98103

99-
INLINE_THRESHOLD = _readenv("NUMBA_DPEX_INLINE_THRESHOLD", int, None)
104+
INLINE_THRESHOLD = _readenv("NUMBA_DPEX_INLINE_THRESHOLD", int, 2)
100105

101106
USE_MLIR = _readenv("NUMBA_DPEX_USE_MLIR", int, 0)

numba_dpex/core/utils/kernel_launcher.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ def set_kernel_from_spirv(self, kernel_module: SPIRVKernelModule):
304304
context_ref = sycl.dpctl_queue_get_context(self.builder, queue_ref)
305305
device_ref = sycl.dpctl_queue_get_device(self.builder, queue_ref)
306306

307+
if config.BUILD_KERNEL_OPTIONS != "":
308+
spv_compiler_options = self.context.insert_const_string(
309+
self.builder.module, config.BUILD_KERNEL_OPTIONS
310+
)
311+
else:
312+
spv_compiler_options = self.builder.load(
313+
create_null_ptr(self.builder, self.context)
314+
)
315+
307316
# build_or_get_kernel steals reference to context and device cause it
308317
# needs to keep them alive for keys.
309318
kernel_ref = self.dpexrt.build_or_get_kernel(
@@ -318,7 +327,7 @@ def set_kernel_from_spirv(self, kernel_module: SPIRVKernelModule):
318327
llvmir.Constant(
319328
llvmir.IntType(64), len(kernel_module.kernel_bitcode)
320329
),
321-
self.builder.load(create_null_ptr(self.builder, self.context)),
330+
spv_compiler_options,
322331
kernel_name,
323332
],
324333
)

numba_dpex/kernel_api_impl/spirv/codegen.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ def inline_threshold(self, value: int):
5555
)
5656
self._inline_threshold = 0
5757
else:
58-
if value == 3:
59-
warnings.warn(
60-
"Due to an existing compiler bug, setting INLINE_THRESHOLD "
61-
f"to {value} can lead to incorrect code generation on "
62-
"certain devices."
63-
)
6458
self._inline_threshold = value
6559

6660
def _optimize_final_module(self):
@@ -69,12 +63,6 @@ def _optimize_final_module(self):
6963

7064
# Make optimization level depending on config.DPEX_OPT variable
7165
pmb.opt_level = config.DPEX_OPT
72-
if config.DPEX_OPT > 2:
73-
warnings.warn(
74-
"Setting NUMBA_DPEX_OPT greater than 2 known to cause issues "
75-
+ "related to very aggressive optimizations that leads to "
76-
+ "broken code."
77-
)
7866

7967
pmb.disable_unit_at_a_time = False
8068

numba_dpex/tests/experimental/codegen/test_inline_threshold_codegen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_codegen_with_max_inline_threshold():
2828
and pipeline to compile both host callable "kernels" and device-only
2929
"device_func" functions.
3030
31-
Unless the inline_threshold is set to 3, the `spir_func` function is not
31+
Unless the inline_threshold is set to >0, the `spir_func` function is not
3232
inlined into the wrapper function. The test checks if the `spir_func`
3333
function is fully inlined into the wrapper. The test is rather rudimentary
3434
and only checks the count of function in the generated module.
@@ -39,7 +39,7 @@ def test_codegen_with_max_inline_threshold():
3939
i64arr_ty = DpnpNdArray(ndim=1, dtype=int64, layout="C", queue=queue_ty)
4040
kernel_sig = types.void(ItemType(1), i64arr_ty, i64arr_ty, i64arr_ty)
4141

42-
disp = dpex_exp.kernel(inline_threshold=3)(kernel_func)
42+
disp = dpex_exp.kernel(inline_threshold=1)(kernel_func)
4343
disp.compile(kernel_sig)
4444
kcres = disp.overloads[kernel_sig.args]
4545
llvm_ir_mod = kcres.library._final_module
@@ -60,7 +60,7 @@ def test_codegen_without_max_inline_threshold():
6060
i64arr_ty = DpnpNdArray(ndim=1, dtype=int64, layout="C", queue=queue_ty)
6161
kernel_sig = types.void(ItemType(1), i64arr_ty, i64arr_ty, i64arr_ty)
6262

63-
disp = dpex_exp.kernel(kernel_func)
63+
disp = dpex_exp.kernel(inline_threshold=0)(kernel_func)
6464
disp.compile(kernel_sig)
6565
kcres = disp.overloads[kernel_sig.args]
6666
llvm_ir_mod = kcres.library._final_module

numba_dpex/tests/experimental/codegen/test_intenum_literal_codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def pass_flags_to_func(a):
4040
i64arr_ty = DpnpNdArray(ndim=1, dtype=int64, layout="C", queue=queue_ty)
4141
kernel_sig = types.void(i64arr_ty)
4242

43-
disp = exp_dpex.kernel(pass_flags_to_func)
43+
disp = exp_dpex.kernel(inline_threshold=0)(pass_flags_to_func)
4444
disp.compile(kernel_sig)
4545
kcres = disp.overloads[kernel_sig.args]
4646
llvm_ir_mod = kcres.library._final_module.__str__()

numba_dpex/tests/experimental/test_compiler_warnings.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
import dpctl
65
import pytest
7-
from numba.core import types
86

9-
from numba_dpex import DpctlSyclQueue, DpnpNdArray
107
from numba_dpex import experimental as dpex_exp
11-
from numba_dpex import int64
12-
from numba_dpex.core.types.kernel_api.index_space_ids import ItemType
138
from numba_dpex.kernel_api import Item
149

1510

@@ -21,15 +16,3 @@ def _kernel(item: Item, a, b, c):
2116
def test_compilation_mode_option_user_definition():
2217
with pytest.warns(UserWarning):
2318
dpex_exp.kernel(_compilation_mode="kernel")(_kernel)
24-
25-
26-
def test_inline_threshold_level_warning():
27-
"""
28-
Test compiler warning generation with an inline_threshold value of 3.
29-
"""
30-
31-
with pytest.warns(UserWarning):
32-
queue_ty = DpctlSyclQueue(dpctl.SyclQueue())
33-
i64arr_ty = DpnpNdArray(ndim=1, dtype=int64, layout="C", queue=queue_ty)
34-
kernel_sig = types.void(ItemType(1), i64arr_ty, i64arr_ty, i64arr_ty)
35-
dpex_exp.kernel(inline_threshold=3)(_kernel).compile(kernel_sig)

numba_dpex/tests/misc/test_warnings.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ def foo(a):
1616
a[dpex.get_global_id(0)] = 0
1717

1818

19-
def test_opt_warning():
20-
bkp = config.DPEX_OPT
21-
config.DPEX_OPT = 3
22-
23-
with pytest.warns(UserWarning):
24-
dpex.call_kernel(foo, dpex.Range(10), dpnp.arange(10))
25-
26-
config.DPEX_OPT = bkp
27-
28-
29-
def test_inline_threshold_eq_3_warning():
30-
bkp = config.INLINE_THRESHOLD
31-
config.INLINE_THRESHOLD = 3
32-
33-
with pytest.warns(UserWarning):
34-
dpex.call_kernel(foo, dpex.Range(10), dpnp.arange(10))
35-
36-
config.INLINE_THRESHOLD = bkp
37-
38-
3919
def test_inline_threshold_negative_val_warning_():
4020
bkp = config.INLINE_THRESHOLD
4121
config.INLINE_THRESHOLD = -1

0 commit comments

Comments
 (0)