mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
HIP: Detect default architecture from the AMDGPU subarch triple
Otherwise, `project(LANGUAGES HIP)` fails to configure on a machine with no AMD GPU when using Clang 22 or newer: Failed to find a default HIP architecture. The default architecture is determined by running `rocm_agent_enumerator`, which returns nothing when no GPU is present, and then by matching ` -target-cpu ([a-z0-9]+) ` in the compiler's cc1 output. Clang stopped passing `-target-cpu` for AMDGPU in LLVM/Clang commit bf9fe776748c (clang/AMDGPU: Stop passing redundant -target-cpu to cc1, 2026-08-31); the processor is now carried in the triple's subarch field. Neither path matches, so configuration fails. Fall back to reading the subarch out of the triple, e.g., `amdgpu9.06-amd-amdhsa` for `gfx906`. Keep the `-target-cpu` branch for older compilers. Generic targets spell the subarch with fewer components, e.g., `amdgpu10.3--` for `gfx10-3-generic`. Those are not matched, so they still reach the existing error rather than producing an invalid architecture name.
This commit is contained in:
@@ -364,6 +364,8 @@ elseif(NOT DEFINED CMAKE_HIP_ARCHITECTURES)
|
||||
set(CMAKE_HIP_ARCHITECTURES "${_CMAKE_HIP_ARCHITECTURES}" CACHE STRING "HIP architectures")
|
||||
elseif(CMAKE_HIP_COMPILER_PRODUCED_OUTPUT MATCHES " -target-cpu ([a-z0-9]+) ")
|
||||
set(CMAKE_HIP_ARCHITECTURES "${CMAKE_MATCH_1}" CACHE STRING "HIP architectures")
|
||||
elseif(CMAKE_HIP_COMPILER_PRODUCED_OUTPUT MATCHES " -triple amdgpu([0-9]+)\\.([0-9a-f][0-9a-f])-")
|
||||
set(CMAKE_HIP_ARCHITECTURES "gfx${CMAKE_MATCH_1}${CMAKE_MATCH_2}" CACHE STRING "HIP architectures")
|
||||
else()
|
||||
message(FATAL_ERROR "Failed to find a default HIP architecture.")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user