mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
HIP: Use 'rocm_agent_enumerator' to determine CMAKE_HIP_ARCHITECTURES
This commit is contained in:

committed by
Brad King

parent
64aac043ee
commit
735f41fc2d
@@ -5,7 +5,8 @@ CMAKE_HIP_ARCHITECTURES
|
|||||||
|
|
||||||
Default value for :prop_tgt:`HIP_ARCHITECTURES` property of targets.
|
Default value for :prop_tgt:`HIP_ARCHITECTURES` property of targets.
|
||||||
|
|
||||||
This is initialized to the default architecture chosen by the compiler.
|
This is initialized to the architectures reported by ``rocm_agent_enumerator``,
|
||||||
|
if available, and otherwise to the default chosen by the compiler.
|
||||||
|
|
||||||
This variable is used to initialize the :prop_tgt:`HIP_ARCHITECTURES` property
|
This variable is used to initialize the :prop_tgt:`HIP_ARCHITECTURES` property
|
||||||
on all targets. See the target property for additional information.
|
on all targets. See the target property for additional information.
|
||||||
|
@@ -85,12 +85,43 @@ if(MSVC_HIP_ARCHITECTURE_ID)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT DEFINED CMAKE_HIP_ARCHITECTURES)
|
if(NOT DEFINED CMAKE_HIP_ARCHITECTURES)
|
||||||
# Analyze output from hipcc to get the current GPU architecture.
|
# Use 'rocm_agent_enumerator' to get the current GPU architecture.
|
||||||
if(CMAKE_HIP_COMPILER_PRODUCED_OUTPUT MATCHES " -target-cpu ([a-z0-9]+) ")
|
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")
|
set(CMAKE_HIP_ARCHITECTURES "${CMAKE_MATCH_1}" CACHE STRING "HIP architectures")
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Failed to find a working HIP architecture.")
|
message(FATAL_ERROR "Failed to find a default HIP architecture.")
|
||||||
endif()
|
endif()
|
||||||
|
unset(_CMAKE_HIP_ARCHITECTURES)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# configure variables set in this file for fast reload later on
|
# configure variables set in this file for fast reload later on
|
||||||
|
Reference in New Issue
Block a user