Skip to content

Commit 0b1c766

Browse files
author
Diptorup Deb
committed
Enable INLINE_THRESHOLD warning for core kernel compilation.
- The numba_dpex.core.kernel_interface.disptcher.JitKernel is not a true numba Dispatcher class and as such does not fully use targetoptions. As such the commit adds a temporary work around to set the code library inline_threshold only using the config.INLINE_THRESHOLD environment flag. Unit tests were updated as well.
1 parent b3b3c71 commit 0b1c766

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

numba_dpex/core/kernel_interface/spirv_kernel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ def compile(
136136
kernel = cres.target_context.prepare_spir_kernel(
137137
func, cres.signature.args
138138
)
139+
140+
# XXX: Setting the inline_threshold in the following way is a temporary
141+
# workaround till the JitKernel dispatcher is replaced by
142+
# experimental.dispatcher.KernelDispatcher.
143+
if config.INLINE_THRESHOLD is not None:
144+
cres.library.inline_threshold = config.INLINE_THRESHOLD
145+
else:
146+
cres.library.inline_threshold = 0
147+
139148
cres.library._optimize_final_module()
140149
self._llvm_module = kernel.module.__str__()
141150
self._module_name = kernel.name
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import logging
1+
import warnings
22

33
import dpnp
4+
import pytest
45

56
import numba_dpex as dpex
67
import numba_dpex.config as config
@@ -15,28 +16,23 @@ def test_opt_warning(caplog):
1516
bkp = config.DPEX_OPT
1617
config.DPEX_OPT = 3
1718

18-
with caplog.at_level(logging.WARNING):
19+
with pytest.warns(UserWarning):
1920
foo[dpex.Range(10)](dpnp.arange(10))
2021

2122
config.DPEX_OPT = bkp
2223

23-
assert "NUMBA_DPEX_OPT" in caplog.text
24-
2524

2625
def test_inline_warning(caplog):
2726
bkp = config.INLINE_THRESHOLD
28-
config.INLINE_THRESHOLD = 2
27+
config.INLINE_THRESHOLD = 3
2928

30-
with caplog.at_level(logging.WARNING):
29+
with pytest.warns(UserWarning):
3130
foo[dpex.Range(10)](dpnp.arange(10))
3231

3332
config.INLINE_THRESHOLD = bkp
3433

35-
assert "INLINE_THRESHOLD" in caplog.text
36-
3734

3835
def test_no_warning(caplog):
39-
with caplog.at_level(logging.WARNING):
36+
with warnings.catch_warnings():
37+
warnings.simplefilter("error")
4038
foo[dpex.Range(10)](dpnp.arange(10))
41-
42-
assert caplog.text == ""

0 commit comments

Comments
 (0)