Skip to content

hip: Set --gcc-toolchain to ensure external HIP installs pick up correct GCC#46573

Merged
RMeli merged 1 commit intospack:developfrom
msimberg:hip-external-set-gcc-toolchain
Oct 10, 2024
Merged

hip: Set --gcc-toolchain to ensure external HIP installs pick up correct GCC#46573
RMeli merged 1 commit intospack:developfrom
msimberg:hip-external-set-gcc-toolchain

Conversation

@msimberg
Copy link
Copy Markdown
Contributor

When using hip and friends as externals, the install will in many cases not be set up to use a specific compiler/GCC standard library but will simply pick up the first one it finds from some system install directory, and this will often not be the same GCC as the one specified as the compiler in a spec.

One problematic case that we bumped into with this is if the system GCC is version 13 and a spack spec uses %gcc@12, where GCC 12 is installed in some non-standard location. However, when a package depends on HIP compilation through hipcc/HIP's clang would pick up GCC 13 (or libstdc++ from GCC 13). The rest of the code would be compiled with the correct GCC 12. Since GCC is not compatible in this direction (forward?), i.e. an application built with a newer version of libstdc++ can't be linked later to an older version of libstdc++. For searchability, the error you'd get in this case while linking is

undefined reference to `std::ios_base_library_init()'

This PR attempts to fix this when hip is external and the compiler is %gcc. It will set in dependent environments:

  • HIPCC_COMPILE_FLAGS_APPEND to include --gcc-toolchain pointing to the prefix of GCC. This is picked up by hipcc. This will be used e.g. by CMake packages that set CMAKE_CXX_COMPILER to hipcc.
  • HIPFLAGS to include the same as above. This is picked up by CMake for the initial value of CMAKE_HIP_FLAGS. When using HIP as a CMake language (at least in newer versions of CMake) HIP's clang++ will be used for compilation, so HIPCC_COMPILE_FLAGS_APPEND wouldn't work here.

As far as I understand if someone sets CMAKE_HIP_FLAGS explicitly, this will override HIPFLAGS. This is not perfect, but as far as I could tell no package is setting CMAKE_HIP_FLAGS at the moment.

I don't know if any of this will help non-CMake packages, but it should not hurt them at least.

llvm-amdgpu when built through spack will set GCC_INSTALL_PREFIX during configuration so the above is only used when hip is external. I suppose the workaround could also be set in llvm-amdgpu but I feel like hip is the semantically right place for these since that is what packages will usually depend on. The environment variables that are being set are also HIP flags, not llvm-amdgpu flags, and I don't think they'd have any effect if one depends only on llvm-amdgpu and uses clang++ directly from there. I don't know if this is a naive assumption?

@msimberg msimberg force-pushed the hip-external-set-gcc-toolchain branch from 66e55af to ea975c6 Compare September 25, 2024 10:49
Copy link
Copy Markdown
Contributor

@simonpintarelli simonpintarelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for me.

@msimberg
Copy link
Copy Markdown
Contributor Author

msimberg commented Oct 2, 2024

@toxa81
Copy link
Copy Markdown
Contributor

toxa81 commented Oct 2, 2024

Also works for me on LUMI-G with gcc-12.2.0 and rocm-6.0.3

@toxa81
Copy link
Copy Markdown
Contributor

toxa81 commented Oct 3, 2024

@haampie how about merging this?

Copy link
Copy Markdown
Contributor

@renjithravindrankannath renjithravindrankannath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RMeli RMeli merged commit 9346306 into spack:develop Oct 10, 2024
arezaii pushed a commit to arezaii/spack that referenced this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants