In recent releases some ROCm packages switched from hipcc to clang++
(as hipcc is now mostly a simple wrapper that calls clang++).
New rocm_use_clang function allows to switch compiler to HIP-compatible clang.

Both hipcc and clang reject some flags when compiling *.hip files;
to clean incompatible CXXFLAGS new test-flags-HIPCXX function is used.

Bug: https://bugs.gentoo.org/957893
Signed-off-by: Sv. Lockal <[email protected]>
---
 eclass/rocm.eclass | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 65726a0bc621..a7601bf43f2d 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -246,6 +246,18 @@ check_amdgpu() {

 fi

+# @FUNCTION: _rocm_strip_unsupported_flags
+# @INTERNAL
+# @DESCRIPTION:
+# Clean flags that are not compatible with 'amdgcn-amd-amdhsa' target.
+_rocm_strip_unsupported_flags() {
+   strip-unsupported-flags
+
+   # FLAGS like -mtls-dialect=* pass test-flags-CXX check, but are
not supported
+   # bug #957893
+   export CXXFLAGS=$(test-flags-HIPCXX ${CXXFLAGS})
+}
+
 # @FUNCTION: rocm_use_hipcc
 # @USAGE: rocm_use_hipcc
 # @DESCRIPTION:
@@ -267,5 +279,20 @@ rocm_use_hipcc() {
    # Export updated CC and CXX. Note that CC is needed even if no C code used,
    # as CMake checks that C compiler can compile a simple test program.
    export CC=hipcc CXX=hipcc
-   strip-unsupported-flags
+   _rocm_strip_unsupported_flags
+}
+
+# @FUNCTION: rocm_use_clang
+# @USAGE: rocm_use_clang
+# @DESCRIPTION:
+# switch active C and C++ compilers to clang/clang++, clean unsupported flags
+rocm_use_clang() {
+   local hipclangpath
+   if ! hipclangpath=$(hipconfig --hipclangpath); then
+        die "Error: \"hipconfig --hipclangpath\" failed"
+    fi
+
+   export CC="${hipclangpath}/${CHOST}-clang"
+   export CXX="${hipclangpath}/${CHOST}-clang++"
+   _rocm_strip_unsupported_flags
 }
-- 
2.50.0

Reply via email to