Skip to content

Commit c13681e

Browse files
committed
Update CARE spack package
1 parent 27997db commit c13681e

File tree

1 file changed

+184
-92
lines changed

1 file changed

+184
-92
lines changed
Lines changed: 184 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
1+
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
22
# Spack Project Developers. See the top-level COPYRIGHT file for details.
33
#
44
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
55

6+
import socket
7+
68
from spack.package import *
79

10+
from .camp import cuda_for_radiuss_projects
11+
from .camp import hip_for_radiuss_projects
12+
from .blt import llnl_link_helpers
13+
814

9-
class Care(CMakePackage, CudaPackage, ROCmPackage):
15+
class Care(CachedCMakePackage, CudaPackage, ROCmPackage):
1016
"""
11-
Algorithms for chai managed arrays.
17+
CHAI and RAJA extensions (includes data structures and algorithms).
1218
"""
1319

1420
homepage = "https://github.com/LLNL/CARE"
@@ -20,170 +26,256 @@ class Care(CMakePackage, CudaPackage, ROCmPackage):
2026
maintainers("adayton1")
2127

2228
version("develop", branch="develop", submodules="True")
23-
version("master", branch="main", submodules="True")
29+
version("master", branch="master", submodules="True")
2430
version(
2531
"0.13.1",
2632
tag="v0.13.1",
2733
commit="0fd0d47aaaa57076f26caad88e667fbc01ff7214",
28-
submodules="True"
34+
submodules="True",
2935
)
3036
version(
3137
"0.13.0",
3238
tag="v0.13.0",
3339
commit="2b288e2c557c3b14befeebc8e14a7d48348bd857",
34-
submodules="True"
40+
submodules="True",
3541
)
3642
version(
3743
"0.12.0",
3844
tag="v0.12.0",
3945
commit="a9978083035eb00a090451bd36d7987bc935204d",
40-
submodules="True"
46+
submodules="True",
4147
)
48+
version("0.10.0", tag="v0.10.0", submodules="True")
4249
version(
43-
"0.3.0",
44-
tag="v0.3.0",
45-
commit="5e2b69b2836c9f2215207ca9a36a690cb77eea33",
46-
submodules="True"
50+
"0.3.0", tag="v0.3.0", commit="5e2b69b2836c9f2215207ca9a36a690cb77eea33", submodules="True"
4751
)
4852
version(
49-
"0.2.0",
50-
tag="v0.2.0",
51-
commit="30135e03b14b1dc753634e9147dafede0663906f",
52-
submodules="True"
53+
"0.2.0", tag="v0.2.0", commit="30135e03b14b1dc753634e9147dafede0663906f", submodules="True"
5354
)
5455

55-
variant("openmp", default=False, description="Build using OpenMP")
56+
variant("openmp", default=False, description="Build with OpenMP support")
57+
variant("mpi", default=False, description="Enable MPI support")
5658
variant(
5759
"implicit_conversions",
58-
default=True,
59-
description="Enable implicit conversions to/from raw pointers",
60+
default=False,
61+
description="Enable implicit" "conversions to/from raw pointers",
6062
)
61-
variant("benchmarks", default=True, description="Build benchmarks.")
62-
variant("examples", default=True, description="Build examples.")
63-
variant("docs", default=False, description="Build documentation")
6463
variant("tests", default=False, description="Build tests")
64+
variant("benchmarks", default=False, description="Build benchmarks.")
65+
variant("examples", default=False, description="Build examples.")
66+
variant("docs", default=False, description="Build documentation")
6567
variant("loop_fuser", default=False, description="Enable loop fusion capability")
6668

67-
depends_on("cmake@3.8:", type="build")
68-
depends_on("cmake@3.9:", type="build", when="+cuda")
69-
depends_on("cmake@3.18:", type="build", when="@0.12.0:")
7069
depends_on("cmake@3.21:", type="build", when="@0.12.0:+rocm")
70+
depends_on("cmake@3.18:", type="build", when="@0.12.0:")
71+
depends_on("cmake@3.14:", type="build", when="@0.10.0:")
72+
depends_on("cmake@3.9:", type="build", when="+cuda")
73+
depends_on("cmake@3.8:", type="build")
7174

7275
depends_on("blt")
7376
depends_on("blt@0.6.2:", type="build", when="@0.13.0:")
7477
depends_on("blt@0.6.1:", type="build", when="@0.12.0:")
75-
depends_on("blt@0.4.0:", type="build", when="@0.3.1:")
78+
depends_on("blt@0.5.2:", type="build", when="@0.10.0:")
79+
depends_on("blt@0.4.1:", type="build", when="@0.3.1:")
7680
depends_on("blt@:0.3.6", type="build", when="@:0.3.0")
7781
conflicts("^blt@:0.3.6", when="+rocm")
7882

7983
depends_on("camp", when="@:0.11.1")
8084

8185
depends_on("umpire")
86+
depends_on("umpire+mpi", when="+mpi")
8287
depends_on("umpire@2024.02.1:", when="@0.13.0:")
8388
depends_on("umpire@2024.02.0:", when="@0.12.0:")
89+
depends_on("umpire@2022.10.0:", when="@0.10.0:")
8490

8591
depends_on("raja")
8692
depends_on("raja@2024.02.2:", when="@0.13.1:")
8793
depends_on("raja@2024.02.1:", when="@0.13.0:")
8894
depends_on("raja@2024.02.0:", when="@0.12.0:")
95+
depends_on("raja@2022.10.5:", when="@0.10.0:")
8996

97+
# TODO: Add an enable_pick variant
9098
depends_on("chai+enable_pick+raja")
9199
depends_on("chai@2024.02.2:", when="@0.13.1:")
92100
depends_on("chai@2024.02.1:", when="@0.13.0:")
93101
depends_on("chai@2024.02.0:", when="@0.12.0:")
102+
depends_on("chai@2022.10.0:", when="@0.10.0:")
103+
94104

95105
with when("+openmp"):
96-
depends_on("llvm-openmp", when="%apple-clang")
97106
depends_on("umpire+openmp")
98107
depends_on("raja+openmp")
99108
depends_on("chai+openmp")
100109

101-
with when("+rocm"):
102-
depends_on("rocprim")
103-
104-
for arch in ROCmPackage.amdgpu_targets:
105-
depends_on("umpire+rocm amdgpu_target={0}".format(arch), when="amdgpu_target={0}".format(arch))
106-
depends_on("raja+rocm amdgpu_target={0}".format(arch), when="amdgpu_target={0}".format(arch))
107-
depends_on("chai+rocm amdgpu_target={0}".format(arch), when="amdgpu_target={0}".format(arch))
108-
109110
with when("+cuda"):
110-
depends_on("cub", when="cuda@:10.2")
111+
# WARNING: this package currently only supports an internal cub
112+
# package. This will cause a race condition if compiled with another
113+
# package that uses cub. TODO: have all packages point to the same external
114+
# cub package.
115+
depends_on("cub")
116+
117+
depends_on("umpire+cuda")
118+
depends_on("raja+cuda")
119+
depends_on("chai+cuda")
111120

112121
for sm_ in CudaPackage.cuda_arch_values:
113122
depends_on("umpire+cuda cuda_arch={0}".format(sm_), when="cuda_arch={0}".format(sm_))
114123
depends_on("raja+cuda cuda_arch={0}".format(sm_), when="cuda_arch={0}".format(sm_))
115124
depends_on("chai+cuda cuda_arch={0}".format(sm_), when="cuda_arch={0}".format(sm_))
116125

126+
with when("+rocm"):
127+
depends_on("umpire+rocm")
128+
depends_on("raja+rocm")
129+
depends_on("chai+rocm")
117130

118-
def cmake_args(self):
131+
for arch_ in ROCmPackage.amdgpu_targets:
132+
depends_on('umpire+rocm amdgpu_target={0}'.format(arch_), when='amdgpu_target={0}'.format(arch_))
133+
depends_on('raja+rocm amdgpu_target={0}'.format(arch_), when='amdgpu_target={0}'.format(arch_))
134+
depends_on('chai+rocm amdgpu_target={0}'.format(arch_), when='amdgpu_target={0}'.format(arch_))
135+
136+
137+
def _get_sys_type(self, spec):
138+
sys_type = spec.architecture
139+
140+
if "SYS_TYPE" in env:
141+
sys_type = env["SYS_TYPE"]
142+
return sys_type
143+
144+
145+
@property
146+
def cache_name(self):
147+
hostname = socket.gethostname()
148+
149+
if "SYS_TYPE" in env:
150+
hostname = hostname.rstrip("1234567890")
151+
return "{0}-{1}-{2}@{3}-{4}.cmake".format(
152+
hostname,
153+
self._get_sys_type(self.spec),
154+
self.spec.compiler.name,
155+
self.spec.compiler.version,
156+
self.spec.dag_hash(8)
157+
)
158+
159+
160+
def initconfig_compiler_entries(self):
119161
spec = self.spec
120-
from_variant = self.define_from_variant
162+
compiler = self.compiler
163+
entries = super().initconfig_compiler_entries()
121164

122-
options = []
123-
options.append("-DBLT_SOURCE_DIR={0}".format(spec["blt"].prefix))
165+
#### BEGIN: Override CachedCMakePackage CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
166+
flags = spec.compiler_flags
167+
168+
# use global spack compiler flags
169+
cppflags = " ".join(flags["cppflags"])
170+
171+
if cppflags:
172+
# avoid always ending up with " " with no flags defined
173+
cppflags += " "
174+
175+
cflags = cppflags + " ".join(flags["cflags"])
176+
177+
if cflags:
178+
entries.append(cmake_cache_string("CMAKE_C_FLAGS", cflags))
179+
180+
cxxflags = cppflags + " ".join(flags["cxxflags"])
181+
182+
if cxxflags:
183+
entries.append(cmake_cache_string("CMAKE_CXX_FLAGS", cxxflags))
184+
185+
fflags = " ".join(flags["fflags"])
186+
187+
if fflags:
188+
entries.append(cmake_cache_string("CMAKE_Fortran_FLAGS", fflags))
189+
190+
#### END: Override CachedCMakePackage CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
191+
192+
llnl_link_helpers(entries, spec, compiler)
193+
194+
return entries
195+
196+
197+
def initconfig_hardware_entries(self):
198+
spec = self.spec
199+
compiler = self.compiler
200+
entries = super().initconfig_hardware_entries()
201+
202+
entries.append(cmake_cache_option("ENABLE_OPENMP", "+openmp" in spec))
124203

125204
if "+cuda" in spec:
126-
options.append("-DENABLE_CUDA=ON")
127-
options.append("-DCUDA_TOOLKIT_ROOT_DIR=" + spec["cuda"].prefix)
128-
options.append("-DNVTOOLSEXT_DIR=" + spec["cuda"].prefix)
129-
130-
if spec.satisfies("cuda@:10.2"):
131-
options.append("-DCUB_DIR=" + spec["cub"].prefix)
132-
else:
133-
options.append("-DCUB_DIR=" + spec["cuda"].prefix)
134-
135-
if not spec.satisfies("cuda_arch=none"):
136-
cuda_arch = spec.variants["cuda_arch"].value
137-
# Please note that within care, CUDA_ARCH is assigned to -code
138-
# and likewise CUDA_CODE is assigned to -arch, so these are
139-
# intentionally flipped here.
140-
options.append("-DCUDA_ARCH=sm_{0}".format(cuda_arch[0]))
141-
options.append("-DCUDA_CODE=compute_{0}".format(cuda_arch[0]))
205+
entries.append(cmake_cache_option("ENABLE_CUDA", True))
206+
entries.append(cmake_cache_option("CUDA_SEPARABLE_COMPILATION", True))
207+
entries.append(cmake_cache_string("CUDA_TOOLKIT_ROOT_DIR", spec["cuda"].prefix))
208+
entries.append(cmake_cache_string("CUB_DIR", spec["cub"].prefix))
209+
210+
cuda_for_radiuss_projects(entries, spec)
142211
else:
143-
options.append("-DENABLE_CUDA=OFF")
212+
entries.append(cmake_cache_option("ENABLE_CUDA", False))
144213

145214
if "+rocm" in spec:
146-
options.append("-DENABLE_HIP=ON")
147-
options.append("-DHIP_ROOT_DIR={0}".format(spec["hip"].prefix))
148-
149-
archs = self.spec.variants["amdgpu_target"].value
215+
entries.append(cmake_cache_option("ENABLE_HIP", True))
216+
entries.append(cmake_cache_string("HIP_ROOT_DIR", spec["hip"].prefix))
150217

151-
if archs != "none":
152-
arch_str = ",".join(archs)
153-
options.append("-DHIP_HIPCC_FLAGS=--amdgpu-target={0}".format(arch_str))
218+
hip_for_radiuss_projects(entries, spec, compiler)
154219
else:
155-
options.append("-DENABLE_HIP=OFF")
156-
157-
options.extend(
158-
[
159-
self.define("CAMP_DIR", spec["camp"].prefix),
160-
self.define("UMPIRE_DIR", spec["umpire"].prefix),
161-
self.define("RAJA_DIR", spec["raja"].prefix),
162-
self.define("CHAI_DIR", spec["chai"].prefix)
163-
]
164-
)
220+
entries.append(cmake_cache_option("ENABLE_HIP", False))
165221

166-
options.extend(
167-
[
168-
from_variant("CARE_ENABLE_IMPLICIT_CONVERSIONS", "implicit_conversions"),
169-
from_variant("CARE_ENABLE_LOOP_FUSER", "loop_fuser")
170-
]
171-
)
222+
return entries
172223

173-
# For tests to work, we also need BLT_ENABLE_TESTS to be on.
174-
# This will take care of the gtest dependency. CARE developers should
175-
# consider consolidating these flags in the future.
176-
options.append(from_variant("BLT_ENABLE_TESTS", "tests"))
177224

178-
options.append(from_variant("ENABLE_TESTS", "tests"))
179-
options.append(from_variant("ENABLE_BENCHMARKS", "benchmarks"))
180-
options.append(from_variant("ENABLE_EXAMPLES", "examples"))
181-
options.append(from_variant("ENABLE_DOCS", "docs"))
225+
def initconfig_mpi_entries(self):
226+
spec = self.spec
227+
228+
entries = super(Care, self).initconfig_mpi_entries()
229+
entries.append(cmake_cache_option("ENABLE_MPI", "+mpi" in spec))
182230

183-
if spec.satisfies("@:0.11.1"):
184-
options.append(from_variant("CARE_ENABLE_TESTS", "tests"))
185-
options.append(from_variant("CARE_ENABLE_BENCHMARKS", "benchmarks"))
186-
options.append(from_variant("CARE_ENABLE_EXAMPLES", "examples"))
187-
options.append(from_variant("CARE_ENABLE_DOCS", "docs"))
231+
return entries
188232

233+
234+
def initconfig_package_entries(self):
235+
spec = self.spec
236+
entries = []
237+
238+
# TPL locations
239+
entries.append("#------------------{0}".format("-" * 60))
240+
entries.append("# TPLs")
241+
entries.append("#------------------{0}\n".format("-" * 60))
242+
243+
entries.append(cmake_cache_path("BLT_SOURCE_DIR", spec["blt"].prefix))
244+
entries.append(cmake_cache_path("CAMP_DIR", spec["camp"].prefix))
245+
entries.append(cmake_cache_path("UMPIRE_DIR", spec["umpire"].prefix))
246+
entries.append(cmake_cache_path("RAJA_DIR", spec["raja"].prefix))
247+
entries.append(cmake_cache_path("CHAI_DIR", spec["chai"].prefix))
248+
249+
# Build options
250+
entries.append("#------------------{0}".format("-" * 60))
251+
entries.append("# Build Options")
252+
entries.append("#------------------{0}\n".format("-" * 60))
253+
254+
entries.append(cmake_cache_string(
255+
"CMAKE_BUILD_TYPE", spec.variants["build_type"].value))
256+
257+
entries.append(cmake_cache_option(
258+
"ENABLE_TESTS", "+tests" in spec))
259+
260+
entries.append(cmake_cache_option(
261+
"ENABLE_BENCHMARKS", "+benchmarks" in spec))
262+
263+
entries.append(cmake_cache_option(
264+
"ENABLE_EXAMPLES", "+examples" in spec))
265+
266+
entries.append(cmake_cache_option(
267+
"ENABLE_DOCS", "+docs" in spec))
268+
269+
entries.append(cmake_cache_option(
270+
"CARE_ENABLE_IMPLICIT_CONVERSIONS", "+implicit_conversions" in spec))
271+
272+
entries.append(cmake_cache_option(
273+
"CARE_ENABLE_LOOP_FUSER", "+loop_fuser" in spec))
274+
275+
return entries
276+
277+
278+
def cmake_args(self):
279+
options = []
189280
return options
281+

0 commit comments

Comments
 (0)