From 64a4a0c9a80fd4fcd3a5efb738de0e955c0deb71 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Wed, 2 Sep 2026 12:09:56 -0700 Subject: [PATCH] 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. --- Modules/CMakeDetermineHIPCompiler.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index c3a1649e29..3c64be4f2a 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -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()