1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
|
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
import os
import socket
from os.path import join as pjoin
import llnl.util.tty as tty
def cmake_cache_entry(name, value, comment=""):
"""Generate a string for a cmake cache variable"""
return 'set({0} "{1}" CACHE PATH "{2}")\n\n'.format(name, value, comment)
def cmake_cache_option(name, boolean_value, comment=""):
"""Generate a string for a cmake configuration option"""
value = "ON" if boolean_value else "OFF"
return 'set({0} {1} CACHE BOOL "{2}")\n\n'.format(name, value, comment)
def get_spec_path(spec, package_name, path_replacements={}, use_bin=False):
"""Extracts the prefix path for the given spack package
path_replacements is a dictionary with string replacements for the path.
"""
if not use_bin:
path = spec[package_name].prefix
else:
path = spec[package_name].prefix.bin
path = os.path.realpath(path)
for key in path_replacements:
path = path.replace(key, path_replacements[key])
return path
class Axom(CMakePackage, CudaPackage):
"""Axom provides a robust, flexible software infrastructure for the development
of multi-physics applications and computational tools."""
maintainers = ['white238']
homepage = "https://github.com/LLNL/axom"
git = "https://github.com/LLNL/axom.git"
version('main', branch='main', submodules=True)
version('develop', branch='develop', submodules=True)
version('0.3.3', tag='v0.3.3', submodules="True")
version('0.3.2', tag='v0.3.2', submodules="True")
version('0.3.1', tag='v0.3.1', submodules="True")
version('0.3.0', tag='v0.3.0', submodules="True")
version('0.2.9', tag='v0.2.9', submodules="True")
phases = ["hostconfig", "cmake", "build", "install"]
root_cmakelists_dir = 'src'
# -----------------------------------------------------------------------
# Variants
# -----------------------------------------------------------------------
variant('shared', default=True,
description='Enable build of shared libraries')
variant('debug', default=False,
description='Build debug instead of optimized version')
variant('fortran', default=True, description="Build with Fortran support")
variant("python", default=False, description="Build python support")
variant("mpi", default=True, description="Build MPI support")
variant('openmp', default=True, description='Turn on OpenMP support.')
variant("mfem", default=False, description="Build with mfem")
variant("hdf5", default=True, description="Build with hdf5")
variant("lua", default=True, description="Build with Lua")
variant("scr", default=False, description="Build with SCR")
variant("umpire", default=True, description="Build with umpire")
variant("raja", default=True, description="Build with raja")
variant("cub", default=True,
description="Build with RAJA's internal CUB support")
varmsg = "Build development tools (such as Sphinx, Uncrustify, etc...)"
variant("devtools", default=False, description=varmsg)
# -----------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------
# Basics
depends_on("cmake@3.8.2:", type='build')
depends_on("mpi", when="+mpi")
# Libraries
depends_on("conduit+python", when="+python")
depends_on("conduit~python", when="~python")
depends_on("conduit+hdf5", when="+hdf5")
depends_on("conduit~hdf5", when="~hdf5")
# HDF5 needs to be the same as Conduit's
depends_on("hdf5@1.8.19:1.8.999~mpi~cxx~shared~fortran", when="+hdf5")
depends_on("lua", when="+lua")
depends_on("scr", when="+scr")
depends_on("raja~openmp", when="+raja~openmp")
depends_on("raja+openmp", when="+raja+openmp")
depends_on("raja+cuda", when="+raja+cuda")
depends_on("umpire~openmp", when="+umpire~openmp")
depends_on("umpire+openmp", when="+umpire+openmp")
depends_on("umpire+cuda+deviceconst", when="+umpire+cuda")
for sm_ in CudaPackage.cuda_arch_values:
depends_on('raja cuda_arch={0}'.format(sm_),
when='+raja cuda_arch={0}'.format(sm_))
depends_on('umpire cuda_arch={0}'.format(sm_),
when='+umpire cuda_arch={0}'.format(sm_))
depends_on("mfem~mpi~metis~zlib", when="+mfem")
depends_on("python", when="+python")
# Devtools
depends_on("cppcheck", when="+devtools")
depends_on("doxygen", when="+devtools")
depends_on("graphviz", when="+devtools")
depends_on("python", when="+devtools")
depends_on("py-sphinx", when="+devtools")
depends_on("py-shroud", when="+devtools")
depends_on("uncrustify@0.61", when="+devtools")
def flag_handler(self, name, flags):
if name in ('cflags', 'cxxflags', 'fflags'):
# the package manages these flags in another way
return (None, None, None)
return (flags, None, None)
def _get_sys_type(self, spec):
sys_type = spec.architecture
# if on llnl systems, we can use the SYS_TYPE
if "SYS_TYPE" in env:
sys_type = env["SYS_TYPE"]
return sys_type
def _get_host_config_path(self, spec):
hostname = socket.gethostname()
if "SYS_TYPE" in env:
# Are we on a LLNL system then strip node number
hostname = hostname.rstrip('1234567890')
filename = "{0}-{1}-{2}.cmake".format(hostname,
self._get_sys_type(spec),
spec.compiler)
dest_dir = self.stage.source_path
fullpath = os.path.abspath(pjoin(dest_dir, filename))
return fullpath
def hostconfig(self, spec, prefix):
"""
This method creates a 'host-config' file that specifies
all of the options used to configure and build Axom.
"""
c_compiler = env["SPACK_CC"]
cpp_compiler = env["SPACK_CXX"]
f_compiler = None
# see if we should enable fortran support
if "SPACK_FC" in env.keys():
# even if this is set, it may not exist
# do one more sanity check
if os.path.isfile(env["SPACK_FC"]):
f_compiler = env["SPACK_FC"]
# cmake
if "+cmake" in spec:
cmake_exe = pjoin(spec['cmake'].prefix.bin, "cmake")
else:
cmake_exe = which("cmake")
if cmake_exe is None:
# error could not find cmake!
crash()
cmake_exe = cmake_exe.command
cmake_exe = os.path.realpath(cmake_exe)
host_config_path = self._get_host_config_path(spec)
cfg = open(host_config_path, "w")
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# !!!! This is a generated file, edit at own risk !!!!\n")
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# SYS_TYPE: {0}\n".format(self._get_sys_type(spec)))
cfg.write("# Compiler Spec: {0}\n".format(spec.compiler))
cfg.write("#------------------{0}\n".format("-" * 60))
# show path to cmake for reference and to be used by config-build.py
cfg.write("# CMake executable path: {0}\n".format(cmake_exe))
cfg.write("#------------------{0}\n\n".format("-" * 60))
# compiler settings
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# Compilers\n")
cfg.write("#------------------{0}\n\n".format("-" * 60))
cfg.write(cmake_cache_entry("CMAKE_C_COMPILER", c_compiler))
cfg.write(cmake_cache_entry("CMAKE_CXX_COMPILER", cpp_compiler))
if "+fortran" in spec or f_compiler is not None:
cfg.write(cmake_cache_option("ENABLE_FORTRAN", True))
cfg.write(cmake_cache_entry("CMAKE_Fortran_COMPILER", f_compiler))
else:
cfg.write(cmake_cache_option("ENABLE_FORTRAN", False))
# use global spack compiler flags
cppflags = ' '.join(spec.compiler_flags['cppflags'])
if cppflags:
# avoid always ending up with ' ' with no flags defined
cppflags += ' '
cflags = cppflags + ' '.join(spec.compiler_flags['cflags'])
if cflags:
cfg.write(cmake_cache_entry("CMAKE_C_FLAGS", cflags))
cxxflags = cppflags + ' '.join(spec.compiler_flags['cxxflags'])
if cxxflags:
cfg.write(cmake_cache_entry("CMAKE_CXX_FLAGS", cxxflags))
fflags = ' '.join(spec.compiler_flags['fflags'])
if fflags:
cfg.write(cmake_cache_entry("CMAKE_Fortran_FLAGS", fflags))
if ((f_compiler is not None)
and ("gfortran" in f_compiler)
and ("clang" in cpp_compiler)):
libdir = pjoin(os.path.dirname(
os.path.dirname(cpp_compiler)), "lib")
flags = ""
for _libpath in [libdir, libdir + "64"]:
if os.path.exists(_libpath):
flags += " -Wl,-rpath,{0}".format(_libpath)
description = ("Adds a missing libstdc++ rpath")
if flags:
cfg.write(cmake_cache_entry("BLT_EXE_LINKER_FLAGS", flags,
description))
# TPL locations
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# TPLs\n")
cfg.write("#------------------{0}\n\n".format("-" * 60))
# Try to find the common prefix of the TPL directory, including the
# compiler. If found, we will use this in the TPL paths
compiler_str = str(spec.compiler).replace('@', '-')
prefix_paths = prefix.split(compiler_str)
path_replacements = {}
if len(prefix_paths) == 2:
tpl_root = os.path.realpath(pjoin(prefix_paths[0], compiler_str))
path_replacements[tpl_root] = "${TPL_ROOT}"
cfg.write("# Root directory for generated TPLs\n")
cfg.write(cmake_cache_entry("TPL_ROOT", tpl_root))
conduit_dir = get_spec_path(spec, "conduit", path_replacements)
cfg.write(cmake_cache_entry("CONDUIT_DIR", conduit_dir))
# optional tpls
if "+mfem" in spec:
mfem_dir = get_spec_path(spec, "mfem", path_replacements)
cfg.write(cmake_cache_entry("MFEM_DIR", mfem_dir))
else:
cfg.write("# MFEM not built\n\n")
if "+hdf5" in spec:
hdf5_dir = get_spec_path(spec, "hdf5", path_replacements)
cfg.write(cmake_cache_entry("HDF5_DIR", hdf5_dir))
else:
cfg.write("# HDF5 not built\n\n")
if "+lua" in spec:
lua_dir = get_spec_path(spec, "lua", path_replacements)
cfg.write(cmake_cache_entry("LUA_DIR", lua_dir))
else:
cfg.write("# Lua not built\n\n")
if "+scr" in spec:
scr_dir = get_spec_path(spec, "scr", path_replacements)
cfg.write(cmake_cache_entry("SCR_DIR", scr_dir))
else:
cfg.write("# SCR not built\n\n")
if "+raja" in spec:
raja_dir = get_spec_path(spec, "raja", path_replacements)
cfg.write(cmake_cache_entry("RAJA_DIR", raja_dir))
else:
cfg.write("# RAJA not built\n\n")
if "+umpire" in spec:
umpire_dir = get_spec_path(spec, "umpire", path_replacements)
cfg.write(cmake_cache_entry("UMPIRE_DIR", umpire_dir))
else:
cfg.write("# Umpire not built\n\n")
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# MPI\n")
cfg.write("#------------------{0}\n\n".format("-" * 60))
if "+mpi" in spec:
cfg.write(cmake_cache_option("ENABLE_MPI", True))
cfg.write(cmake_cache_entry("MPI_C_COMPILER", spec['mpi'].mpicc))
cfg.write(cmake_cache_entry("MPI_CXX_COMPILER",
spec['mpi'].mpicxx))
if "+fortran" in spec or f_compiler is not None:
cfg.write(cmake_cache_entry("MPI_Fortran_COMPILER",
spec['mpi'].mpifc))
# Check for slurm
using_slurm = False
slurm_checks = ['+slurm',
'schedulers=slurm',
'process_managers=slurm']
if any(spec['mpi'].satisfies(variant) for variant in slurm_checks):
using_slurm = True
# Determine MPIEXEC
if using_slurm:
if spec['mpi'].external:
mpiexec = '/usr/bin/srun'
else:
mpiexec = os.path.join(spec['slurm'].prefix.bin, 'srun')
else:
mpiexec = os.path.join(spec['mpi'].prefix.bin, 'mpirun')
if not os.path.exists(mpiexec):
mpiexec = os.path.join(spec['mpi'].prefix.bin, 'mpiexec')
if not os.path.exists(mpiexec):
msg = "Unable to determine MPIEXEC, Axom tests may fail"
cfg.write("# {0}\n\n".format(msg))
tty.msg(msg)
else:
# starting with cmake 3.10, FindMPI expects MPIEXEC_EXECUTABLE
# vs the older versions which expect MPIEXEC
if self.spec["cmake"].satisfies('@3.10:'):
cfg.write(cmake_cache_entry("MPIEXEC_EXECUTABLE", mpiexec))
else:
cfg.write(cmake_cache_entry("MPIEXEC", mpiexec))
# Determine MPIEXEC_NUMPROC_FLAG
if using_slurm:
cfg.write(cmake_cache_entry("MPIEXEC_NUMPROC_FLAG", "-n"))
else:
cfg.write(cmake_cache_entry("MPIEXEC_NUMPROC_FLAG", "-np"))
if spec['mpi'].name == 'spectrum-mpi':
cfg.write(cmake_cache_entry("BLT_MPI_COMMAND_APPEND",
"mpibind"))
else:
cfg.write(cmake_cache_option("ENABLE_MPI", False))
##################################
# Devtools
##################################
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# Devtools\n")
cfg.write("#------------------{0}\n\n".format("-" * 60))
# Add common prefix to path replacement list
if "+devtools" in spec:
# Grab common devtools root and strip the trailing slash
path1 = os.path.realpath(spec["uncrustify"].prefix)
path2 = os.path.realpath(spec["doxygen"].prefix)
devtools_root = os.path.commonprefix([path1, path2])[:-1]
path_replacements[devtools_root] = "${DEVTOOLS_ROOT}"
cfg.write("# Root directory for generated developer tools\n")
cfg.write(cmake_cache_entry("DEVTOOLS_ROOT", devtools_root))
if "+python" in spec or "+devtools" in spec:
python_path = os.path.realpath(spec['python'].command.path)
for key in path_replacements:
python_path = python_path.replace(key, path_replacements[key])
cfg.write(cmake_cache_entry("PYTHON_EXECUTABLE", python_path))
if "doxygen" in spec or "py-sphinx" in spec:
cfg.write(cmake_cache_option("ENABLE_DOCS", True))
if "doxygen" in spec:
doxygen_bin_dir = get_spec_path(spec, "doxygen",
path_replacements,
use_bin=True)
cfg.write(cmake_cache_entry("DOXYGEN_EXECUTABLE",
pjoin(doxygen_bin_dir,
"doxygen")))
if "py-sphinx" in spec:
python_bin_dir = get_spec_path(spec, "python",
path_replacements,
use_bin=True)
cfg.write(cmake_cache_entry("SPHINX_EXECUTABLE",
pjoin(python_bin_dir,
"sphinx-build")))
else:
cfg.write(cmake_cache_option("ENABLE_DOCS", False))
if "py-shroud" in spec:
shroud_bin_dir = get_spec_path(spec, "py-shroud",
path_replacements, use_bin=True)
cfg.write(cmake_cache_entry("SHROUD_EXECUTABLE",
pjoin(shroud_bin_dir, "shroud")))
if "uncrustify" in spec:
uncrustify_bin_dir = get_spec_path(spec, "uncrustify",
path_replacements,
use_bin=True)
cfg.write(cmake_cache_entry("UNCRUSTIFY_EXECUTABLE",
pjoin(uncrustify_bin_dir,
"uncrustify")))
if "cppcheck" in spec:
cppcheck_bin_dir = get_spec_path(spec, "cppcheck",
path_replacements, use_bin=True)
cfg.write(cmake_cache_entry("CPPCHECK_EXECUTABLE",
pjoin(cppcheck_bin_dir, "cppcheck")))
##################################
# Other machine specifics
##################################
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# Other machine specifics\n")
cfg.write("#------------------{0}\n\n".format("-" * 60))
# OpenMP
if "+openmp" in spec:
cfg.write(cmake_cache_option("ENABLE_OPENMP", True))
else:
cfg.write(cmake_cache_option("ENABLE_OPENMP", False))
# Enable death tests
if spec.satisfies('target=ppc64le:') and "+cuda" in spec:
cfg.write(cmake_cache_option("ENABLE_GTEST_DEATH_TESTS", False))
else:
cfg.write(cmake_cache_option("ENABLE_GTEST_DEATH_TESTS", True))
# Override XL compiler family
familymsg = ("Override to proper compiler family for XL")
if (f_compiler is not None) and ("xlf" in f_compiler):
cfg.write(cmake_cache_entry("CMAKE_Fortran_COMPILER_ID", "XL",
familymsg))
if "xlc" in c_compiler:
cfg.write(cmake_cache_entry("CMAKE_C_COMPILER_ID", "XL",
familymsg))
if "xlC" in cpp_compiler:
cfg.write(cmake_cache_entry("CMAKE_CXX_COMPILER_ID", "XL",
familymsg))
if spec.satisfies('target=ppc64le:'):
if (f_compiler is not None) and ("xlf" in f_compiler):
description = ("Converts C-style comments to Fortran style "
"in preprocessed files")
cfg.write(cmake_cache_entry("BLT_FORTRAN_FLAGS",
"-WF,-C! -qxlf2003=polymorphic",
description))
# Grab lib directory for the current fortran compiler
libdir = os.path.join(os.path.dirname(
os.path.dirname(f_compiler)), "lib")
description = ("Adds a missing rpath for libraries "
"associated with the fortran compiler")
linker_flags = "${BLT_EXE_LINKER_FLAGS} -Wl,-rpath," + libdir
cfg.write(cmake_cache_entry("BLT_EXE_LINKER_FLAGS",
linker_flags, description))
if "+shared" in spec:
linker_flags = "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath," \
+ libdir
cfg.write(cmake_cache_entry("CMAKE_SHARED_LINKER_FLAGS",
linker_flags, description))
if "+cuda" in spec:
cfg.write("#------------------{0}\n".format("-" * 60))
cfg.write("# Cuda\n")
cfg.write("#------------------{0}\n\n".format("-" * 60))
cfg.write(cmake_cache_option("ENABLE_CUDA", True))
cudatoolkitdir = spec['cuda'].prefix
cfg.write(cmake_cache_entry("CUDA_TOOLKIT_ROOT_DIR",
cudatoolkitdir))
cudacompiler = "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc"
cfg.write(cmake_cache_entry("CMAKE_CUDA_COMPILER",
cudacompiler))
cfg.write(cmake_cache_option("CUDA_SEPARABLE_COMPILATION",
True))
cfg.write(cmake_cache_option("AXOM_ENABLE_ANNOTATIONS", True))
if "+cub" in spec:
cfg.write(cmake_cache_option("AXOM_ENABLE_CUB", True))
else:
cfg.write(cmake_cache_option("AXOM_ENABLE_CUB", False))
# CUDA_FLAGS
cudaflags = "-restrict "
if not spec.satisfies('cuda_arch=none'):
cuda_arch = spec.variants['cuda_arch'].value
axom_arch = 'sm_{0}'.format(cuda_arch[0])
cfg.write(cmake_cache_entry("AXOM_CUDA_ARCH", axom_arch))
cudaflags += "-arch ${AXOM_CUDA_ARCH} "
else:
cfg.write("# cuda_arch could not be determined\n\n")
cudaflags += "-std=c++11 --expt-extended-lambda -G "
cfg.write(cmake_cache_entry("CMAKE_CUDA_FLAGS", cudaflags))
if "+mpi" in spec:
cfg.write(cmake_cache_entry("CMAKE_CUDA_HOST_COMPILER",
"${MPI_CXX_COMPILER}"))
else:
cfg.write(cmake_cache_entry("CMAKE_CUDA_HOST_COMPILER",
"${CMAKE_CXX_COMPILER}"))
cfg.write("# nvcc does not like gtest's 'pthreads' flag\n")
cfg.write(cmake_cache_option("gtest_disable_pthreads", True))
cfg.write("\n")
cfg.close()
tty.info("Spack generated Axom host-config file: " + host_config_path)
def cmake_args(self):
spec = self.spec
host_config_path = self._get_host_config_path(spec)
options = []
options.extend(['-C', host_config_path])
if self.run_tests is False:
options.append('-DENABLE_TESTS=OFF')
else:
options.append('-DENABLE_TESTS=ON')
if "+shared" in spec:
options.append('-DBUILD_SHARED_LIBS=ON')
else:
options.append('-DBUILD_SHARED_LIBS=OFF')
return options
@run_after('install')
def install_cmake_cache(self):
install(self._get_host_config_path(self.spec), prefix)
|