Skip to content

Compile HIP sources with the HIP language when the C++ compiler is not Clang - #980

Open
haampie-bot wants to merge 1 commit into
microsoft:mainfrom
haampie-llms:hip-language
Open

haampie-bot wants to merge 1 commit into
microsoft:mainfrom
haampie-llms:hip-language

Conversation

@haampie-bot

Copy link
Copy Markdown

On ROCm, the HIP sources are compiled as C++ (src/core/CMakeLists.txt#L9, src/ext/nccl/CMakeLists.txt#L8, test/CMakeLists.txt#L15) and linked to hip::device (CMakeLists.txt#L240), so the C++ compiler has to be hipcc or Clang. With GCC, every source fails with "g++: error: unrecognized command-line option '--offload-arch=gfx90a'". Package managers such as Spack then have to replace their C++ compiler with hipcc for the whole build.

The fix is to compile these sources with CMake's HIP language when the C++ compiler is not Clang, and to link hip::host instead of hip::device. The project already sets CMAKE_HIP_STANDARD, CMAKE_HIP_FLAGS and CMAKE_HIP_ARCHITECTURES (CMakeLists.txt#L235-L238), so the per-target --offload-arch options are not needed in this mode. Builds with hipcc or Clang as C++ compiler, and CUDA builds, are unchanged.

Testing

Tested with ROCm 10.1 and MPICH for gfx90a. With GCC 11 as C++ compiler and amdclang++ as HIP compiler, the default all target builds: the libraries, the Python modules and the tests (with numactl's headers on CPATH). On main that configuration fails with the error above. With hipcc as C++ compiler, the generated compile and link commands are identical to main. Nothing was run on a GPU, and the CUDA build was not tested.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:33
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Coverage builds with GCC fail to link because they receive the Clang-only -Xarch_host option, while HIP sources receive no coverage instrumentation.

1 open issue
What changed in this PR

This PR enables ROCm builds with a non-Clang C++ compiler, such as GCC, by compiling GPU-related sources with CMake’s HIP language. Existing hipcc/Clang and CUDA paths are preserved.

Changes:

  • Selects HIP compilation and hip::host linking for non-Clang C++ compilers.
  • Updates libraries and tests to use HIP source properties and CMake-managed GPU architectures.
  • Preserves hidden symbol visibility for HIP-compiled Python modules.
File Description
test/​mscclpp-test/​CMakeLists.txt Applies HIP compilation to test sources and shared helpers.
test/​CMakeLists.txt Selects HIP compilation for ROCm tests in the new mode.
src/​ext/​nccl/​CMakeLists.txt Uses the selected language and conditional architecture flags.
src/​ext/​collectives/​CMakeLists.txt Adds HIP compilation for collective sources.
src/​core/​CMakeLists.txt Adds HIP compilation for core library sources.
python/​test/​CMakeLists.txt Compiles test bindings as HIP with hidden visibility.
python/​csrc/​CMakeLists.txt Compiles Python bindings as HIP with hidden visibility.
CMakeLists.txt Selects the ROCm compilation mode and runtime dependency.

Review effort: Balanced

Comment thread CMakeLists.txt Resolved
@haampie-bot

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

(written by a human from the bot account)

…t Clang

On ROCm, the HIP sources are compiled as C++ and linked to hip::device,
which requires the C++ compiler to be hipcc or Clang. With GCC, every
source fails with "g++: error: unrecognized command-line option
'--offload-arch=gfx90a'".

When the C++ compiler is not Clang, enable CMake's HIP language, compile
the sources of the core library, the collectives and NCCL extensions, the
Python bindings and the tests as HIP, and link hip::host instead of
hip::device. The GPU architectures then come from CMAKE_HIP_ARCHITECTURES,
which is already set from MSCCLPP_GPU_ARCHS. Builds with hipcc or Clang as
C++ compiler and CUDA builds are unchanged.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The GCC/HIP compiler-boundary changes have only build-level validation; GPU execution and cross-module Python conversions still require ROCm runtime testing unavailable in this review environment.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants