Skip to content

Commit

Permalink
feat[cartesian]: Setting extra compile args and DaCe block size via e…
Browse files Browse the repository at this point in the history
…nv variables (#1462)

* Set default block size using env variable.

* Fix nvcc flags.

* Set extra compile args using env variable.

* Rename env variable.

* Rename env variables.

* Run pre-commit.

* Use typing.List for compatibility with py3.8.

* Fix dace compilation.

* Address review comments.

* Shift statement outside if block.
  • Loading branch information
stubbiali committed Feb 26, 2024
1 parent b86a347 commit d9004cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/gt4py/cartesian/backend/dace_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,14 @@ def keep_line(line):
def apply(cls, stencil_ir: gtir.Stencil, builder: "StencilBuilder", sdfg: dace.SDFG):
self = cls()
with dace.config.temporary_config():
# To prevent conflict with 3rd party usage of DaCe config always make sure that any
# changes be under the temporary_config manager
if gt_config.GT4PY_USE_HIP:
dace.config.Config.set("compiler", "cuda", "backend", value="hip")
dace.config.Config.set("compiler", "cuda", "max_concurrent_streams", value=-1)
dace.config.Config.set(
"compiler", "cuda", "default_block_size", value=gt_config.DACE_DEFAULT_BLOCK_SIZE
)
dace.config.Config.set("compiler", "cpu", "openmp_sections", value=False)
code_objects = sdfg.generate_code()
is_gpu = "CUDA" in {co.title for co in code_objects}
Expand Down
2 changes: 2 additions & 0 deletions src/gt4py/cartesian/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def stencil_id(self) -> StencilID:
"api_annotations": f"[{', '.join(self._extract_api_annotations())}]",
**self._externals,
}
if self.builder.backend.name == "dace:gpu":
fingerprint["default_block_size"] = gt_config.DACE_DEFAULT_BLOCK_SIZE

# typeignore because attrclass StencilID has generated constructor
return StencilID( # type: ignore
Expand Down
13 changes: 8 additions & 5 deletions src/gt4py/cartesian/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import multiprocessing
import os
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

import gridtools_cpp

Expand Down Expand Up @@ -49,6 +49,10 @@
GT_CPP_TEMPLATE_DEPTH: int = 1024

# Settings dict
GT4PY_EXTRA_COMPILE_ARGS: str = os.environ.get("GT4PY_EXTRA_COMPILE_ARGS", "")
extra_compile_args: List[str] = (
list(GT4PY_EXTRA_COMPILE_ARGS.split(" ")) if GT4PY_EXTRA_COMPILE_ARGS else []
)
build_settings: Dict[str, Any] = {
"boost_include_path": os.path.join(BOOST_ROOT, "include"),
"cuda_bin_path": os.path.join(CUDA_ROOT, "bin"),
Expand All @@ -57,10 +61,7 @@
"gt_include_path": os.environ.get("GT_INCLUDE_PATH", GT_INCLUDE_PATH),
"openmp_cppflags": os.environ.get("OPENMP_CPPFLAGS", "-fopenmp").split(),
"openmp_ldflags": os.environ.get("OPENMP_LDFLAGS", "-fopenmp").split(),
"extra_compile_args": {
"cxx": [],
"cuda": [],
},
"extra_compile_args": {"cxx": extra_compile_args, "cuda": extra_compile_args},
"extra_link_args": [],
"parallel_jobs": multiprocessing.cpu_count(),
"cpp_template_depth": os.environ.get("GT_CPP_TEMPLATE_DEPTH", GT_CPP_TEMPLATE_DEPTH),
Expand All @@ -83,3 +84,5 @@
code_settings: Dict[str, Any] = {"root_package_name": "_GT_"}

os.environ.setdefault("DACE_CONFIG", os.path.join(os.path.abspath("."), ".dace.conf"))

DACE_DEFAULT_BLOCK_SIZE: str = os.environ.get("DACE_DEFAULT_BLOCK_SIZE", "64,8,1")

0 comments on commit d9004cd

Please sign in to comment.