Skip to content

Commit 511241f

Browse files
authored
Merge pull request #1158 from IntelPython/feature/introduce_dpex_opt_config
Add DPEX_OPT config and do not use numba's OPT
2 parents 39b5a5c + e70a0ff commit 511241f

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

numba_dpex/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ def __getattr__(name):
8787
# Flag to turn on the ConstantSizeStaticLocalMemoryPass in the kernel pipeline.
8888
# The pass is turned off by default.
8989
STATIC_LOCAL_MEM_PASS = _readenv("NUMBA_DPEX_STATIC_LOCAL_MEM_PASS", int, 0)
90+
91+
DPEX_OPT = _readenv("NUMBA_DPEX_OPT", int, 2)
92+
93+
INLINE_THRESHOLD = _readenv("NUMBA_DPEX_INLINE_THRESHOLD", int, None)

numba_dpex/core/codegen.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import logging
6+
57
from llvmlite import binding as ll
68
from llvmlite import ir as llvmir
79
from numba.core import utils
@@ -31,11 +33,22 @@ def _optimize_final_module(self):
3133
# Run some lightweight optimization to simplify the module.
3234
pmb = ll.PassManagerBuilder()
3335

34-
# Make optimization level depending on config.OPT variable
35-
pmb.opt_level = config.OPT
36+
# Make optimization level depending on config.DPEX_OPT variable
37+
pmb.opt_level = config.DPEX_OPT
38+
if config.DPEX_OPT > 2:
39+
logging.warning(
40+
"Setting NUMBA_DPEX_OPT greater than 2 known to cause issues "
41+
+ "related to very aggressive optimizations that leads to "
42+
+ "broken code."
43+
)
3644

3745
pmb.disable_unit_at_a_time = False
38-
pmb.inlining_threshold = 2
46+
if config.INLINE_THRESHOLD is not None:
47+
logging.warning(
48+
"Setting INLINE_THRESHOLD leads to very aggressive "
49+
+ "optimizations that may produce incorrect binary."
50+
)
51+
pmb.inlining_threshold = config.INLINE_THRESHOLD
3952
pmb.disable_unroll_loops = True
4053
pmb.loop_vectorize = False
4154
pmb.slp_vectorize = False

numba_dpex/core/kernel_interface/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(
9494
self._kernel_bundle_cache = NullCache()
9595
self._cache_hits = 0
9696

97-
if debug_flags or config.OPT == 0:
97+
if debug_flags or config.DPEX_OPT == 0:
9898
# if debug is ON we need to pass additional
9999
# flags to igc.
100100
self._create_sycl_kernel_bundle_flags = ["-g", "-cl-opt-disable"]

numba_dpex/core/parfors/kernel_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _compile_kernel_parfor(
8080
)
8181

8282
dpctl_create_program_from_spirv_flags = []
83-
if debug or config.OPT == 0:
83+
if debug or config.DPEX_OPT == 0:
8484
# if debug is ON we need to pass additional flags to igc.
8585
dpctl_create_program_from_spirv_flags = ["-g", "-cl-opt-disable"]
8686

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import logging
2+
3+
import dpnp
4+
5+
import numba_dpex as dpex
6+
import numba_dpex.config as config
7+
8+
9+
@dpex.kernel(enable_cache=False)
10+
def foo(a):
11+
a[dpex.get_global_id(0)] = 0
12+
13+
14+
def test_opt_warning(caplog):
15+
bkp = config.DPEX_OPT
16+
config.DPEX_OPT = 3
17+
18+
with caplog.at_level(logging.WARNING):
19+
foo[dpex.Range(10)](dpnp.arange(10))
20+
21+
config.DPEX_OPT = bkp
22+
23+
assert "NUMBA_DPEX_OPT" in caplog.text
24+
25+
26+
def test_inline_warning(caplog):
27+
bkp = config.INLINE_THRESHOLD
28+
config.INLINE_THRESHOLD = 2
29+
30+
with caplog.at_level(logging.WARNING):
31+
foo[dpex.Range(10)](dpnp.arange(10))
32+
33+
config.INLINE_THRESHOLD = bkp
34+
35+
assert "INLINE_THRESHOLD" in caplog.text
36+
37+
38+
def test_no_warning(caplog):
39+
with caplog.at_level(logging.WARNING):
40+
foo[dpex.Range(10)](dpnp.arange(10))
41+
42+
assert caplog.text == ""

0 commit comments

Comments
 (0)