From e2b87ade06722d304864d5ed26b68d0ccf30faa9 Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Thu, 3 Mar 2022 13:34:22 -0800 Subject: rocmcc compiler: initial commit based on aocc and clang (#28575) * rocmcc compiler: initial commit based on aocc and clang Co-authored-by: luker Co-authored-by: Tom Scogland --- lib/spack/env/cc | 8 ++-- lib/spack/env/rocmcc/amdclang | 1 + lib/spack/env/rocmcc/amdclang++ | 1 + lib/spack/env/rocmcc/amdflang | 1 + lib/spack/spack/compilers/__init__.py | 3 +- lib/spack/spack/compilers/rocmcc.py | 78 +++++++++++++++++++++++++++++++++++ lib/spack/spack/modules/lmod.py | 4 ++ 7 files changed, 91 insertions(+), 5 deletions(-) create mode 120000 lib/spack/env/rocmcc/amdclang create mode 120000 lib/spack/env/rocmcc/amdclang++ create mode 120000 lib/spack/env/rocmcc/amdflang create mode 100644 lib/spack/spack/compilers/rocmcc.py diff --git a/lib/spack/env/cc b/lib/spack/env/cc index fecc2d5327..1a52f2c612 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -241,28 +241,28 @@ case "$command" in mode=cpp debug_flags="-g" ;; - cc|c89|c99|gcc|clang|armclang|icc|icx|pgcc|nvc|xlc|xlc_r|fcc) + cc|c89|c99|gcc|clang|armclang|icc|icx|pgcc|nvc|xlc|xlc_r|fcc|amdclang) command="$SPACK_CC" language="C" comp="CC" lang_flags=C debug_flags="-g" ;; - c++|CC|g++|clang++|armclang++|icpc|icpx|dpcpp|pgc++|nvc++|xlc++|xlc++_r|FCC) + c++|CC|g++|clang++|armclang++|icpc|icpx|dpcpp|pgc++|nvc++|xlc++|xlc++_r|FCC|amdclang++) command="$SPACK_CXX" language="C++" comp="CXX" lang_flags=CXX debug_flags="-g" ;; - ftn|f90|fc|f95|gfortran|flang|armflang|ifort|ifx|pgfortran|nvfortran|xlf90|xlf90_r|nagfor|frt) + ftn|f90|fc|f95|gfortran|flang|armflang|ifort|ifx|pgfortran|nvfortran|xlf90|xlf90_r|nagfor|frt|amdflang) command="$SPACK_FC" language="Fortran 90" comp="FC" lang_flags=F debug_flags="-g" ;; - f77|xlf|xlf_r|pgf77) + f77|xlf|xlf_r|pgf77|amdflang) command="$SPACK_F77" language="Fortran 77" comp="F77" diff --git a/lib/spack/env/rocmcc/amdclang b/lib/spack/env/rocmcc/amdclang new file mode 120000 index 0000000000..82c2b8e90a --- /dev/null +++ b/lib/spack/env/rocmcc/amdclang @@ -0,0 +1 @@ +../cc \ No newline at end of file diff --git a/lib/spack/env/rocmcc/amdclang++ b/lib/spack/env/rocmcc/amdclang++ new file mode 120000 index 0000000000..abf4cd45c7 --- /dev/null +++ b/lib/spack/env/rocmcc/amdclang++ @@ -0,0 +1 @@ +../cpp \ No newline at end of file diff --git a/lib/spack/env/rocmcc/amdflang b/lib/spack/env/rocmcc/amdflang new file mode 120000 index 0000000000..b6c64233b0 --- /dev/null +++ b/lib/spack/env/rocmcc/amdflang @@ -0,0 +1 @@ +../fc \ No newline at end of file diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py index f56222d24f..5aad6b2b98 100644 --- a/lib/spack/spack/compilers/__init__.py +++ b/lib/spack/spack/compilers/__init__.py @@ -42,7 +42,8 @@ _compiler_cache = {} # type: Dict[str, spack.compiler.Compiler] _compiler_to_pkg = { 'clang': 'llvm+clang', - 'oneapi': 'intel-oneapi-compilers' + 'oneapi': 'intel-oneapi-compilers', + 'rocmcc': 'llvm-amdgpu' } diff --git a/lib/spack/spack/compilers/rocmcc.py b/lib/spack/spack/compilers/rocmcc.py new file mode 100644 index 0000000000..9cb11be869 --- /dev/null +++ b/lib/spack/spack/compilers/rocmcc.py @@ -0,0 +1,78 @@ +# Copyright 2013-2022 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) + +import re + +import llnl.util.lang + +import spack.compilers.clang + + +class Rocmcc(spack.compilers.clang.Clang): + # Subclasses use possible names of C compiler + cc_names = ['amdclang'] + + # Subclasses use possible names of C++ compiler + cxx_names = ['amdclang++'] + + # Subclasses use possible names of Fortran 77 compiler + f77_names = ['amdflang'] + + # Subclasses use possible names of Fortran 90 compiler + fc_names = ['amdflang'] + + PrgEnv = 'PrgEnv-amd' + PrgEnv_compiler = 'amd' + + @property + def link_paths(self): + link_paths = {'cc': 'rocmcc/amdclang', + 'cxx': 'rocmcc/amdclang++', + 'f77': 'rocmcc/amdflang', + 'fc': 'rocmcc/amdflang'} + + return link_paths + + @property + def cxx11_flag(self): + return "-std=c++11" + + @property + def cxx14_flag(self): + return "-std=c++14" + + @property + def cxx17_flag(self): + return "-std=c++17" + + @property + def c99_flag(self): + return '-std=c99' + + @property + def c11_flag(self): + return "-std=c11" + + @classmethod + @llnl.util.lang.memoized + def extract_version_from_output(cls, output): + match = re.search( + r'llvm-project roc-(\d+)[._](\d+)[._](\d+)', + output + ) + if match: + return '.'.join(match.groups()) + + @classmethod + def fc_version(cls, fortran_compiler): + return cls.default_version(fortran_compiler) + + @classmethod + def f77_version(cls, f77): + return cls.fc_version(f77) + + @property + def stdcxx_libs(self): + return ('-lstdc++', ) diff --git a/lib/spack/spack/modules/lmod.py b/lib/spack/spack/modules/lmod.py index e29992767e..0111f43229 100644 --- a/lib/spack/spack/modules/lmod.py +++ b/lib/spack/spack/modules/lmod.py @@ -188,6 +188,10 @@ class LmodConfiguration(BaseConfiguration): if self.spec.name == 'llvm': provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) provides['compiler'].name = 'clang' + # Special case for llvm-amdgpu + if self.spec.name == 'llvm-amdgpu': + provides['compiler'] = spack.spec.CompilerSpec(str(self.spec)) + provides['compiler'].name = 'rocmcc' # All the other tokens in the hierarchy must be virtual dependencies for x in self.hierarchy_tokens: -- cgit v1.2.3-70-g09d2