* [gentoo-dev] [PATCH] rocm.eclass: add rocm_use_hipcc function and update example accordingly
@ 2024-08-03 21:09 Sv. Lockal
2024-08-17 12:10 ` [gentoo-dev] " Sv. Lockal
0 siblings, 1 reply; 2+ messages in thread
From: Sv. Lockal @ 2024-08-03 21:09 UTC (permalink / raw
To: gentoo-dev
This adds a new function rocm_use_hipcc in rocm.eclass to be used in
every src_configure, where the compiler is switched to hipcc (a. k. a.
clang with extra flags).
Github pull request: https://github.com/gentoo/gentoo/pull/37639
Bug: https://bugs.gentoo.org/936099
Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
---
eclass/rocm.eclass | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 7039455dec6b5..44ddf4fd09a87 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -15,9 +15,13 @@
# edit USE flag to control which GPU architecture to compile. Using
# ${ROCM_USEDEP} can ensure coherence among dependencies. Ebuilds can call the
# function get_amdgpu_flag to translate activated target to GPU compile flags,
-# passing it to configuration. Function check_amdgpu can help ebuild ensure
+# passing it to configuration. Function rocm_use_hipcc switches active compiler
+# to hipcc and cleans incompatible flags (useful for users with gcc-only flags
+# in /etc/portage/make.conf). Function check_amdgpu can help ebuild ensure
# read and write permissions to GPU device in src_test phase, throwing friendly
-# error message if unavailable.
+# error message if unavailable. However src_configure in general should not
+# access any GPU devices. If it does, it usually means that CMakeLists.txt
+# ignores AMDGPU_TARGETS in favor of autodetected GPU, which is not desired.
#
# @EXAMPLE:
# Example ebuild for ROCm library in https://github.com/ROCmSoftwarePlatform
@@ -39,14 +43,12 @@
# "
#
# src_configure() {
-# # avoid sandbox violation
-# addpredict /dev/kfd
-# addpredict /dev/dri/
+# rocm_use_hipcc
# local mycmakeargs=(
# -DAMDGPU_TARGETS="$(get_amdgpu_flags)"
# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
# )
-# CXX=hipcc cmake_src_configure
+# cmake_src_configure
# }
#
# src_test() {
@@ -90,6 +92,8 @@ esac
if [[ ! ${_ROCM_ECLASS} ]]; then
_ROCM_ECLASS=1
+inherit flag-o-matic
+
# @ECLASS_VARIABLE: ROCM_VERSION
# @REQUIRED
# @PRE_INHERIT
@@ -231,3 +235,12 @@ check_amdgpu() {
}
fi
+
+# @FUNCTION: rocm_use_hipcc
+# @USAGE: rocm_use_hipcc
+# @DESCRIPTION:
+# switch active C and C++ compilers to hipcc and clean unsupported flags.
+rocm_use_hipcc() {
+ export CC=hipcc CXX=hipcc
+ strip-unsupported-flags
+}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-dev] Re: [PATCH] rocm.eclass: add rocm_use_hipcc function and update example accordingly
2024-08-03 21:09 [gentoo-dev] [PATCH] rocm.eclass: add rocm_use_hipcc function and update example accordingly Sv. Lockal
@ 2024-08-17 12:10 ` Sv. Lockal
0 siblings, 0 replies; 2+ messages in thread
From: Sv. Lockal @ 2024-08-17 12:10 UTC (permalink / raw
To: gentoo-dev
Following the discussion in https://github.com/gentoo/gentoo/pull/37639,
rocm_use_hipcc now creates ROCM_TARGET_LST to prevent GPU access
during src_configure phase. Interdiff is below:
diff -u b/eclass/rocm.eclass b/eclass/rocm.eclass
--- b/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -20,7 +20,7 @@
# in /etc/portage/make.conf). Function check_amdgpu can help ebuild ensure
# read and write permissions to GPU device in src_test phase, throwing friendly
# error message if unavailable. However src_configure in general should not
-# access any GPU devices. If it does, it usually means that CMakeLists.txt
+# access any AMDGPU devices. If it does, it usually means that CMakeLists.txt
# ignores AMDGPU_TARGETS in favor of autodetected GPU, which is not desired.
#
# @EXAMPLE:
@@ -239,8 +239,23 @@
# @FUNCTION: rocm_use_hipcc
# @USAGE: rocm_use_hipcc
# @DESCRIPTION:
-# switch active C and C++ compilers to hipcc and clean unsupported flags.
+# switch active C and C++ compilers to hipcc, clean unsupported flags
and setup ROCM_TARGET_LST file.
rocm_use_hipcc() {
+ # During the configuration stage, CMake tests whether the
compiler is able to compile a simple program.
+ # Since CMake checker does not specify --offload-arch=, hipcc
enumerates devices using four methods
+ # until it finds at least one device. Last way is by accessing
them (via rocminfo).
+ # To prevent potential sandbox violations, we set the
ROCM_TARGET_LST variable (which is checked first).
+ local target_lst="${T}"/gentoo_rocm_target.lst
+ if [[ "${AMDGPU_TARGETS[@]}" = "" ]]; then
+ # Expected no GPU code; still need to calm down sandbox
+ echo "gfx000" > "${target_lst}" || die
+ else
+ printf "%s\n" ${AMDGPU_TARGETS[@]} > "${target_lst}" || die
+ fi
+ export ROCM_TARGET_LST="${target_lst}"
+
+ # 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
}
On Sun, Aug 4, 2024 at 5:09 AM Sv. Lockal <lockalsash@gmail.com> wrote:
>
> This adds a new function rocm_use_hipcc in rocm.eclass to be used in
> every src_configure, where the compiler is switched to hipcc (a. k. a.
> clang with extra flags).
>
> Github pull request: https://github.com/gentoo/gentoo/pull/37639
> Bug: https://bugs.gentoo.org/936099
> Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
> ---
> eclass/rocm.eclass | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
> index 7039455dec6b5..44ddf4fd09a87 100644
> --- a/eclass/rocm.eclass
> +++ b/eclass/rocm.eclass
> @@ -15,9 +15,13 @@
> # edit USE flag to control which GPU architecture to compile. Using
> # ${ROCM_USEDEP} can ensure coherence among dependencies. Ebuilds can call the
> # function get_amdgpu_flag to translate activated target to GPU compile flags,
> -# passing it to configuration. Function check_amdgpu can help ebuild ensure
> +# passing it to configuration. Function rocm_use_hipcc switches active compiler
> +# to hipcc and cleans incompatible flags (useful for users with gcc-only flags
> +# in /etc/portage/make.conf). Function check_amdgpu can help ebuild ensure
> # read and write permissions to GPU device in src_test phase, throwing friendly
> -# error message if unavailable.
> +# error message if unavailable. However src_configure in general should not
> +# access any GPU devices. If it does, it usually means that CMakeLists.txt
> +# ignores AMDGPU_TARGETS in favor of autodetected GPU, which is not desired.
> #
> # @EXAMPLE:
> # Example ebuild for ROCm library in https://github.com/ROCmSoftwarePlatform
> @@ -39,14 +43,12 @@
> # "
> #
> # src_configure() {
> -# # avoid sandbox violation
> -# addpredict /dev/kfd
> -# addpredict /dev/dri/
> +# rocm_use_hipcc
> # local mycmakeargs=(
> # -DAMDGPU_TARGETS="$(get_amdgpu_flags)"
> # -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
> # )
> -# CXX=hipcc cmake_src_configure
> +# cmake_src_configure
> # }
> #
> # src_test() {
> @@ -90,6 +92,8 @@ esac
> if [[ ! ${_ROCM_ECLASS} ]]; then
> _ROCM_ECLASS=1
>
> +inherit flag-o-matic
> +
> # @ECLASS_VARIABLE: ROCM_VERSION
> # @REQUIRED
> # @PRE_INHERIT
> @@ -231,3 +235,12 @@ check_amdgpu() {
> }
>
> fi
> +
> +# @FUNCTION: rocm_use_hipcc
> +# @USAGE: rocm_use_hipcc
> +# @DESCRIPTION:
> +# switch active C and C++ compilers to hipcc and clean unsupported flags.
> +rocm_use_hipcc() {
> + export CC=hipcc CXX=hipcc
> + strip-unsupported-flags
> +}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-17 12:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-03 21:09 [gentoo-dev] [PATCH] rocm.eclass: add rocm_use_hipcc function and update example accordingly Sv. Lockal
2024-08-17 12:10 ` [gentoo-dev] " Sv. Lockal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox