Skip to content

Commit

Permalink
Update to GridTools C++ v2.2.0 (#829)
Browse files Browse the repository at this point in the history
Updates code generator to changes from GridTools v2.1.0 to GridTools v2.2.0.
- Require c++17 (consequence: drop support for CUDA < 11)
- Update to new `make` pattern.
  • Loading branch information
havogt authored Jul 12, 2022
1 parent 53620cc commit 36c7e88
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
22 changes: 10 additions & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,22 @@ exclude =
# `pip install gt4py[cuda90]` like:
cuda =
cupy
cuda90 =
cupy-cuda90
cuda91 =
cupy-cuda91
cuda92 =
cupy-cuda92
cuda100 =
cupy-cuda100
cuda101 =
cupy-cuda101
cuda102 =
cupy-cuda102
cuda110 =
cupy-cuda110
cuda111 =
cupy-cuda111
cuda112 =
cupy-cuda112
cuda113 =
cupy-cuda113
cuda114 =
cupy-cuda114
cuda115 =
cupy-cuda115
cuda116 =
cupy-cuda116
cuda117 =
cupy-cuda117
dace =
dace~=0.13
sympy
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/backend/dace_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class DaCeComputationCodegen:
const int __J = domain[1];
const int __K = domain[2];
${name}_t dace_handle;
auto allocator = gt::sid::make_cached_allocator(&${allocator}<char[]>);
auto allocator = gt::sid::cached_allocator(&${allocator}<char[]>);
${"\\n".join(tmp_allocs)}
__program_${name}(${",".join(["&dace_handle", *dace_args])});
};
Expand Down
13 changes: 7 additions & 6 deletions src/gt4py/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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


GT4PY_INSTALLATION_PATH: str = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -29,6 +29,8 @@
"CUDA_HOME", os.environ.get("CUDA_PATH", os.path.abspath("/usr/local/cuda"))
)

CUDA_HOST_CXX: Optional[str] = os.environ.get("CUDA_HOST_CXX", None)


GT_REPO_DIRNAME: str = "gridtools"
GT_INCLUDE_PATH: str = os.path.abspath(
Expand All @@ -55,17 +57,16 @@
"openmp_ldflags": os.environ.get("OPENMP_LDFLAGS", "-fopenmp").split(),
"extra_compile_args": {
"cxx": [],
"nvcc": [
# disable warnings in nvcc as a workaround for
# 'catastrophic failure' error in nvcc < 11
"--disable-warnings",
],
"nvcc": [],
},
"extra_link_args": [],
"parallel_jobs": multiprocessing.cpu_count(),
"cpp_template_depth": os.environ.get("GT_CPP_TEMPLATE_DEPTH", GT_CPP_TEMPLATE_DEPTH),
}

if CUDA_HOST_CXX is not None:
build_settings["extra_compile_args"]["nvcc"].append(f"-ccbin={CUDA_HOST_CXX}")

cache_settings: Dict[str, Any] = {
"dir_name": os.environ.get("GT_CACHE_DIR_NAME", ".gt_cache"),
"root_path": os.environ.get("GT_CACHE_ROOT", os.path.abspath(".")),
Expand Down
13 changes: 10 additions & 3 deletions src/gt4py/gt_src_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@


_DEFAULT_GRIDTOOLS_VERSION = 2
# TODO: GT2 release with CUDA SID adapter
_GRIDTOOLS_GIT_BRANCHES = {1: "v1.1.4", 2: "v2.1.0"}

_GRIDTOOLS_GIT_REPO = {
1: "https://github.com/GridTools/gridtools.git",
2: "https://github.com/GridTools/gridtools.git",
}
_GRIDTOOLS_GIT_BRANCHES = {
1: "v1.1.4",
2: "v2.2.0",
}
_GRIDTOOLS_INCLUDE_PATHS = {
1: gt_config.build_settings["gt_include_path"],
2: gt_config.build_settings["gt2_include_path"],
Expand All @@ -37,7 +44,7 @@ def install_gt_sources(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> bool:
is_ok = has_gt_sources(major_version)
if not is_ok:
GIT_BRANCH = _GRIDTOOLS_GIT_BRANCHES[major_version]
GIT_REPO = "https://github.com/GridTools/gridtools.git"
GIT_REPO = _GRIDTOOLS_GIT_REPO[major_version]

install_path = os.path.dirname(__file__)
target_path = os.path.abspath(
Expand Down
14 changes: 7 additions & 7 deletions src/gtc/cuir/cuir_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ def visit_VerticalLoop(
return *sid::multi_shifted<tag::${field}>(
device::at_key<tag::${field}>(_ptr),
m_strides,
tuple_util::device::make<hymap::keys<dim::i, dim::j, dim::k
hymap::keys<dim::i, dim::j, dim::k
% if field not in temp_names:
% for i in range(data_dims):
, integral_constant<int, ${i + 3}>
% endfor
% endif
>::template values>(i, j, k
>::make_values(i, j, k
% if field not in temp_names:
% for i in range(data_dims):
, dim_${i + 3}
Expand Down Expand Up @@ -486,7 +486,7 @@ def ctype(symbol: str) -> str:
template <class Storage>
auto block(Storage storage) {
return sid::block(std::move(storage),
tuple_util::make<hymap::keys<dim::i, dim::j>::values>(
hymap::keys<dim::i, dim::j>::make_values(
i_block_size_t(), j_block_size_t()));
}
Expand All @@ -502,7 +502,7 @@ def ctype(symbol: str) -> str:
auto ${name}(domain_t domain){
return [domain](${','.join(f'auto&& {p}' for p in params)}){
auto tmp_alloc = sid::device::make_cached_allocator(&cuda_util::cuda_malloc<char[]>);
auto tmp_alloc = sid::device::cached_allocator(&cuda_util::cuda_malloc<char[]>);
const int i_size = domain[0];
const int j_size = domain[1];
const int k_size = domain[2];
Expand Down Expand Up @@ -535,13 +535,13 @@ def ctype(symbol: str) -> str:
assert((${loop_start(vertical_loop)}) >= 0 &&
(${loop_start(vertical_loop)}) < k_size);
auto offset_${id(vertical_loop)} = tuple_util::make<hymap::keys<dim::k>::values>(
auto offset_${id(vertical_loop)} = hymap::keys<dim::k>::make_values(
${loop_start(vertical_loop)}
);
auto composite_${id(vertical_loop)} = sid::composite::make<
auto composite_${id(vertical_loop)} = sid::composite::keys<
${', '.join(f'tag::{field}' for field in loop_fields(vertical_loop))}
>(
>::make_values(
% for field in loop_fields(vertical_loop):
% if field in params:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_unittest/test_gtc/test_gtcpp_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ def build_gridtools_test(tmp_path: Path, code: str):
tmp_src = tmp_path / "test.cpp"
tmp_src.write_text(code)

extra_compile_args = ["-std=c++17"]
ext_module = setuptools.Extension(
"test",
[str(tmp_src.absolute())],
include_dirs=[config.GT2_INCLUDE_PATH, config.build_settings["boost_include_path"]],
language="c++",
extra_compile_args=extra_compile_args,
)
args = [
"build_ext",
Expand Down

0 comments on commit 36c7e88

Please sign in to comment.