-
Notifications
You must be signed in to change notification settings - Fork 85
Enhancement - Support AMDGPU_TARGETS in ROCm CMake builds #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,11 +37,25 @@ else() | |||||||||||||||||||||||||||||||||||||||||||||
| set(HIP_PATH $ENV{HIP_PATH}) | ||||||||||||||||||||||||||||||||||||||||||||||
| endif() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Turn off CMAKE_HIP_ARCHITECTURES Feature if cmake version is 3.21+ | ||||||||||||||||||||||||||||||||||||||||||||||
| if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0) | ||||||||||||||||||||||||||||||||||||||||||||||
| set(CMAKE_HIP_ARCHITECTURES OFF) | ||||||||||||||||||||||||||||||||||||||||||||||
| # Set HIP architectures from AMDGPU_TARGETS environment variable if available. | ||||||||||||||||||||||||||||||||||||||||||||||
| # AMDGPU_TARGETS should be a space-separated list of GPU architectures, | ||||||||||||||||||||||||||||||||||||||||||||||
| # e.g. "gfx908 gfx90a gfx942". | ||||||||||||||||||||||||||||||||||||||||||||||
| # Both the CMake variable AMDGPU_TARGETS and CMAKE_HIP_ARCHITECTURES must be set: | ||||||||||||||||||||||||||||||||||||||||||||||
| # - AMDGPU_TARGETS is read by ROCm's hip-config-amd.cmake to set --offload-arch flags | ||||||||||||||||||||||||||||||||||||||||||||||
| # - CMAKE_HIP_ARCHITECTURES is the native CMake variable for HIP (requires >= 3.21) | ||||||||||||||||||||||||||||||||||||||||||||||
| if(DEFINED ENV{AMDGPU_TARGETS}) | ||||||||||||||||||||||||||||||||||||||||||||||
| string(REPLACE " " ";" HIP_ARCH_LIST "$ENV{AMDGPU_TARGETS}") | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| string(REPLACE " " ";" HIP_ARCH_LIST "$ENV{AMDGPU_TARGETS}") | |
| # Normalize whitespace to avoid empty list elements: | |
| # 1) strip leading/trailing whitespace | |
| # 2) collapse runs of spaces/tabs into a single list separator ';' | |
| set(_AMDGPU_TARGETS_RAW "$ENV{AMDGPU_TARGETS}") | |
| string(STRIP "${_AMDGPU_TARGETS_RAW}" _AMDGPU_TARGETS_STRIPPED) | |
| string(REGEX REPLACE "[ \t]+" ";" HIP_ARCH_LIST "${_AMDGPU_TARGETS_STRIPPED}") |
Copilot
AI
Mar 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set(AMDGPU_TARGETS ... CACHE STRING ...) will not override an existing cached AMDGPU_TARGETS value. If a build directory is reconfigured with a different AMDGPU_TARGETS environment variable, this code may silently keep using the old cached value. Decide the intended precedence (env vs cache) and implement it explicitly (e.g., only set when the cache entry is unset, or use FORCE when env should win).
| set(AMDGPU_TARGETS ${HIP_ARCH_LIST} CACHE STRING "AMD GPU targets to compile for") | |
| set(AMDGPU_TARGETS ${HIP_ARCH_LIST} CACHE STRING "AMD GPU targets to compile for" FORCE) |
Copilot
AI
Mar 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(DEFINED ENV{AMDGPU_TARGETS}) is true even when the environment variable exists but is empty. In that case HIP_ARCH_LIST becomes empty and this will cache an empty AMDGPU_TARGETS, potentially breaking the HIP toolchain configuration instead of falling back to auto-detection. Consider checking that $ENV{AMDGPU_TARGETS} is non-empty (after trimming) before taking this branch.
| string(REPLACE " " ";" HIP_ARCH_LIST "$ENV{AMDGPU_TARGETS}") | |
| set(AMDGPU_TARGETS ${HIP_ARCH_LIST} CACHE STRING "AMD GPU targets to compile for") | |
| if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0) | |
| set(CMAKE_HIP_ARCHITECTURES ${HIP_ARCH_LIST}) | |
| endif() | |
| message(STATUS "Using AMDGPU_TARGETS from environment: ${HIP_ARCH_LIST}") | |
| # Copy and trim the environment variable to ensure it is non-empty after stripping whitespace. | |
| set(_amdgpu_targets_raw "$ENV{AMDGPU_TARGETS}") | |
| string(STRIP "${_amdgpu_targets_raw}" _amdgpu_targets) | |
| if(NOT _amdgpu_targets STREQUAL "") | |
| string(REPLACE " " ";" HIP_ARCH_LIST "${_amdgpu_targets}") | |
| set(AMDGPU_TARGETS ${HIP_ARCH_LIST} CACHE STRING "AMD GPU targets to compile for") | |
| if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0) | |
| set(CMAKE_HIP_ARCHITECTURES ${HIP_ARCH_LIST}) | |
| endif() | |
| message(STATUS "Using AMDGPU_TARGETS from environment: ${HIP_ARCH_LIST}") | |
| else() | |
| if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0) | |
| set(CMAKE_HIP_ARCHITECTURES OFF) | |
| endif() | |
| message(STATUS "AMDGPU_TARGETS is defined but empty, relying on hipcc auto-detection") | |
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says both
AMDGPU_TARGETSandCMAKE_HIP_ARCHITECTURESmust be set, but the micro-benchmark CMake projects in this repo areLANGUAGES CXXand compile viahipccas the C++ compiler (they don’t enable the HIP language). In that setup,CMAKE_HIP_ARCHITECTURESis unlikely to be consumed by CMake at all, so this note can be misleading. Please adjust the comment (and/or the logic) to reflect what actually drives offload arch selection here (typicallyAMDGPU_TARGETSas read byhip-config-amd.cmake).