Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DPEX_OPT, INLINE_THRESHOLD config and do not use numba's OPT #1158

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions numba_dpex/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ def __getattr__(name):
# Flag to turn on the ConstantSizeStaticLocalMemoryPass in the kernel pipeline.
# The pass is turned off by default.
STATIC_LOCAL_MEM_PASS = _readenv("NUMBA_DPEX_STATIC_LOCAL_MEM_PASS", int, 0)

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

INLINE_THRESHOLD = _readenv("NUMBA_DPEX_INLINE_THRESHOLD", int, None)
19 changes: 16 additions & 3 deletions numba_dpex/core/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0

import logging

from llvmlite import binding as ll
from llvmlite import ir as llvmir
from numba.core import utils
Expand Down Expand Up @@ -31,11 +33,22 @@ def _optimize_final_module(self):
# Run some lightweight optimization to simplify the module.
pmb = ll.PassManagerBuilder()

# Make optimization level depending on config.OPT variable
pmb.opt_level = config.OPT
# Make optimization level depending on config.DPEX_OPT variable
pmb.opt_level = config.DPEX_OPT
diptorupd marked this conversation as resolved.
Show resolved Hide resolved
if config.DPEX_OPT > 2:
logging.warning(
"Setting NUMBA_DPEX_OPT greater than 2 known to cause issues "
+ "related to very aggressive optimizations that leads to "
+ "broken code."
)

pmb.disable_unit_at_a_time = False
pmb.inlining_threshold = 2
if config.INLINE_THRESHOLD is not None:
logging.warning(
"Setting INLINE_THRESHOLD leads to very aggressive "
+ "optimizations that may produce incorrect binary."
)
pmb.inlining_threshold = config.INLINE_THRESHOLD
pmb.disable_unroll_loops = True
pmb.loop_vectorize = False
pmb.slp_vectorize = False
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/kernel_interface/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
self._kernel_bundle_cache = NullCache()
self._cache_hits = 0

if debug_flags or config.OPT == 0:
if debug_flags or config.DPEX_OPT == 0:
# if debug is ON we need to pass additional
# flags to igc.
self._create_sycl_kernel_bundle_flags = ["-g", "-cl-opt-disable"]
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/parfors/kernel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _compile_kernel_parfor(
)

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

Expand Down
42 changes: 42 additions & 0 deletions numba_dpex/tests/misc/test_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import logging

import dpnp

import numba_dpex as dpex
import numba_dpex.config as config


@dpex.kernel(enable_cache=False)
def foo(a):
a[dpex.get_global_id(0)] = 0


def test_opt_warning(caplog):
bkp = config.DPEX_OPT
config.DPEX_OPT = 3

with caplog.at_level(logging.WARNING):
foo[dpex.Range(10)](dpnp.arange(10))

config.DPEX_OPT = bkp

assert "NUMBA_DPEX_OPT" in caplog.text


def test_inline_warning(caplog):
bkp = config.INLINE_THRESHOLD
config.INLINE_THRESHOLD = 2

with caplog.at_level(logging.WARNING):
foo[dpex.Range(10)](dpnp.arange(10))

config.INLINE_THRESHOLD = bkp

assert "INLINE_THRESHOLD" in caplog.text


def test_no_warning(caplog):
with caplog.at_level(logging.WARNING):
foo[dpex.Range(10)](dpnp.arange(10))

assert caplog.text == ""
Loading