Merge topic 'hip-nvidia'

fd982eec10 HIP: Add tests for special NVIDIA values of CMAKE_HIP_ARCHITECTURES
8c8b3f1bfa HIP: Fix support for -DCMAKE_HIP_ARCHITECTURES=native with NVCC
b3e92775ab HIP: Add CMAKE_HIP_HOST_COMPILER when compiler is NVCC
e43918b4ca HIP: Fix linking mixed-lang binary with CXX compiler and Makefile generators
4794505122 HIP: Do not require hip-lang package for NVIDIA platform
09d759dc7f HIP: Simplify exclusion of AMD device runtime with NVIDIA GPUs
2a60663670 HIP: Simplify CMAKE_GENERATOR references for determining compiler
8124950f6c CUDA: Generalize CMAKE_{CUDA => <LANG>}_HOST_COMPILER variable docs

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8836
This commit is contained in:
Brad King
2023-09-26 13:40:18 +00:00
committed by Kitware Robot
16 changed files with 233 additions and 100 deletions

View File

@@ -26,13 +26,13 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
if(DEFINED CMAKE_${lang}_VERBOSE_COMPILE_FLAG)
set(COMPILE_DEFINITIONS "${CMAKE_${lang}_VERBOSE_COMPILE_FLAG}")
endif()
if(lang STREQUAL "CUDA")
if(CMAKE_CUDA_ARCHITECTURES STREQUAL "native")
if(lang MATCHES "^(CUDA|HIP)$")
if(CMAKE_${lang}_ARCHITECTURES STREQUAL "native")
# We are about to detect the native architectures, so we do
# not yet know them. Use all architectures during detection.
set(CMAKE_CUDA_ARCHITECTURES "all")
set(CMAKE_${lang}_ARCHITECTURES "all")
endif()
set(CMAKE_CUDA_RUNTIME_LIBRARY "Static")
set(CMAKE_${lang}_RUNTIME_LIBRARY "Static")
endif()
if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
# Avoid adding our own platform standard libraries for compilers

View File

@@ -5,8 +5,8 @@ include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseLibraryArchitecture.cmake)
if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR
("${CMAKE_GENERATOR}" MATCHES "Ninja") ) )
if(NOT ((CMAKE_GENERATOR MATCHES "Make") OR
(CMAKE_GENERATOR MATCHES "Ninja")))
message(FATAL_ERROR "HIP language not currently supported by \"${CMAKE_GENERATOR}\" generator")
endif()
@@ -107,6 +107,13 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN)
# If the user set CMAKE_HIP_ARCHITECTURES, validate its value.
include(Internal/CMakeCUDAArchitecturesValidate)
cmake_cuda_architectures_validate(HIP)
if(NOT CMAKE_HIP_HOST_COMPILER AND NOT $ENV{HIPHOSTCXX} STREQUAL "")
get_filename_component(CMAKE_HIP_HOST_COMPILER $ENV{HIPHOSTCXX} PROGRAM)
if(NOT EXISTS "${CMAKE_HIP_HOST_COMPILER}")
message(FATAL_ERROR "Could not find compiler set in environment variable HIPHOSTCXX:\n$ENV{HIPHOSTCXX}.\n${CMAKE_HIP_HOST_COMPILER}")
endif()
endif()
endif()
if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang")
@@ -114,6 +121,9 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN)
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")
if(CMAKE_HIP_HOST_COMPILER)
string(APPEND CMAKE_HIP_COMPILER_ID_TEST_FLAGS_FIRST " -ccbin=\"${CMAKE_HIP_HOST_COMPILER}\"")
endif()
endif()
# We perform compiler identification for a second time to extract implicit linking info.
@@ -164,57 +174,61 @@ if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT)
message(FATAL_ERROR "Failed to find ROCm root directory.")
endif()
# Normally implicit link information is not detected until ABI detection,
# but we need to populate CMAKE_HIP_LIBRARY_ARCHITECTURE to find hip-lang.
cmake_parse_implicit_link_info("${CMAKE_HIP_COMPILER_PRODUCED_OUTPUT}"
_CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS
_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS
_CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS
_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG
"" LANGUAGE HIP)
message(CONFIGURE_LOG
"Parsed HIP implicit link information from compiler id output:\n${_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG}\n\n")
cmake_parse_library_architecture(HIP "${_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS}" "" CMAKE_HIP_LIBRARY_ARCHITECTURE)
if(CMAKE_HIP_LIBRARY_ARCHITECTURE)
message(CONFIGURE_LOG
"Parsed HIP library architecture from compiler id output: ${CMAKE_HIP_LIBRARY_ARCHITECTURE}\n")
endif()
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS)
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS)
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS)
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG)
if(CMAKE_HIP_PLATFORM STREQUAL "amd")
# For this platform we need the hip-lang cmake package.
if(NOT CMAKE_HIP_COMPILER_ROCM_LIB)
set(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS
"${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib"
"${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib64"
)
# Normally implicit link information is not detected until ABI detection,
# but we need to populate CMAKE_HIP_LIBRARY_ARCHITECTURE to find hip-lang.
cmake_parse_implicit_link_info("${CMAKE_HIP_COMPILER_PRODUCED_OUTPUT}"
_CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS
_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS
_CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS
_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG
"" LANGUAGE HIP)
message(CONFIGURE_LOG
"Parsed HIP implicit link information from compiler id output:\n${_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG}\n\n")
cmake_parse_library_architecture(HIP "${_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS}" "" CMAKE_HIP_LIBRARY_ARCHITECTURE)
if(CMAKE_HIP_LIBRARY_ARCHITECTURE)
list(APPEND _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/${CMAKE_HIP_LIBRARY_ARCHITECTURE}")
message(CONFIGURE_LOG
"Parsed HIP library architecture from compiler id output: ${CMAKE_HIP_LIBRARY_ARCHITECTURE}\n")
endif()
foreach(dir IN LISTS _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS)
if(EXISTS "${dir}/cmake/hip-lang/hip-lang-config.cmake")
set(CMAKE_HIP_COMPILER_ROCM_LIB "${dir}")
break()
endif()
endforeach()
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LIBS)
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_DIRS)
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_FWKS)
unset(_CMAKE_HIP_COMPILER_ID_IMPLICIT_LOG)
if(NOT CMAKE_HIP_COMPILER_ROCM_LIB)
list(TRANSFORM _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS APPEND "/cmake/hip-lang/hip-lang-config.cmake")
string(REPLACE ";" "\n " _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}")
message(FATAL_ERROR
"The ROCm root directory:\n"
" ${CMAKE_HIP_COMPILER_ROCM_ROOT}\n"
"does not contain the HIP runtime CMake package, expected at one of:\n"
" ${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}\n"
set(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS
"${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib"
"${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib64"
)
if(CMAKE_HIP_LIBRARY_ARCHITECTURE)
list(APPEND _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/${CMAKE_HIP_LIBRARY_ARCHITECTURE}")
endif()
foreach(dir IN LISTS _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS)
if(EXISTS "${dir}/cmake/hip-lang/hip-lang-config.cmake")
set(CMAKE_HIP_COMPILER_ROCM_LIB "${dir}")
break()
endif()
endforeach()
if(NOT CMAKE_HIP_COMPILER_ROCM_LIB)
list(TRANSFORM _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS APPEND "/cmake/hip-lang/hip-lang-config.cmake")
string(REPLACE ";" "\n " _CMAKE_HIP_COMPILER_ROCM_LIB_DIRS "${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}")
message(FATAL_ERROR
"The ROCm root directory:\n"
" ${CMAKE_HIP_COMPILER_ROCM_ROOT}\n"
"does not contain the HIP runtime CMake package, expected at one of:\n"
" ${_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS}\n"
)
endif()
unset(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS)
endif()
if(CMAKE_HIP_COMPILER_ROCM_LIB MATCHES "/lib64$" AND NOT DEFINED CMAKE_SIZEOF_VOID_P)
# We have not yet determined the target ABI but we need 'find_package' to
# search lib64 directories to find hip-lang CMake package dependencies.
# This will be replaced by ABI detection later.
set(CMAKE_HIP_SIZEOF_DATA_PTR 8)
endif()
unset(_CMAKE_HIP_COMPILER_ROCM_LIB_DIRS)
endif()
if(CMAKE_HIP_COMPILER_ROCM_LIB MATCHES "/lib64$" AND NOT DEFINED CMAKE_SIZEOF_VOID_P)
# We have not yet determined the target ABI but we need 'find_package' to
# search lib64 directories to find hip-lang CMake package dependencies.
# This will be replaced by ABI detection later.
set(CMAKE_HIP_SIZEOF_DATA_PTR 8)
endif()
if (NOT _CMAKE_TOOLCHAIN_LOCATION)

View File

@@ -25,8 +25,8 @@ or :command:`project` commands:
If this variable is already set, either explicitly or cached by
a previous call, the check is skipped.
:variable:`CMAKE_CUDA_HOST_COMPILER`
This variable is set when ``<lang>`` is ``CUDA``.
:variable:`CMAKE_<LANG>_HOST_COMPILER`
This variable is set when ``<lang>`` is ``CUDA`` or ``HIP``.
If the check detects an explicit host compiler that is required for
compilation, this variable will be set to that compiler.
@@ -34,12 +34,12 @@ or :command:`project` commands:
this variable will be cleared.
If this variable is already set, its value is preserved only if
:variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>` is also set.
:variable:`CMAKE_<LANG>_COMPILER` is also set.
Otherwise, the check runs and overwrites
:variable:`CMAKE_CUDA_HOST_COMPILER` with a new result.
Note that :variable:`CMAKE_CUDA_HOST_COMPILER` documents it should
:variable:`CMAKE_<LANG>_HOST_COMPILER` with a new result.
Note that :variable:`CMAKE_<LANG>_HOST_COMPILER` documents it should
not be set without also setting
:variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>` to a NVCC compiler.
:variable:`CMAKE_<LANG>_COMPILER` to a NVCC compiler.
For example:
@@ -65,7 +65,7 @@ macro(check_language lang)
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang})
set(extra_compiler_variables)
if(${lang} STREQUAL CUDA AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
if("${lang}" MATCHES "^(CUDA|HIP)$" AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
set(extra_compiler_variables "set(CMAKE_CUDA_HOST_COMPILER \\\"\${CMAKE_CUDA_HOST_COMPILER}\\\")")
endif()

View File

@@ -2,10 +2,8 @@ include(Compiler/NVIDIA)
__compiler_nvidia_cxx_standards(HIP)
__compiler_nvidia_cuda_flags(HIP)
# The ROCm hip-lang package does not work for nvcc,
# so provide a minimal one ourselves.
add_library(hip-lang::device INTERFACE IMPORTED)
set(_CMAKE_HIP_DEVICE_RUNTIME_TARGET hip-lang::device)
# The ROCm hip-lang cmake package's device runtime library is not needed for NVIDIA GPUs.
set(_CMAKE_HIP_DEVICE_RUNTIME_TARGET "")
set(CMAKE_HIP_STANDARD_INCLUDE_DIRECTORIES "${CMAKE_HIP_COMPILER_ROCM_ROOT}/include")