diff options
-rw-r--r-- | var/spack/repos/builtin/packages/camp/package.py | 30 | ||||
-rw-r--r-- | var/spack/repos/builtin/packages/hip/package.py | 46 |
2 files changed, 70 insertions, 6 deletions
diff --git a/var/spack/repos/builtin/packages/camp/package.py b/var/spack/repos/builtin/packages/camp/package.py index e9ea3ac8be..67285e9742 100644 --- a/var/spack/repos/builtin/packages/camp/package.py +++ b/var/spack/repos/builtin/packages/camp/package.py @@ -22,6 +22,27 @@ class Camp(CMakePackage, CudaPackage): depends_on('cmake@3.8:', type='build') depends_on('cmake@3.9:', type='build', when="+cuda") + variant('hip', default=False, description='Enable HIP support') + + # possible amd gpu targets for hip builds + # TODO: we should add a hip build system description equivalent to + # lib/spack/spack/build_systems/cuda.py, where possible hip amd gpu + # architectures are defined in a similar way as for cuda gpu + # architectures. In the meantime, require users to define + # amd gpu type for hip builds with a variant here. + amdgpu_targets = ( + 'gfx701', 'gfx801', 'gfx802', 'gfx803', + 'gfx900', 'gfx906', 'gfx908', 'gfx1010', + 'gfx1011', 'gfx1012', 'none' + ) + variant('amdgpu_target', default='none', values=amdgpu_targets) + + depends_on('llvm-amdgpu', when='+hip') + depends_on('hip', when='+hip') + + # need amd gpu type for hip builds + conflicts('amdgpu_target=none', when='+hip') + def cmake_args(self): spec = self.spec @@ -40,6 +61,15 @@ class Camp(CMakePackage, CudaPackage): else: options.append('-DENABLE_CUDA=OFF') + if '+hip' in spec: + arch = self.spec.variants['amdgpu_target'].value + options.extend([ + '-DENABLE_HIP=ON', + '-DHIP_ROOT_DIR={0}'.format(spec['hip'].prefix), + '-DHIP_HCC_FLAGS=--amdgpu-target={0}'.format(arch)]) + else: + options.append('-DENABLE_HIP=OFF') + options.append('-DENABLE_TESTS={0}'.format( "On" if self.run_tests else "Off")) diff --git a/var/spack/repos/builtin/packages/hip/package.py b/var/spack/repos/builtin/packages/hip/package.py index e1893341bf..7b93dcfda2 100644 --- a/var/spack/repos/builtin/packages/hip/package.py +++ b/var/spack/repos/builtin/packages/hip/package.py @@ -3,8 +3,8 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) - -from spack import * +from spack.util.prefix import Prefix +import os class Hip(CMakePackage): @@ -48,14 +48,48 @@ class Hip(CMakePackage): # See https://github.com/ROCm-Developer-Tools/HIP/pull/2141 patch('0002-Fix-detection-of-HIP_CLANG_ROOT.patch', when='@3.5.0:') + def get_rocm_prefix_info(self): + # External packages in Spack do not currently contain dependency + # information. External installations of hip therefore must compute + # necessary paths to other rocm components by relative paths. This + # assumes all components are installed under a single umbrella + # directory. Manual edits to `fallback_path` may be necessary if this + # assumption does not hold. + if self.spec.external: + # typically, self.spec.prefix is /opt/rocm/hip, so fallback_path + # will be /opt/rocm. The rocminfo executable is usually + # found at /opt/rocm/bin/rocminfo. + fallback_prefix = Prefix(os.path.dirname(self.spec.prefix)) + if not os.path.isdir(fallback_prefix): + msg = "Could not determine prefix for other rocm components\n" + msg += "Either report a bug at github.com/spack/spack or " + msg += "manually edit fallback_prefix in the package file as " + msg += "a workaround." + raise RuntimeError(msg) + + return { + 'llvm-amdgpu': fallback_prefix.llvm, + 'hsa-rocr-dev': fallback_prefix.hsa, + 'rocminfo': fallback_prefix.bin, + 'rocm-device-libs': fallback_prefix, + } + else: + return dict((name, self.spec[name].prefix) + for name in ('llvm-amdgpu', 'hsa-rocr-dev', 'rocminfo', + 'rocm-device-libs')) + def setup_dependent_build_environment(self, env, dependent_spec): + # Indirection for dependency paths because hip may be an external in + # Spack. See block comment on get_rocm_prefix_info + rocm_prefixes = self.get_rocm_prefix_info() + env.set('ROCM_PATH', '') env.set('HIP_COMPILER', 'clang') env.set('HIP_PLATFORM', 'hcc') - env.set('HIP_CLANG_PATH', self.spec['llvm-amdgpu'].prefix.bin) - env.set('HSA_PATH', self.spec['hsa-rocr-dev'].prefix) - env.set('ROCMINFO_PATH', self.spec['rocminfo'].prefix) - env.set('DEVICE_LIB_PATH', self.spec['rocm-device-libs'].prefix.lib) + env.set('HIP_CLANG_PATH', rocm_prefixes['llvm-amdgpu'].bin) + env.set('HSA_PATH', rocm_prefixes['hsa-rocr-dev']) + env.set('ROCMINFO_PATH', rocm_prefixes['rocminfo']) + env.set('DEVICE_LIB_PATH', rocm_prefixes['rocm-device-libs'].lib) def setup_dependent_package(self, module, dependent_spec): self.spec.hipcc = join_path(self.prefix.bin, 'hipcc') |