kokkos: refactor defines to use helper functions (#27189)

This commit is contained in:
Seth R. Johnson 2021-11-04 04:31:29 -04:00 committed by GitHub
parent 6a7b07c60b
commit 503576c017
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -175,6 +175,7 @@ class Kokkos(CMakePackage, CudaPackage, ROCmPackage):
conflicts("+wrapper", when="~cuda")
stds = ["11", "14", "17", "20"]
# TODO: This should be named cxxstd for consistency with other packages
variant("std", default="14", values=stds, multi=False)
variant("pic", default=False, description="Build position independent code")
@ -208,18 +209,10 @@ def get_microarch(cls, target):
def append_args(self, cmake_prefix, cmake_options, spack_options):
variant_to_cmake_option = {'rocm': 'hip'}
for variant_name in cmake_options:
enablestr = "+%s" % variant_name
opt = variant_to_cmake_option.get(variant_name, variant_name)
optuc = opt.upper()
optname = "Kokkos_%s_%s" % (cmake_prefix, optuc)
option = None
if enablestr in self.spec:
option = "-D%s=ON" % optname
else:
# explicitly turn off if not enabled
# this avoids any confusing implicit defaults
# that come from the CMake
option = "-D%s=OFF" % optname
optname = "Kokkos_%s_%s" % (cmake_prefix, opt.upper())
# Explicitly enable or disable
option = self.define_from_variant(optname, variant_name)
if option not in spack_options:
spack_options.append(option)
@ -231,6 +224,7 @@ def setup_dependent_package(self, module, dependent_spec):
def cmake_args(self):
spec = self.spec
from_variant = self.define_from_variant
if spec.satisfies("~wrapper+cuda") and not (
spec.satisfies("%clang") or spec.satisfies("%cce")
@ -238,14 +232,11 @@ def cmake_args(self):
raise InstallError("Kokkos requires +wrapper when using +cuda"
"without clang")
options = []
isdiy = "+diy" in spec
if isdiy:
options.append("-DSpack_WORKAROUND=On")
if "+pic" in spec:
options.append("-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
options = [
from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
from_variant("Kokkos_CXX_STANDARD", "std"),
from_variant("BUILD_SHARED_LIBS", "shared"),
]
spack_microarches = []
if "+cuda" in spec:
@ -272,29 +263,24 @@ def cmake_args(self):
amdgpu_target))
for arch in spack_microarches:
options.append("-DKokkos_ARCH_%s=ON" % arch.upper())
options.append(self.define("Kokkos_ARCH_" + arch.upper(), True))
self.append_args("ENABLE", self.devices_values, options)
self.append_args("ENABLE", self.options_values, options)
self.append_args("ENABLE", self.tpls_values, options)
for tpl in self.tpls_values:
var = "+%s" % tpl
if var in self.spec:
options.append("-D%s_DIR=%s" % (tpl, spec[tpl].prefix))
if spec.variants[tpl].value:
options.append(self.define(tpl + "_DIR", spec[tpl].prefix))
if '+rocm' in self.spec:
options.append('-DCMAKE_CXX_COMPILER=%s' %
self.spec['hip'].hipcc)
options.append(self.define(
'CMAKE_CXX_COMPILER', self.spec['hip'].hipcc))
elif '+wrapper' in self.spec:
options.append("-DCMAKE_CXX_COMPILER=%s" %
self.spec["kokkos-nvcc-wrapper"].kokkos_cxx)
# Set the C++ standard to use
options.append("-DKokkos_CXX_STANDARD=%s" %
self.spec.variants["std"].value)
options.append('-DBUILD_SHARED_LIBS=%s' % ('+shared' in self.spec))
options.append(self.define(
"CMAKE_CXX_COMPILER",
self.spec["kokkos-nvcc-wrapper"].kokkos_cxx
))
return options