Skip to content

Commit a1c3691

Browse files
author
Diptorup Deb
committed
Move inline_threshold value checks into setter.
1 parent 0b1c766 commit a1c3691

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

numba_dpex/core/codegen.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ def inline_threshold(self, value: int):
4848
)
4949
self._inline_threshold = 0
5050
else:
51+
if value == 3:
52+
warnings.warn(
53+
"Due to an existing compiler bug, setting INLINE_THRESHOLD "
54+
f"to {value} can lead to incorrect code generation on "
55+
"certain devices."
56+
)
5157
self._inline_threshold = value
5258

5359
def _optimize_final_module(self):
@@ -64,15 +70,7 @@ def _optimize_final_module(self):
6470
)
6571

6672
pmb.disable_unit_at_a_time = False
67-
68-
if hasattr(self, "_inline_threshold") and self._inline_threshold > 0:
69-
if self._inline_threshold >= 3:
70-
warnings.warn(
71-
"Due to an existing compiler bug, setting INLINE_THRESHOLD "
72-
f"to {self._inline_threshold} can lead to incorrect "
73-
"code generation on certain devices."
74-
)
75-
pmb.inlining_threshold = self._inline_threshold
73+
pmb.inlining_threshold = self.inline_threshold
7674

7775
pmb.disable_unroll_loops = True
7876
pmb.loop_vectorize = False

numba_dpex/tests/misc/test_warnings.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def foo(a):
1212
a[dpex.get_global_id(0)] = 0
1313

1414

15-
def test_opt_warning(caplog):
15+
def test_opt_warning():
1616
bkp = config.DPEX_OPT
1717
config.DPEX_OPT = 3
1818

@@ -22,7 +22,7 @@ def test_opt_warning(caplog):
2222
config.DPEX_OPT = bkp
2323

2424

25-
def test_inline_warning(caplog):
25+
def test_inline_threshold_eq_3_warning():
2626
bkp = config.INLINE_THRESHOLD
2727
config.INLINE_THRESHOLD = 3
2828

@@ -32,7 +32,27 @@ def test_inline_warning(caplog):
3232
config.INLINE_THRESHOLD = bkp
3333

3434

35-
def test_no_warning(caplog):
35+
def test_inline_threshold_negative_val_warning_():
36+
bkp = config.INLINE_THRESHOLD
37+
config.INLINE_THRESHOLD = -1
38+
39+
with pytest.warns(UserWarning):
40+
foo[dpex.Range(10)](dpnp.arange(10))
41+
42+
config.INLINE_THRESHOLD = bkp
43+
44+
45+
def test_inline_threshold_gt_3_warning():
46+
bkp = config.INLINE_THRESHOLD
47+
config.INLINE_THRESHOLD = 4
48+
49+
with pytest.warns(UserWarning):
50+
foo[dpex.Range(10)](dpnp.arange(10))
51+
52+
config.INLINE_THRESHOLD = bkp
53+
54+
55+
def test_no_warning():
3656
with warnings.catch_warnings():
3757
warnings.simplefilter("error")
3858
foo[dpex.Range(10)](dpnp.arange(10))

0 commit comments

Comments
 (0)