Skip to content

Commit

Permalink
feat[dace]: Buildflags to the ITIR -> SDFG translation (#1389)
Browse files Browse the repository at this point in the history
Made it possible to also pass build flags to the `ITIR -> SDFG` translator.
  • Loading branch information
philip-paul-mueller authored Dec 18, 2023
1 parent cdcd653 commit 6c7c5d5
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ def get_sorted_dim_ranges(domain: common.Domain) -> Sequence[common.FiniteUnitRa

""" Default build configuration in DaCe backend """
_build_type = "Release"
# removing -ffast-math from DaCe default compiler args in order to support isfinite/isinf/isnan built-ins
_cpu_args = (
"-std=c++14 -fPIC -Wall -Wextra -O3 -march=native -Wno-unused-parameter -Wno-unused-label"
)


def convert_arg(arg: Any):
Expand Down Expand Up @@ -242,6 +238,7 @@ def build_sdfg_from_itir(
def run_dace_iterator(program: itir.FencilDefinition, *args, **kwargs):
# build parameters
build_cache = kwargs.get("build_cache", None)
compiler_args = kwargs.get("compiler_args", None) # `None` will take default.
build_type = kwargs.get("build_type", "RelWithDebInfo")
on_gpu = kwargs.get("on_gpu", False)
auto_optimize = kwargs.get("auto_optimize", False)
Expand Down Expand Up @@ -274,7 +271,10 @@ def run_dace_iterator(program: itir.FencilDefinition, *args, **kwargs):
sdfg.build_folder = compilation_cache._session_cache_dir_path / ".dacecache"
with dace.config.temporary_config():
dace.config.Config.set("compiler", "build_type", value=build_type)
dace.config.Config.set("compiler", "cpu", "args", value=_cpu_args)
if compiler_args is not None:
dace.config.Config.set(
"compiler", "cuda" if on_gpu else "cpu", "args", value=compiler_args
)
sdfg_program = sdfg.compile(validate=False)

# store SDFG program in build cache
Expand Down Expand Up @@ -312,12 +312,21 @@ def run_dace_iterator(program: itir.FencilDefinition, *args, **kwargs):


def _run_dace_cpu(program: itir.FencilDefinition, *args, **kwargs) -> None:
compiler_args = dace.config.Config.get("compiler", "cpu", "args")

# disable finite-math-only in order to support isfinite/isinf/isnan builtins
if "-ffast-math" in compiler_args:
compiler_args += " -fno-finite-math-only"
if "-ffinite-math-only" in compiler_args:
compiler_args.replace("-ffinite-math-only", "")

run_dace_iterator(
program,
*args,
**kwargs,
build_cache=_build_cache_cpu,
build_type=_build_type,
compiler_args=compiler_args,
on_gpu=False,
)

Expand Down

0 comments on commit 6c7c5d5

Please sign in to comment.