mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-01-26 11:04:33 +00:00
Add support for SPIR-V platform in HIP
- Introduced `spirv` as a valid option for `CMAKE_HIP_PLATFORM`. - Updated handling of `CMAKE_HIP_ARCHITECTURES` to default to `OFF` for `spirv`. Help: Remove trailing blank line from hip-chipStar release notes
This commit is contained in:
parent
0439baaad1
commit
f14118ebe8
5
Help/release/dev/hip-chipStar.rst
Normal file
5
Help/release/dev/hip-chipStar.rst
Normal file
@ -0,0 +1,5 @@
|
||||
hip-chipStar
|
||||
------------
|
||||
|
||||
* ``HIP`` language code may now be compiled for SPIR-V targets (e.g., via chipStar).
|
||||
See the :variable:`CMAKE_HIP_PLATFORM` variable.
|
||||
@ -12,5 +12,9 @@ This is initialized based on the value of :variable:`CMAKE_HIP_PLATFORM`:
|
||||
Uses architectures reported by ``rocm_agent_enumerator``, if available,
|
||||
and otherwise to a default chosen by the compiler.
|
||||
|
||||
``spirv``
|
||||
Defaults to ``OFF``. The HIP package (e.g., chipStar) handles targeting
|
||||
via its own configuration.
|
||||
|
||||
This variable is used to initialize the :prop_tgt:`HIP_ARCHITECTURES` property
|
||||
on all targets. See the target property for additional information.
|
||||
|
||||
@ -13,6 +13,11 @@ The value must be one of:
|
||||
``nvidia``
|
||||
NVIDIA GPUs
|
||||
|
||||
.. versionadded:: 4.3
|
||||
|
||||
``spirv``
|
||||
SPIR-V target (e.g., chipStar)
|
||||
|
||||
If not specified, a default is computed via ``hipconfig --platform``.
|
||||
|
||||
:variable:`CMAKE_HIP_ARCHITECTURES` entries are interpreted with
|
||||
|
||||
@ -17,15 +17,17 @@ if(NOT CMAKE_HIP_PLATFORM)
|
||||
)
|
||||
if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND _CMAKE_HIPCONFIG_PLATFORM MATCHES "^(nvidia|nvcc)$")
|
||||
set(CMAKE_HIP_PLATFORM "nvidia" CACHE STRING "HIP platform" FORCE)
|
||||
elseif(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND _CMAKE_HIPCONFIG_PLATFORM MATCHES "^(spirv)$")
|
||||
set(CMAKE_HIP_PLATFORM "spirv" CACHE STRING "HIP platform" FORCE)
|
||||
else()
|
||||
set(CMAKE_HIP_PLATFORM "amd" CACHE STRING "HIP platform" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT CMAKE_HIP_PLATFORM MATCHES "^(amd|nvidia)$")
|
||||
if(NOT CMAKE_HIP_PLATFORM MATCHES "^(amd|nvidia|spirv)$")
|
||||
message(FATAL_ERROR
|
||||
"The CMAKE_HIP_PLATFORM has unsupported value:\n"
|
||||
" '${CMAKE_HIP_PLATFORM}'\n"
|
||||
"It must be 'amd' or 'nvidia'."
|
||||
"It must be 'amd', 'nvidia', or 'spirv'."
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -54,10 +56,10 @@ if(NOT CMAKE_HIP_COMPILER)
|
||||
if(NOT CMAKE_HIP_COMPILER_INIT)
|
||||
if(CMAKE_HIP_PLATFORM STREQUAL "nvidia")
|
||||
set(CMAKE_HIP_COMPILER_LIST nvcc)
|
||||
elseif(CMAKE_HIP_PLATFORM STREQUAL "amd")
|
||||
elseif(CMAKE_HIP_PLATFORM STREQUAL "amd" OR CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
set(CMAKE_HIP_COMPILER_LIST clang++)
|
||||
|
||||
# Look for the Clang coming with ROCm to support HIP.
|
||||
# Look for the Clang coming with ROCm or chipStar to support HIP.
|
||||
execute_process(COMMAND hipconfig --hipclangpath
|
||||
OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH
|
||||
RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT
|
||||
@ -140,7 +142,13 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN)
|
||||
endif()
|
||||
|
||||
if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang")
|
||||
list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-v")
|
||||
# For spirv platform (chipStar), set special flags for compiler identification
|
||||
include(Internal/CMakeChipStarHIP OPTIONAL)
|
||||
if(CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
_cmake_chipstar_set_compiler_id_flags()
|
||||
else()
|
||||
list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-v")
|
||||
endif()
|
||||
elseif(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA")
|
||||
# Tell nvcc to treat .hip files as CUDA sources.
|
||||
list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "-x cu -v")
|
||||
@ -194,11 +202,18 @@ if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT)
|
||||
message(FATAL_ERROR "Failed to find ROCm root directory.")
|
||||
# For spirv platform (chipStar), fall back to HIP_PATH environment variable
|
||||
if(CMAKE_HIP_PLATFORM STREQUAL "spirv" AND DEFINED ENV{HIP_PATH} AND IS_DIRECTORY "$ENV{HIP_PATH}")
|
||||
set(CMAKE_HIP_COMPILER_ROCM_ROOT "$ENV{HIP_PATH}")
|
||||
file(TO_CMAKE_PATH "${CMAKE_HIP_COMPILER_ROCM_ROOT}" CMAKE_HIP_COMPILER_ROCM_ROOT)
|
||||
else()
|
||||
message(FATAL_ERROR "Failed to find HIP root directory.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_HIP_PLATFORM STREQUAL "amd")
|
||||
# For this platform we need the hip-lang cmake package.
|
||||
|
||||
if(CMAKE_HIP_PLATFORM STREQUAL "amd" OR CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
# For amd and spirv platforms we need the hip-lang cmake package.
|
||||
|
||||
# Normally implicit link information is not detected until ABI detection,
|
||||
# but we need to populate CMAKE_HIP_LIBRARY_ARCHITECTURE to find hip-lang.
|
||||
@ -309,6 +324,9 @@ if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA")
|
||||
endif()
|
||||
endif()
|
||||
unset(CMAKE_HIP_ARCHITECTURES_DEFAULT)
|
||||
elseif(NOT DEFINED CMAKE_HIP_ARCHITECTURES AND CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
# chipStar handles targeting via hip package
|
||||
set(CMAKE_HIP_ARCHITECTURES "OFF" CACHE STRING "HIP architectures")
|
||||
elseif(NOT DEFINED CMAKE_HIP_ARCHITECTURES)
|
||||
# Use 'rocm_agent_enumerator' to get the current GPU architecture.
|
||||
set(_CMAKE_HIP_ARCHITECTURES)
|
||||
|
||||
@ -69,6 +69,13 @@ _cmake_common_language_platform_flags(HIP)
|
||||
# CMAKE_HIP_COMPILE_OBJECT
|
||||
# CMAKE_HIP_LINK_EXECUTABLE
|
||||
|
||||
# For spirv platform (chipStar), set compile and link commands
|
||||
if(CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
include(Internal/CMakeChipStarHIP OPTIONAL)
|
||||
_cmake_chipstar_set_compiler_flags()
|
||||
_cmake_chipstar_set_link_commands()
|
||||
endif()
|
||||
|
||||
# create a shared library
|
||||
if(NOT CMAKE_HIP_CREATE_SHARED_LIBRARY)
|
||||
set(CMAKE_HIP_CREATE_SHARED_LIBRARY
|
||||
|
||||
@ -11,7 +11,7 @@ endif()
|
||||
|
||||
set(__CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS}")
|
||||
|
||||
if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang")
|
||||
if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
string(APPEND CMAKE_HIP_FLAGS " --cuda-host-only")
|
||||
endif()
|
||||
|
||||
|
||||
54
Modules/Internal/CMakeChipStarHIP.cmake
Normal file
54
Modules/Internal/CMakeChipStarHIP.cmake
Normal file
@ -0,0 +1,54 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
# Helper functions for chipStar (spirv platform) HIP support
|
||||
|
||||
# Set chipStar compile flags in CMAKE_HIP_COMPILE_OBJECT
|
||||
function(_cmake_chipstar_set_compiler_flags)
|
||||
if(NOT CMAKE_HIP_PLATFORM STREQUAL "spirv" OR NOT CMAKE_HIP_COMPILER_ID STREQUAL "Clang")
|
||||
return()
|
||||
endif()
|
||||
set(_hip_path "${CMAKE_HIP_COMPILER_ROCM_ROOT}")
|
||||
set(_chipstar_flags "--offload=spirv64 --hip-path=${_hip_path} -nogpulib -nohipwrapperinc -include ${_hip_path}/include/hip/spirv_fixups.h")
|
||||
set(CMAKE_HIP_COMPILE_OBJECT
|
||||
"<CMAKE_HIP_COMPILER> ${_chipstar_flags} <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -x hip -c <SOURCE>" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Set link commands for chipStar to include libCHIP.so
|
||||
# This makes CMake treat it as if the compiler driver links it implicitly
|
||||
function(_cmake_chipstar_set_link_commands)
|
||||
if(NOT CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
return()
|
||||
endif()
|
||||
set(_hip_path "${CMAKE_HIP_COMPILER_ROCM_ROOT}")
|
||||
set(_chipstar_lib "${_hip_path}/lib/libCHIP.so")
|
||||
# Set link command templates with libCHIP.so appended (quoted for paths with spaces)
|
||||
set(CMAKE_HIP_LINK_EXECUTABLE
|
||||
"<CMAKE_HIP_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> \"${_chipstar_lib}\"" PARENT_SCOPE)
|
||||
set(CMAKE_HIP_CREATE_SHARED_LIBRARY
|
||||
"<CMAKE_HIP_COMPILER> <CMAKE_SHARED_LIBRARY_HIP_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> \"${_chipstar_lib}\"" PARENT_SCOPE)
|
||||
set(CMAKE_HIP_CREATE_SHARED_MODULE
|
||||
"<CMAKE_HIP_COMPILER> <CMAKE_SHARED_LIBRARY_HIP_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> \"${_chipstar_lib}\"" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
|
||||
|
||||
# Set compiler ID test flags for chipStar (called before CMAKE_HIP_COMPILER_ROCM_ROOT is set)
|
||||
function(_cmake_chipstar_set_compiler_id_flags)
|
||||
if(NOT CMAKE_HIP_PLATFORM STREQUAL "spirv")
|
||||
return()
|
||||
endif()
|
||||
# At this point CMAKE_HIP_COMPILER_ROCM_ROOT isn't set yet, use HIP_PATH or hipconfig
|
||||
set(_hip_path "$ENV{HIP_PATH}")
|
||||
if(NOT IS_DIRECTORY "${_hip_path}")
|
||||
execute_process(COMMAND hipconfig --rocmpath
|
||||
OUTPUT_VARIABLE _hip_path OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
if(IS_DIRECTORY "${_hip_path}")
|
||||
file(TO_CMAKE_PATH "${_hip_path}" _hip_path)
|
||||
# All flags in one string so they're used together. -no-hip-rt prevents linking amdhip64.
|
||||
list(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST
|
||||
"-v --offload=spirv64 --hip-path=${_hip_path} -nogpulib -nohipwrapperinc -no-hip-rt -L${_hip_path}/lib -lCHIP -include ${_hip_path}/include/hip/spirv_fixups.h")
|
||||
set(CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST "${CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
@ -2764,6 +2764,11 @@ void cmGeneratorTarget::AddHIPArchitectureFlags(cmBuildStep compileOrLink,
|
||||
return;
|
||||
}
|
||||
|
||||
// For spirv platform, chipStar handles targeting via the hip package
|
||||
if (this->Makefile->GetSafeDefinition("CMAKE_HIP_PLATFORM") == "spirv") {
|
||||
return;
|
||||
}
|
||||
|
||||
cmList options(arch);
|
||||
|
||||
for (std::string& option : options) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user