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

Remove version switch for GridTools C++ #858

Merged
merged 4 commits into from
Aug 2, 2022
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
11 changes: 4 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,13 @@ repository:
# pip install git+https://github.com/gridtools/gt4py.git#egg=gt4py[cudaXX]

In either case, you need to run a post-installation script to install
GridTools C++ sources.The new ``gtc:`` backends require GridTools v2,
while the old GT4Py ``gt:`` backends require GridTools v1:
GridTools C++ sources. The backends require GridTools v2, which can be
installed with:

::

# Run the command to install GridTools v1.x C++ sources
python -m gt4py.gt_src_manager install -m 1

# Run the command to install GridTools v2.x C++ sources
python -m gt4py.gt_src_manager install -m 2
# Install the GridTools v2 sources.
python -m gt4py.gt_src_manager install

Note that ``pip`` will not delete GridTools C++ sources when
uninstalling the package, so make sure you run the remove command in
Expand Down
7 changes: 1 addition & 6 deletions src/gt4py/backend/pyext_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ def get_gt_pyext_build_opts(
else:
cuda_arch = ""

if gt_version == 1:
gt_include_path = gt_config.build_settings["gt_include_path"]
elif gt_version == 2:
gt_include_path = gt_config.build_settings["gt2_include_path"]
else:
raise RuntimeError(f"GridTools version {gt_version}.x is not supported")
gt_include_path = gt_config.build_settings["gt_include_path"]

import os

Expand Down
6 changes: 0 additions & 6 deletions src/gt4py/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@
os.path.join(os.path.dirname(__file__), "_external_src", GT_REPO_DIRNAME, "include")
)

GT2_REPO_DIRNAME: str = "gridtools2"
GT2_INCLUDE_PATH: str = os.path.abspath(
os.path.join(os.path.dirname(__file__), "_external_src", GT2_REPO_DIRNAME, "include")
)

GT_CPP_TEMPLATE_DEPTH: int = 1024

# Settings dict
Expand All @@ -52,7 +47,6 @@
"cuda_library_path": os.path.join(CUDA_ROOT, "lib64"),
"cuda_arch": os.environ.get("CUDA_ARCH", None),
"gt_include_path": os.environ.get("GT_INCLUDE_PATH", GT_INCLUDE_PATH),
"gt2_include_path": os.environ.get("GT2_INCLUDE_PATH", GT2_INCLUDE_PATH),
"openmp_cppflags": os.environ.get("OPENMP_CPPFLAGS", "-fopenmp").split(),
"openmp_ldflags": os.environ.get("OPENMP_LDFLAGS", "-fopenmp").split(),
"extra_compile_args": {
Expand Down
72 changes: 23 additions & 49 deletions src/gt4py/gt_src_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,28 @@
import gt4py.config as gt_config


_DEFAULT_GRIDTOOLS_VERSION = 2

_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"],
}
_GRIDTOOLS_REPO_DIRNAMES = {1: gt_config.GT_REPO_DIRNAME, 2: gt_config.GT2_REPO_DIRNAME}


def install_gt_sources(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> bool:
assert major_version in _GRIDTOOLS_GIT_BRANCHES

is_ok = has_gt_sources(major_version)
_GRIDTOOLS_GIT_REPO = "https://github.com/GridTools/gridtools.git"
_GRIDTOOLS_GIT_BRANCH = "v2.2.0"
_GRIDTOOLS_INCLUDE_PATHS = gt_config.build_settings["gt_include_path"]
_GRIDTOOLS_REPO_DIRNAMES = gt_config.GT_REPO_DIRNAME


def install_gt_sources() -> bool:
is_ok = has_gt_sources()
if not is_ok:
GIT_BRANCH = _GRIDTOOLS_GIT_BRANCHES[major_version]
GIT_REPO = _GRIDTOOLS_GIT_REPO[major_version]
GIT_BRANCH = _GRIDTOOLS_GIT_BRANCH
GIT_REPO = _GRIDTOOLS_GIT_REPO

install_path = os.path.dirname(__file__)
target_path = os.path.abspath(
os.path.join(install_path, "_external_src", _GRIDTOOLS_REPO_DIRNAMES[major_version])
os.path.join(install_path, "_external_src", _GRIDTOOLS_REPO_DIRNAMES)
)
if not os.path.exists(target_path):
git_cmd = f"git clone --depth 1 -b {GIT_BRANCH} {GIT_REPO} {target_path}"
print(f"Getting GridTools C++ sources...\n$ {git_cmd}")
subprocess.check_call(git_cmd.split(), stderr=subprocess.STDOUT)

is_ok = has_gt_sources(major_version)
is_ok = has_gt_sources()
if is_ok:
print("Success!!")
else:
Expand All @@ -68,12 +55,10 @@ def install_gt_sources(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> bool:
return is_ok


def remove_gt_sources(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> bool:
assert major_version in _GRIDTOOLS_REPO_DIRNAMES

def remove_gt_sources() -> bool:
install_path = os.path.dirname(__file__)
target_path = os.path.abspath(
os.path.join(install_path, "_external_src", _GRIDTOOLS_REPO_DIRNAMES[major_version])
os.path.join(install_path, "_external_src", _GRIDTOOLS_REPO_DIRNAMES)
)

is_ok = not os.path.exists(target_path)
Expand All @@ -95,15 +80,12 @@ def remove_gt_sources(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> bool:
return is_ok


def has_gt_sources(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> bool:
assert major_version in _GRIDTOOLS_INCLUDE_PATHS
return os.path.isfile(
os.path.join(_GRIDTOOLS_INCLUDE_PATHS[major_version], "gridtools", "common", "defs.hpp")
)
def has_gt_sources() -> bool:
return os.path.isfile(os.path.join(_GRIDTOOLS_INCLUDE_PATHS, "gridtools", "common", "defs.hpp"))


def _print_status(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> None:
if has_gt_sources(major_version):
def _print_status() -> None:
if has_gt_sources():
print("\nGridTools sources are installed\n")
else:
print("\nGridTools are missing (GT compiled backends will not work)\n")
Expand All @@ -112,21 +94,13 @@ def _print_status(major_version: int = _DEFAULT_GRIDTOOLS_VERSION) -> None:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Manage GridTools C++ code sources")
parser.add_argument("command", choices=["install", "remove", "status"])
parser.add_argument(
"-m",
"--major-version",
choices=list(_GRIDTOOLS_GIT_BRANCHES.keys()),
type=int,
default=_DEFAULT_GRIDTOOLS_VERSION,
help=f"major GridTools version for the installation (default: {_DEFAULT_GRIDTOOLS_VERSION})",
)
args = parser.parse_args()

if args.command == "install":
install_gt_sources(args.major_version)
_print_status(args.major_version)
install_gt_sources()
_print_status()
elif args.command == "remove":
remove_gt_sources(args.major_version)
_print_status(args.major_version)
remove_gt_sources()
_print_status()
elif args.command == "status":
_print_status(args.major_version)
_print_status()
4 changes: 2 additions & 2 deletions tests/reference_cpp_regression/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
def compile_reference():
current_dir = os.path.dirname(__file__)
build_opts = pyext_builder.get_gt_pyext_build_opts().copy()
gt2_include_path = gt_config.build_settings["gt2_include_path"]
gt_include_path = gt_config.build_settings["gt_include_path"]
build_opts["include_dirs"].extend(
[gt2_include_path, os.path.join(gt2_include_path, "..", "tests")]
[gt_include_path, os.path.join(gt_include_path, "..", "tests")]
)

build_opts.setdefault("extra_compile_args", [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unittest/test_gtc/test_cuir_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def build_gridtools_test(tmp_path: Path, code: str):

opts = pyext_builder.get_gt_pyext_build_opts(uses_cuda=True)
assert isinstance(opts["include_dirs"], list)
opts["include_dirs"].append(config.GT2_INCLUDE_PATH)
opts["include_dirs"].append(config.GT_INCLUDE_PATH)
ext_module = setuptools.Extension(
"test",
[str(tmp_src.absolute())],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unittest/test_gtc/test_gtcpp_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_gridtools_test(tmp_path: Path, code: str):
ext_module = setuptools.Extension(
"test",
[str(tmp_src.absolute())],
include_dirs=[config.GT2_INCLUDE_PATH, config.build_settings["boost_include_path"]],
include_dirs=[config.GT_INCLUDE_PATH, config.build_settings["boost_include_path"]],
language="c++",
extra_compile_args=extra_compile_args,
)
Expand Down
13 changes: 6 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ envlist =
deps = -r {toxinidir}/requirements-dev.txt
install_command = python -m pip install --no-cache-dir {opts} {packages}
commands_pre =
python -m gt4py.gt_src_manager install -m 1
python -m gt4py.gt_src_manager install -m 2
python -m gt4py.gt_src_manager install
python -m gt4py.gt_cache_manager clean
passenv = BOOST_ROOT BOOST_HOME CUDA_HOME CUDA_PATH CXX CC OPENMP_CPPFLAGS OPENMP_LDFLAGS PIP_USER PYTHONUSERBASE
whitelist_externals =
Expand All @@ -24,14 +23,14 @@ extras =
format
all: dace
cuda: cuda
cuda90: cuda90
cuda91: cuda91
cuda92: cuda92
cuda100: cuda100
cuda101: cuda101
cuda110: cuda110
cuda111: cuda111
cuda112: cuda112
cuda113: cuda113
cuda114: cuda114
cuda115: cuda115
cuda116: cuda116
cuda117: cuda117

[testenv:py{38,39}-internal-cpu]
commands =
Expand Down