* [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function
@ 2025-06-22 16:29 Sv. Lockal
2025-06-22 16:31 ` [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: Add functions for testing/stripping HIPFLAGS Sv. Lockal
2025-07-05 7:15 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function Sam James
0 siblings, 2 replies; 4+ messages in thread
From: Sv. Lockal @ 2025-06-22 16:29 UTC (permalink / raw
To: gentoo-dev
This allows to find compiler for HIP language files.
Environment variable HIPCXX is used by CMake[1].
In recent releases of CMake, it strictly requires clang++, not hipcc.
When not defined, CMake uses multiple methods to find HIP compiler,
hipconfig is one of them[2].
[1] https://cmake.org/cmake/help/latest/envvar/HIPCXX.html
[2] https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeDetermineHIPCompiler.cmake
Bug: https://bugs.gentoo.org/957893
Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
---
eclass/toolchain-funcs.eclass | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index baf032bbd4ec..1f3f958badee 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -73,6 +73,10 @@ tc-getCPP() { tc-getPROG CPP "${CC:-gcc} -E" "$@"; }
# @USAGE: [toolchain prefix]
# @RETURN: name of the C++ compiler
tc-getCXX() { tc-getPROG CXX g++ "$@"; }
+# @FUNCTION: tc-getHIPCXX
+# @USAGE: [toolchain prefix]
+# @RETURN: name of the HIP compiler
+tc-getHIPCXX() { tc-getPROG HIPCXX "$(hipconfig
--hipclangpath)/clang++" "$@"; }
# @FUNCTION: tc-getLD
# @USAGE: [toolchain prefix]
# @RETURN: name of the linker
--
2.50.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: Add functions for testing/stripping HIPFLAGS
2025-06-22 16:29 [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function Sv. Lockal
@ 2025-06-22 16:31 ` Sv. Lockal
2025-06-22 16:32 ` [gentoo-dev] [PATCH 3/3] rocm.eclass: add rocm_use_clang and strip flags in a better way Sv. Lockal
2025-07-05 7:15 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function Sam James
1 sibling, 1 reply; 4+ messages in thread
From: Sv. Lockal @ 2025-06-22 16:31 UTC (permalink / raw
To: gentoo-dev
HIPFLAFS allows to specify default compilation flags to be used when
compiling HIP files.
As environment variable, it is supported in CMake for all projects
that specify HIP as language[1][2].
Some flags like -mtls-dialect=* are not supported by HIP compiler;
test-flags-HIPCXX can be used to test flags.
[1] https://cmake.org/cmake/help/latest/envvar/HIPFLAGS.html
[2] https://rocm.docs.amd.com/en/latest/conceptual/cmake-packages.html#using-the-hip-single-source-programming-model
Bug: https://bugs.gentoo.org/957893
Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
---
eclass/flag-o-matic.eclass | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
index f22854c646c7..1c9abe1280b6 100644
--- a/eclass/flag-o-matic.eclass
+++ b/eclass/flag-o-matic.eclass
@@ -636,6 +636,11 @@ _test-flag-PROG() {
cmdline_extra+=(-xc)
;;
+ hip)
+ in_ext='hip'
+ in_src='int main(void) { return 0; }'
+ cmdline_extra+=(-xhip -c)
+ ;;
esac
local test_in=${T}/test-flag.${in_ext}
local test_out=${T}/test-flag.exe
@@ -707,6 +712,12 @@ test-flag-FC() { _test-flag-PROG FC f95 "$@"; }
# Returns shell true if <flag> is supported by the C compiler and
linker, else returns shell false.
test-flag-CCLD() { _test-flag-PROG CC c+ld "$@"; }
+# @FUNCTION: test-flag-HIPCXX
+# @USAGE: <flag>
+# @DESCRIPTION:
+# Returns shell true if <flag> is supported by the HIP compiler, else
returns shell false.
+test-flag-HIPCXX() { _test-flag-PROG HIPCXX hip "$@"; }
+
# @FUNCTION: test-flags-PROG
# @USAGE: <compiler> <flag> [more flags...]
# @INTERNAL
@@ -788,6 +799,12 @@ test-flags-FC() { _test-flags-PROG FC "$@"; }
# Returns shell true if <flags> are supported by the C compiler and
default linker, else returns shell false.
test-flags-CCLD() { _test-flags-PROG CCLD "$@"; }
+# @FUNCTION: test-flags-HIPCXX
+# @USAGE: <flags>
+# @DESCRIPTION:
+# Returns shell true if <flags> are supported by the HIP compiler and
default linker, else returns shell false.
+test-flags-HIPCXX() { _test-flags-PROG HIPCXX "$@"; }
+
# @FUNCTION: test-flags
# @USAGE: <flags>
# @DESCRIPTION:
@@ -810,7 +827,7 @@ test_version_info() {
# @FUNCTION: strip-unsupported-flags
# @DESCRIPTION:
-# Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain.
+# Strip {C,CXX,F,FC,HIP}FLAGS of any flags not supported by the
active toolchain.
strip-unsupported-flags() {
[[ $# -ne 0 ]] && die "strip-unsupported-flags takes no arguments"
export CFLAGS=$(test-flags-CC ${CFLAGS})
@@ -818,6 +835,7 @@ strip-unsupported-flags() {
export FFLAGS=$(test-flags-F77 ${FFLAGS})
export FCFLAGS=$(test-flags-FC ${FCFLAGS})
export LDFLAGS=$(test-flags-CCLD ${LDFLAGS})
+ export HIPFLAGS=$(test-flags-HIPCXX ${HIPFLAGS})
}
# @FUNCTION: get-flag
@@ -1008,6 +1026,12 @@ test-compile() {
args+=(${FCFLAGS[@]} ${LDFLAGS[@]} -xf95)
libs+=(${LIBS[@]})
;;
+ hip)
+ compiler="$(tc-getHIPCXX)"
+ filename_in="${T}/test.hip"
+ filename_out="${T}/test.o"
+ args+=(${CFLAGS[@]} -xhip -c)
+ ;;
*)
die "Unknown compiled language ${lang}"
;;
--
2.50.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-dev] [PATCH 3/3] rocm.eclass: add rocm_use_clang and strip flags in a better way
2025-06-22 16:31 ` [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: Add functions for testing/stripping HIPFLAGS Sv. Lockal
@ 2025-06-22 16:32 ` Sv. Lockal
0 siblings, 0 replies; 4+ messages in thread
From: Sv. Lockal @ 2025-06-22 16:32 UTC (permalink / raw
To: gentoo-dev
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 <lockalsash@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function
2025-06-22 16:29 [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function Sv. Lockal
2025-06-22 16:31 ` [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: Add functions for testing/stripping HIPFLAGS Sv. Lockal
@ 2025-07-05 7:15 ` Sam James
1 sibling, 0 replies; 4+ messages in thread
From: Sam James @ 2025-07-05 7:15 UTC (permalink / raw
To: Sv. Lockal; +Cc: gentoo-dev
"Sv. Lockal" <lockalsash@gmail.com> writes:
> This allows to find compiler for HIP language files.
> Environment variable HIPCXX is used by CMake[1].
> In recent releases of CMake, it strictly requires clang++, not hipcc.
> When not defined, CMake uses multiple methods to find HIP compiler,
> hipconfig is one of them[2].
>
Thanks, I merged the series as part of your PR
(https://github.com/gentoo/gentoo/pull/42691).
> [1] https://cmake.org/cmake/help/latest/envvar/HIPCXX.html
> [2] https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeDetermineHIPCompiler.cmake
>
> Bug: https://bugs.gentoo.org/957893
> Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
> ---
> eclass/toolchain-funcs.eclass | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
> index baf032bbd4ec..1f3f958badee 100644
> --- a/eclass/toolchain-funcs.eclass
> +++ b/eclass/toolchain-funcs.eclass
> @@ -73,6 +73,10 @@ tc-getCPP() { tc-getPROG CPP "${CC:-gcc} -E" "$@"; }
> # @USAGE: [toolchain prefix]
> # @RETURN: name of the C++ compiler
> tc-getCXX() { tc-getPROG CXX g++ "$@"; }
> +# @FUNCTION: tc-getHIPCXX
> +# @USAGE: [toolchain prefix]
> +# @RETURN: name of the HIP compiler
> +tc-getHIPCXX() { tc-getPROG HIPCXX "$(hipconfig
> --hipclangpath)/clang++" "$@"; }
> # @FUNCTION: tc-getLD
> # @USAGE: [toolchain prefix]
> # @RETURN: name of the linker
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-05 7:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-22 16:29 [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function Sv. Lockal
2025-06-22 16:31 ` [gentoo-dev] [PATCH 2/3] flag-o-matic.eclass: Add functions for testing/stripping HIPFLAGS Sv. Lockal
2025-06-22 16:32 ` [gentoo-dev] [PATCH 3/3] rocm.eclass: add rocm_use_clang and strip flags in a better way Sv. Lockal
2025-07-05 7:15 ` [gentoo-dev] [PATCH 1/3] toolchain-funcs.eclass: add tc-getHIPCXX function Sam James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox