Skip to content

Commit 06d379e

Browse files
author
Diptorup Deb
committed
Unit test to validate inline_threshold target option.
1 parent 4f9616b commit 06d379e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
11
# SPDX-FileCopyrightText: 2023 Intel Corporation
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
5+
from numba.core import compiler
6+
7+
import numba_dpex as dpex
8+
from numba_dpex import experimental as dpex_exp
9+
10+
11+
def kernel_func(a, b, c):
12+
i = dpex.get_global_id(0)
13+
c[i] = a[i] + b[i]
14+
15+
16+
def test_inline_threshold_set_using_config():
17+
oldConfig = dpex.config.INLINE_THRESHOLD
18+
dpex.config.INLINE_THRESHOLD = None
19+
20+
disp = dpex_exp.kernel(kernel_func)
21+
flags = compiler.Flags()
22+
disp.targetdescr.options.parse_as_flags(flags, disp.targetoptions)
23+
24+
assert flags.inline_threshold == 0
25+
26+
dpex.config.INLINE_THRESHOLD = 2
27+
28+
flags = compiler.Flags()
29+
disp.targetdescr.options.parse_as_flags(flags, disp.targetoptions)
30+
31+
assert flags.inline_threshold == 2
32+
33+
dpex.config.INLINE_THRESHOLD = oldConfig
34+
35+
36+
def test_inline_threshold_set_using_decorator_option():
37+
"""Test setting the inline_threshold value using the kernel decorator flag"""
38+
39+
disp = dpex_exp.kernel(inline_threshold=2)(kernel_func)
40+
flags = compiler.Flags()
41+
disp.targetdescr.options.parse_as_flags(flags, disp.targetoptions)
42+
43+
assert flags.inline_threshold == 2
44+
45+
46+
def test_inline_threshold_set_using_decorator_supersedes_config_option():
47+
oldConfig = dpex.config.INLINE_THRESHOLD
48+
dpex.config.INLINE_THRESHOLD = None
49+
50+
disp = dpex_exp.kernel(inline_threshold=3)(kernel_func)
51+
flags = compiler.Flags()
52+
disp.targetdescr.options.parse_as_flags(flags, disp.targetoptions)
53+
54+
print(flags.inline_threshold)
55+
assert flags.inline_threshold == 3
56+
57+
dpex.config.INLINE_THRESHOLD = oldConfig

0 commit comments

Comments
 (0)