Kokkos package: rocm support (#21157)
This commit is contained in:
parent
7bed6a7077
commit
fd8d14f7c5
1 changed files with 37 additions and 23 deletions
|
@ -5,7 +5,7 @@
|
||||||
from spack import *
|
from spack import *
|
||||||
|
|
||||||
|
|
||||||
class Kokkos(CMakePackage, CudaPackage):
|
class Kokkos(CMakePackage, CudaPackage, ROCmPackage):
|
||||||
"""Kokkos implements a programming model in C++ for writing performance
|
"""Kokkos implements a programming model in C++ for writing performance
|
||||||
portable applications targeting all major HPC platforms."""
|
portable applications targeting all major HPC platforms."""
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ class Kokkos(CMakePackage, CudaPackage):
|
||||||
'openmp': [False, 'Whether to build OpenMP backend'],
|
'openmp': [False, 'Whether to build OpenMP backend'],
|
||||||
'pthread': [False, 'Whether to build Pthread backend'],
|
'pthread': [False, 'Whether to build Pthread backend'],
|
||||||
'serial': [True, 'Whether to build serial backend'],
|
'serial': [True, 'Whether to build serial backend'],
|
||||||
'hip': [False, 'Whether to build HIP backend'],
|
'rocm': [False, 'Whether to build HIP backend'],
|
||||||
}
|
}
|
||||||
conflicts("+hip", when="@:3.0")
|
conflicts("+rocm", when="@:3.0")
|
||||||
|
|
||||||
tpls_variants = {
|
tpls_variants = {
|
||||||
'hpx': [False, 'Whether to enable the HPX library'],
|
'hpx': [False, 'Whether to enable the HPX library'],
|
||||||
|
@ -72,15 +72,6 @@ class Kokkos(CMakePackage, CudaPackage):
|
||||||
'tests': [False, 'Build for tests'],
|
'tests': [False, 'Build for tests'],
|
||||||
}
|
}
|
||||||
|
|
||||||
amd_gpu_arches = (
|
|
||||||
'vega900',
|
|
||||||
'vega906',
|
|
||||||
'vega908',
|
|
||||||
)
|
|
||||||
variant("amd_gpu_arch", default='none', values=('none',) + amd_gpu_arches,
|
|
||||||
description="AMD GPU architecture")
|
|
||||||
conflicts("+hip", when="amd_gpu_arch=none")
|
|
||||||
|
|
||||||
spack_micro_arch_map = {
|
spack_micro_arch_map = {
|
||||||
"graviton": "",
|
"graviton": "",
|
||||||
"graviton2": "",
|
"graviton2": "",
|
||||||
|
@ -151,6 +142,20 @@ class Kokkos(CMakePackage, CudaPackage):
|
||||||
cuda_arches = spack_cuda_arch_map.values()
|
cuda_arches = spack_cuda_arch_map.values()
|
||||||
conflicts("+cuda", when="cuda_arch=none")
|
conflicts("+cuda", when="cuda_arch=none")
|
||||||
|
|
||||||
|
amdgpu_arch_map = {
|
||||||
|
'gfx900': 'vega900',
|
||||||
|
'gfx906': 'vega906',
|
||||||
|
'gfx908': 'vega908'
|
||||||
|
}
|
||||||
|
amd_support_conflict_msg = (
|
||||||
|
'{0} is not supported; '
|
||||||
|
'Kokkos supports the following AMD GPU targets: '
|
||||||
|
+ ', '.join(amdgpu_arch_map.keys()))
|
||||||
|
for arch in ROCmPackage.amdgpu_targets:
|
||||||
|
if arch not in amdgpu_arch_map:
|
||||||
|
conflicts('+rocm', when='amdgpu_target={0}'.format(arch),
|
||||||
|
msg=amd_support_conflict_msg.format(arch))
|
||||||
|
|
||||||
devices_values = list(devices_variants.keys())
|
devices_values = list(devices_variants.keys())
|
||||||
for dev in devices_variants:
|
for dev in devices_variants:
|
||||||
dflt, desc = devices_variants[dev]
|
dflt, desc = devices_variants[dev]
|
||||||
|
@ -187,8 +192,10 @@ class Kokkos(CMakePackage, CudaPackage):
|
||||||
variant('shared', default=True, description='Build shared libraries')
|
variant('shared', default=True, description='Build shared libraries')
|
||||||
|
|
||||||
def append_args(self, cmake_prefix, cmake_options, spack_options):
|
def append_args(self, cmake_prefix, cmake_options, spack_options):
|
||||||
for opt in cmake_options:
|
variant_to_cmake_option = {'rocm': 'hip'}
|
||||||
enablestr = "+%s" % opt
|
for variant_name in cmake_options:
|
||||||
|
enablestr = "+%s" % variant_name
|
||||||
|
opt = variant_to_cmake_option.get(variant_name, variant_name)
|
||||||
optuc = opt.upper()
|
optuc = opt.upper()
|
||||||
optname = "Kokkos_%s_%s" % (cmake_prefix, optuc)
|
optname = "Kokkos_%s_%s" % (cmake_prefix, optuc)
|
||||||
option = None
|
option = None
|
||||||
|
@ -226,14 +233,22 @@ def cmake_args(self):
|
||||||
if not cuda_arch == "none":
|
if not cuda_arch == "none":
|
||||||
kokkos_arch_name = self.spack_cuda_arch_map[cuda_arch]
|
kokkos_arch_name = self.spack_cuda_arch_map[cuda_arch]
|
||||||
spack_microarches.append(kokkos_arch_name)
|
spack_microarches.append(kokkos_arch_name)
|
||||||
|
|
||||||
kokkos_microarch_name = self.spack_micro_arch_map[spec.target.name]
|
kokkos_microarch_name = self.spack_micro_arch_map[spec.target.name]
|
||||||
if kokkos_microarch_name:
|
if kokkos_microarch_name:
|
||||||
spack_microarches.append(kokkos_microarch_name)
|
spack_microarches.append(kokkos_microarch_name)
|
||||||
|
|
||||||
for arch in self.amd_gpu_arches:
|
if "+rocm" in spec:
|
||||||
keyval = "amd_gpu_arch=%s" % arch
|
for amdgpu_target in spec.variants['amdgpu_target'].value:
|
||||||
if keyval in spec:
|
if amdgpu_target != "none":
|
||||||
spack_microarches.append(arch)
|
if amdgpu_target in self.amdgpu_arch_map:
|
||||||
|
spack_microarches.append(
|
||||||
|
self.amdgpu_arch_map[amdgpu_target])
|
||||||
|
else:
|
||||||
|
# Note that conflict declarations should prevent
|
||||||
|
# choosing an unsupported AMD GPU target
|
||||||
|
raise SpackError("Unsupported target: {0}".format(
|
||||||
|
amdgpu_target))
|
||||||
|
|
||||||
for arch in spack_microarches:
|
for arch in spack_microarches:
|
||||||
options.append("-DKokkos_ARCH_%s=ON" % arch.upper())
|
options.append("-DKokkos_ARCH_%s=ON" % arch.upper())
|
||||||
|
@ -247,13 +262,12 @@ def cmake_args(self):
|
||||||
if var in self.spec:
|
if var in self.spec:
|
||||||
options.append("-D%s_DIR=%s" % (tpl, spec[tpl].prefix))
|
options.append("-D%s_DIR=%s" % (tpl, spec[tpl].prefix))
|
||||||
|
|
||||||
# we do not need the compiler wrapper from Spack
|
if '+rocm' in self.spec:
|
||||||
# set the compiler explicitly (may be Spack wrapper or nvcc-wrapper)
|
options.append('-DCMAKE_CXX_COMPILER=%s' %
|
||||||
try:
|
self.spec['hip'].hipcc)
|
||||||
|
elif '+wrapper' in self.spec:
|
||||||
options.append("-DCMAKE_CXX_COMPILER=%s" %
|
options.append("-DCMAKE_CXX_COMPILER=%s" %
|
||||||
self.spec["kokkos-nvcc-wrapper"].kokkos_cxx)
|
self.spec["kokkos-nvcc-wrapper"].kokkos_cxx)
|
||||||
except Exception:
|
|
||||||
options.append("-DCMAKE_CXX_COMPILER=%s" % spack_cxx)
|
|
||||||
|
|
||||||
# Set the C++ standard to use
|
# Set the C++ standard to use
|
||||||
options.append("-DKokkos_CXX_STANDARD=%s" %
|
options.append("-DKokkos_CXX_STANDARD=%s" %
|
||||||
|
|
Loading…
Reference in a new issue