Skip to content

Commit b4a5d42

Browse files
authored
Reintroduce icon-exclaim to spack-c2sm (#1059)
- add package for ghex - add package for hwmalloc - add package for icon-exclaim - add package for oomph - add package for uv
1 parent 11a1c49 commit b4a5d42

File tree

8 files changed

+660
-4
lines changed

8 files changed

+660
-4
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from spack.package import *
2+
3+
4+
class Ghex(CMakePackage, CudaPackage, ROCmPackage):
5+
"""
6+
GHEX is a generic halo-exchange library.
7+
8+
This Spack package was originally copied from:
9+
https://github.com/ghex-org/spack-repos/blob/main/packages/ghex/package.py
10+
11+
License: ghex-org
12+
"""
13+
14+
homepage = "https://github.com/ghex-org/GHEX"
15+
url = "https://github.com/ghex-org/GHEX/archive/refs/tags/v0.3.0.tar.gz"
16+
git = "https://github.com/ghex-org/GHEX.git"
17+
maintainers = ["boeschf"]
18+
19+
version("0.4.1", tag="v0.4.1", submodules=True)
20+
version("0.4.0", tag="v0.4.0", submodules=True)
21+
version("0.3.0", tag="v0.3.0", submodules=True)
22+
version("master", branch="master", submodules=True)
23+
24+
depends_on("cxx", type="build")
25+
26+
generator("ninja")
27+
28+
backends = ("mpi", "ucx", "libfabric")
29+
variant(
30+
"backend",
31+
default="mpi",
32+
description="Transport backend",
33+
values=backends,
34+
multi=False,
35+
)
36+
variant("xpmem", default=False, description="Use xpmem shared memory")
37+
variant("python", default=True, description="Build Python bindings")
38+
39+
depends_on("cmake@3.21:", type="build")
40+
depends_on("mpi")
41+
depends_on("boost")
42+
depends_on("xpmem", when="+xpmem", type=("build", "run"))
43+
44+
depends_on("oomph")
45+
for backend in backends:
46+
depends_on(f"oomph backend={backend}", when=f"backend={backend}")
47+
depends_on("oomph+cuda", when="+cuda")
48+
depends_on("oomph+rocm", when="+rocm")
49+
depends_on("oomph@0.3:", when="@0.3:")
50+
51+
conflicts("+cuda+rocm")
52+
53+
with when("+python"):
54+
extends("python")
55+
depends_on("python@3.7:", type="build")
56+
depends_on("py-pip", type="build")
57+
depends_on("py-pybind11", type="build")
58+
depends_on("py-mpi4py", type=("build", "run"))
59+
depends_on("py-numpy", type=("build", "run"))
60+
61+
depends_on("py-pytest", when="+python", type=("test"))
62+
63+
def cmake_args(self):
64+
spec = self.spec
65+
66+
args = [
67+
self.define("GHEX_USE_BUNDLED_LIBS", True),
68+
self.define("GHEX_USE_BUNDLED_GRIDTOOLS", True),
69+
self.define("GHEX_USE_BUNDLED_GTEST", self.run_tests),
70+
self.define("GHEX_USE_BUNDLED_OOMPH", False),
71+
self.define("GHEX_TRANSPORT_BACKEND",
72+
spec.variants["backend"].value.upper()),
73+
self.define_from_variant("GHEX_USE_XPMEM", "xpmem"),
74+
self.define_from_variant("GHEX_BUILD_PYTHON_BINDINGS", "python"),
75+
self.define("GHEX_WITH_TESTING", self.run_tests),
76+
]
77+
78+
if spec.satisfies("+python"):
79+
args.append(self.define("GHEX_PYTHON_LIB_PATH", python_platlib))
80+
81+
if self.run_tests and spec.satisfies("^openmpi"):
82+
args.append(self.define("MPIEXEC_PREFLAGS", "--oversubscribe"))
83+
84+
if "+cuda" in spec and spec.variants["cuda_arch"].value != "none":
85+
arch_str = ";".join(spec.variants["cuda_arch"].value)
86+
args.append(self.define("CMAKE_CUDA_ARCHITECTURES", arch_str))
87+
args.append(self.define("GHEX_USE_GPU", True))
88+
args.append(self.define("GHEX_GPU_TYPE", "NVIDIA"))
89+
90+
if "+rocm" in spec and spec.variants["amdgpu_target"].value != "none":
91+
arch_str = ";".join(spec.variants["amdgpu_target"].value)
92+
args.append(self.define("CMAKE_HIP_ARCHITECTURES", arch_str))
93+
args.append(self.define("GHEX_USE_GPU", True))
94+
args.append(self.define("GHEX_GPU_TYPE", "AMD"))
95+
96+
if spec.satisfies("~cuda~rocm"):
97+
args.append(self.define("GHEX_USE_GPU", False))
98+
99+
return args
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index d5420e0..35dbe56 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -105,11 +105,11 @@ install(FILES ${PROJECT_BINARY_DIR}/include/hwmalloc/config.hpp
6+
install(EXPORT HWMALLOC-targets
7+
FILE HWMALLOC-targets.cmake
8+
NAMESPACE HWMALLOC::
9+
- DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
10+
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/hwmalloc/cmake)
11+
12+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HWMALLOCConfig.cmake.in
13+
${CMAKE_CURRENT_BINARY_DIR}/HWMALLOCConfig.cmake
14+
- INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
15+
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/hwmalloc/cmake)
16+
17+
write_basic_package_version_file(HWMALLOCConfigVersion.cmake
18+
VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion)
19+
@@ -120,7 +120,7 @@ install(
20+
${CMAKE_CURRENT_BINARY_DIR}/HWMALLOCConfigVersion.cmake
21+
${CMAKE_CURRENT_LIST_DIR}/cmake/FindNUMA.cmake
22+
DESTINATION
23+
- ${CMAKE_INSTALL_LIBDIR}/cmake)
24+
+ ${CMAKE_INSTALL_LIBDIR}/hwmalloc/cmake)
25+
26+
export(EXPORT HWMALLOC-targets
27+
FILE "${CMAKE_CURRENT_BINARY_DIR}/HWMALLOC-targets.cmake")
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from spack.package import *
2+
3+
4+
class Hwmalloc(CMakePackage, CudaPackage, ROCmPackage):
5+
"""
6+
HWMALLOC is a allocator which supports memory registration for e.g. remote memory access
7+
8+
This Spack package was originally copied from:
9+
https://github.com/ghex-org/spack-repos/blob/main/packages/hwmalloc/package.py
10+
11+
License: ghex-org
12+
"""
13+
14+
homepage = "https://github.com/ghex-org/hwmalloc"
15+
url = "https://github.com/ghex-org/hwmalloc/archive/refs/tags/v0.3.0.tar.gz"
16+
git = "https://github.com/ghex-org/hwmalloc.git"
17+
maintainers = ["boeschf"]
18+
19+
version("0.3.0",
20+
sha256=
21+
"d4d4ac6087a806600d79fb62c02719ca3d58a412968fe1ef4a2fd58d9e7ee950")
22+
version("0.2.0",
23+
sha256=
24+
"734758a390a3258b86307e4aef50a7ca2e5d0e2e579f18aeefcd05397e114419")
25+
version("0.1.0",
26+
sha256=
27+
"06e9bfcef0ecce4d19531ccbe03592b502d1281c7a092bc0ff51ca187899b21c")
28+
version("master", branch="master")
29+
30+
depends_on("cxx", type="build")
31+
32+
generator("ninja")
33+
34+
depends_on("numactl", type=("build", "run"))
35+
depends_on("boost", type=("build"))
36+
depends_on("cmake@3.19:", type="build")
37+
38+
variant(
39+
"numa-throws",
40+
default=False,
41+
description="True if numa_tools may throw during initialization",
42+
)
43+
variant("numa-local",
44+
default=True,
45+
description="Use numa_tools for local node allocations")
46+
variant("logging", default=False, description="print logging info to cerr")
47+
48+
patch("cmake_install_path.patch", when="@:0.3.0", level=1)
49+
50+
def cmake_args(self):
51+
args = [
52+
self.define_from_variant("HWMALLOC_NUMA_THROWS", "numa-throws"),
53+
self.define_from_variant("HWMALLOC_NUMA_FOR_LOCAL", "numa-local"),
54+
self.define_from_variant("HWMALLOC_ENABLE_LOGGING", "logging"),
55+
self.define("HWMALLOC_WITH_TESTING", self.run_tests),
56+
]
57+
58+
if "+cuda" in self.spec:
59+
args.append(self.define("HWMALLOC_ENABLE_DEVICE", True))
60+
args.append(self.define("HWMALLOC_DEVICE_RUNTIME", "cuda"))
61+
elif "+rocm" in self.spec:
62+
args.append(self.define("HWMALLOC_ENABLE_DEVICE", True))
63+
args.append(self.define("HWMALLOC_DEVICE_RUNTIME", "hip"))
64+
else:
65+
args.append(self.define("HWMALLOC_ENABLE_DEVICE", False))
66+
67+
return args
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from spack.pkg.c2sm.icon import Icon
2+
import shutil
3+
import os
4+
import re
5+
from collections import defaultdict
6+
import spack.error as error
7+
8+
9+
def validate_variant_dsl(pkg, name, value):
10+
set_mutual_excl = set(['substitute', 'verify', 'serialize'])
11+
set_input_var = set(value)
12+
if len(set_mutual_excl.intersection(set_input_var)) > 1:
13+
raise error.SpecError(
14+
'Cannot have more than one of (substitute, verify, serialize) in the same build'
15+
)
16+
17+
18+
class IconExclaim(Icon):
19+
git = 'git@github.com:C2SM/icon-exclaim.git'
20+
21+
maintainers('jonasjucker', 'huppd')
22+
23+
version('develop', branch='icon-dsl', submodules=True)
24+
25+
# EXCLAIM-GT4Py specific features:
26+
dsl_values = ('substitute', 'verify')
27+
variant('dsl',
28+
default='none',
29+
validator=validate_variant_dsl,
30+
values=('none', ) + dsl_values,
31+
description='Build with GT4Py dynamical core',
32+
multi=True)
33+
34+
for x in dsl_values:
35+
depends_on('icon4py', type="build", when=f"dsl={x}")
36+
37+
def configure_args(self):
38+
raw_args = super().configure_args()
39+
40+
# Split into categories
41+
args_flags = []
42+
icon_ldflags = []
43+
ldflags = []
44+
libs = []
45+
46+
for a in raw_args:
47+
if a.startswith("LIBS="):
48+
libs.append(a.split("=", 1)[1].strip())
49+
elif a.startswith("ICON_LDFLAGS="):
50+
icon_ldflags.append(a.split("=", 1)[1].strip())
51+
elif a.startswith("LDFLAGS="):
52+
ldflags.append(a.split("=", 1)[1].strip())
53+
else:
54+
args_flags.append(a)
55+
56+
# Handle DSL variants
57+
dsl = self.spec.variants['dsl'].value
58+
if dsl != ('none', ):
59+
if 'substitute' in dsl:
60+
args_flags.append('--enable-py2f=substitute')
61+
elif 'verify' in dsl:
62+
args_flags.append('--enable-py2f=verify')
63+
else:
64+
raise ValueError(
65+
f"Unknown DSL variant '{dsl}'. "
66+
f"Valid options are: {', '.join(('none',) + dsl_values)}")
67+
68+
# Add icon4py paths and libs
69+
icon4py_prefix = self.spec["icon4py"].prefix
70+
bindings_dir = os.path.join(icon4py_prefix, "src")
71+
72+
ldflags.append(f"-L{bindings_dir} -Wl,-rpath,{bindings_dir}")
73+
libs.append("-licon4py_bindings")
74+
75+
# Remove duplicates
76+
icon_ldflags = list(dict.fromkeys(icon_ldflags))
77+
ldflags = list(dict.fromkeys(ldflags))
78+
libs = list(dict.fromkeys(libs))
79+
80+
# Reconstruct final configure args
81+
final_args = args_flags
82+
if icon_ldflags:
83+
final_args.append("ICON_LDFLAGS=" + " ".join(icon_ldflags))
84+
if ldflags:
85+
final_args.append("LDFLAGS=" + " ".join(ldflags))
86+
if libs:
87+
final_args.append("LIBS=" + " ".join(libs))
88+
89+
return final_args
90+
91+
def build(self, spec, prefix):
92+
# Check the variant
93+
dsl = self.spec.variants['dsl'].value
94+
if dsl != ('none', ):
95+
file = "icon4py_bindings.f90"
96+
97+
bindings_dir = os.path.join(self.spec["icon4py"].prefix, "src")
98+
src_file = os.path.join(bindings_dir, file)
99+
100+
build_py2f_dir = os.path.join(self.stage.source_path, "src",
101+
"build_py2f")
102+
os.makedirs(build_py2f_dir, exist_ok=True)
103+
dest_file = os.path.join(build_py2f_dir, file)
104+
105+
shutil.copy2(src_file, dest_file)
106+
print(
107+
f"Copied {src_file} to build directory {dest_file} because +dsl is enabled"
108+
)
109+
110+
# Proceed with the normal build
111+
super().build(spec, prefix)

repos/c2sm/packages/icon/package.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ def configure_args(self):
212212
'You use variant extra-config-args. Injecting non-variant configure arguments may potentially disrupt the build process!'
213213
)
214214

215-
# Finalize the LIBS variable (we always put the real collected
216-
# libraries to the front):
217-
flags['LIBS'].insert(0, libs.link_flags)
218-
219215
# Help the libtool scripts of the bundled libraries find the correct
220216
# paths to the external libraries. Specify the library search (-L) flags
221217
# in the reversed order

0 commit comments

Comments
 (0)