diff options
author | Zack Galbreath <zack.galbreath@kitware.com> | 2021-09-15 20:33:41 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-09-16 18:41:30 (GMT) |
commit | 735f41fc2d91bac11506ebf355136b0dbd8ac8c7 (patch) | |
tree | 86c84e0476c7698ae4866c07e8b2429123a45089 /Modules/CMakeDetermineHIPCompiler.cmake | |
parent | 64aac043eed8a58e69b1b7952086cdfa73cd3cac (diff) | |
download | CMake-735f41fc2d91bac11506ebf355136b0dbd8ac8c7.zip CMake-735f41fc2d91bac11506ebf355136b0dbd8ac8c7.tar.gz CMake-735f41fc2d91bac11506ebf355136b0dbd8ac8c7.tar.bz2 |
HIP: Use 'rocm_agent_enumerator' to determine CMAKE_HIP_ARCHITECTURES
Diffstat (limited to 'Modules/CMakeDetermineHIPCompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineHIPCompiler.cmake | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index ed0110a..4f0b754 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -85,12 +85,43 @@ if(MSVC_HIP_ARCHITECTURE_ID) endif() if(NOT DEFINED CMAKE_HIP_ARCHITECTURES) - # Analyze output from hipcc to get the current GPU architecture. - if(CMAKE_HIP_COMPILER_PRODUCED_OUTPUT MATCHES " -target-cpu ([a-z0-9]+) ") + # Use 'rocm_agent_enumerator' to get the current GPU architecture. + set(_CMAKE_HIP_ARCHITECTURES) + find_program(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR + NAMES rocm_agent_enumerator + NO_CACHE) + if(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR) + execute_process(COMMAND "${_CMAKE_HIP_ROCM_AGENT_ENUMERATOR}" -t GPU + RESULT_VARIABLE _CMAKE_ROCM_AGENT_ENUMERATOR_RESULT + OUTPUT_VARIABLE _CMAKE_ROCM_AGENT_ENUMERATOR_STDOUT + ERROR_VARIABLE _CMAKE_ROCM_AGENT_ENUMERATOR_STDERR + ) + if(_CMAKE_ROCM_AGENT_ENUMERATOR_RESULT EQUAL 0) + separate_arguments(_hip_archs NATIVE_COMMAND "${_CMAKE_ROCM_AGENT_ENUMERATOR_STDOUT}") + foreach(_hip_arch ${_hip_archs}) + if(_hip_arch STREQUAL "gfx000") + continue() + endif() + string(FIND ${_hip_arch} ":" pos) + if(NOT pos STREQUAL "-1") + string(SUBSTRING ${_hip_arch} 0 ${pos} _hip_arch) + endif() + list(APPEND _CMAKE_HIP_ARCHITECTURES "${_hip_arch}") + endforeach() + endif() + unset(_CMAKE_ROCM_AGENT_ENUMERATOR_RESULT) + unset(_CMAKE_ROCM_AGENT_ENUMERATOR_STDOUT) + unset(_CMAKE_ROCM_AGENT_ENUMERATOR_STDERR) + endif() + unset(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR) + if(_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") else() - message(FATAL_ERROR "Failed to find a working HIP architecture.") + message(FATAL_ERROR "Failed to find a default HIP architecture.") endif() + unset(_CMAKE_HIP_ARCHITECTURES) endif() # configure variables set in this file for fast reload later on |