mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-25 01:28:50 -05:00
Merge topic 'hip-nvidia'
fd982eec10HIP: Add tests for special NVIDIA values of CMAKE_HIP_ARCHITECTURES8c8b3f1bfaHIP: Fix support for -DCMAKE_HIP_ARCHITECTURES=native with NVCCb3e92775abHIP: Add CMAKE_HIP_HOST_COMPILER when compiler is NVCCe43918b4caHIP: Fix linking mixed-lang binary with CXX compiler and Makefile generators4794505122HIP: Do not require hip-lang package for NVIDIA platform09d759dc7fHIP: Simplify exclusion of AMD device runtime with NVIDIA GPUs2a60663670HIP: Simplify CMAKE_GENERATOR references for determining compiler8124950f6cCUDA: Generalize CMAKE_{CUDA => <LANG>}_HOST_COMPILER variable docs Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8836
This commit is contained in:
@@ -8,8 +8,10 @@ CUDAHOSTCXX
|
||||
Preferred executable for compiling host code when compiling ``CUDA``
|
||||
language files. Will only be used by CMake on the first configuration to
|
||||
determine ``CUDA`` host compiler, after which the value for ``CUDAHOSTCXX`` is
|
||||
stored in the cache as :variable:`CMAKE_CUDA_HOST_COMPILER`. This environment
|
||||
variable is preferred over :variable:`CMAKE_CUDA_HOST_COMPILER`.
|
||||
stored in the cache as
|
||||
:variable:`CMAKE_CUDA_HOST_COMPILER <CMAKE_<LANG>_HOST_COMPILER>`.
|
||||
This environment variable is preferred over
|
||||
:variable:`CMAKE_CUDA_HOST_COMPILER <CMAKE_<LANG>_HOST_COMPILER>`.
|
||||
|
||||
This environment variable is primarily meant for use with projects that
|
||||
enable ``CUDA`` as a first-class language.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
HIPHOSTCXX
|
||||
-----------
|
||||
|
||||
.. versionadded:: 3.28
|
||||
|
||||
.. include:: ENV_VAR.txt
|
||||
|
||||
Preferred executable for compiling host code when compiling ``HIP``
|
||||
language files with the NVIDIA CUDA Compiler. Will only be used by CMake
|
||||
on the first configuration to determine ``HIP`` host compiler, after which
|
||||
the value for ``HIPHOSTCXX`` is stored in the cache as
|
||||
:variable:`CMAKE_HIP_HOST_COMPILER <CMAKE_<LANG>_HOST_COMPILER>`.
|
||||
|
||||
This environment variable is primarily meant for use with projects that
|
||||
enable ``HIP`` as a first-class language.
|
||||
|
||||
.. note::
|
||||
|
||||
Ignored when using :ref:`Visual Studio Generators`.
|
||||
@@ -84,6 +84,7 @@ Environment Variables for Languages
|
||||
/envvar/FFLAGS
|
||||
/envvar/HIPCXX
|
||||
/envvar/HIPFLAGS
|
||||
/envvar/HIPHOSTCXX
|
||||
/envvar/ISPC
|
||||
/envvar/ISPCFLAGS
|
||||
/envvar/OBJC
|
||||
|
||||
@@ -628,6 +628,7 @@ Variables for Languages
|
||||
/variable/CMAKE_LANG_FLAGS_RELEASE_INIT
|
||||
/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO
|
||||
/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT
|
||||
/variable/CMAKE_LANG_HOST_COMPILER
|
||||
/variable/CMAKE_LANG_IGNORE_EXTENSIONS
|
||||
/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES
|
||||
/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES
|
||||
|
||||
@@ -3,34 +3,6 @@ CMAKE_CUDA_HOST_COMPILER
|
||||
|
||||
.. versionadded:: 3.10
|
||||
|
||||
When :variable:`CMAKE_CUDA_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>` is
|
||||
``NVIDIA``, ``CMAKE_CUDA_HOST_COMPILER`` selects the compiler executable to use
|
||||
when compiling host code for ``CUDA`` language files.
|
||||
This maps to the ``nvcc -ccbin`` option.
|
||||
|
||||
The ``CMAKE_CUDA_HOST_COMPILER`` variable may be set explicitly before CUDA is
|
||||
first enabled by a :command:`project` or :command:`enable_language` command.
|
||||
This can be done via ``-DCMAKE_CUDA_HOST_COMPILER=...`` on the command line
|
||||
or in a :ref:`toolchain file <Cross Compiling Toolchain>`. Or, one may set
|
||||
the :envvar:`CUDAHOSTCXX` environment variable to provide a default value.
|
||||
|
||||
Once the CUDA language is enabled, the ``CMAKE_CUDA_HOST_COMPILER`` variable
|
||||
is read-only and changes to it are undefined behavior.
|
||||
|
||||
.. note::
|
||||
|
||||
Since ``CMAKE_CUDA_HOST_COMPILER`` is meaningful only when the
|
||||
:variable:`CMAKE_CUDA_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>` is ``NVIDIA``,
|
||||
it does not make sense to set ``CMAKE_CUDA_HOST_COMPILER`` without also
|
||||
setting ``CMAKE_CUDA_COMPILER`` to NVCC.
|
||||
|
||||
.. note::
|
||||
|
||||
Projects should not try to set ``CMAKE_CUDA_HOST_COMPILER`` to match
|
||||
:variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>` themselves.
|
||||
It is the end-user's responsibility, not the project's, to ensure that
|
||||
the C++ and CUDA compilers target the same ABI.
|
||||
|
||||
.. note::
|
||||
|
||||
Ignored when using :ref:`Visual Studio Generators`.
|
||||
This is the original CUDA-specific name for the more general
|
||||
:variable:`CMAKE_<LANG>_HOST_COMPILER` variable. See the latter
|
||||
for details.
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
CMAKE_<LANG>_HOST_COMPILER
|
||||
--------------------------
|
||||
|
||||
.. versionadded:: 3.10
|
||||
``CMAKE_CUDA_HOST_COMPILER``
|
||||
|
||||
.. versionadded:: 3.28
|
||||
``CMAKE_HIP_HOST_COMPILER``
|
||||
|
||||
This variable is available when ``<LANG>`` is ``CUDA`` or ``HIP``.
|
||||
|
||||
When :variable:`CMAKE_<LANG>_COMPILER_ID` is
|
||||
``NVIDIA``, ``CMAKE_<LANG>_HOST_COMPILER`` selects the compiler executable
|
||||
to use when compiling host code for ``CUDA`` or ``HIP`` language files.
|
||||
This maps to the ``nvcc -ccbin`` option.
|
||||
|
||||
The ``CMAKE_<LANG>_HOST_COMPILER`` variable may be set explicitly before CUDA
|
||||
or HIP is first enabled by a :command:`project` or :command:`enable_language`
|
||||
command.
|
||||
This can be done via ``-DCMAKE_<LANG>_HOST_COMPILER=...`` on the command line
|
||||
or in a :ref:`toolchain file <Cross Compiling Toolchain>`. Or, one may set
|
||||
the :envvar:`CUDAHOSTCXX` or :envvar:`HIPHOSTCXX` environment variable to
|
||||
provide a default value.
|
||||
|
||||
Once the CUDA or HIP language is enabled, the ``CMAKE_<LANG>_HOST_COMPILER``
|
||||
variable is read-only and changes to it are undefined behavior.
|
||||
|
||||
.. note::
|
||||
|
||||
Since ``CMAKE_<LANG>_HOST_COMPILER`` is meaningful only when the
|
||||
:variable:`CMAKE_<LANG>_COMPILER_ID` is ``NVIDIA``,
|
||||
it does not make sense to set ``CMAKE_<LANG>_HOST_COMPILER`` without also
|
||||
setting ``CMAKE_<LANG>_COMPILER`` to NVCC.
|
||||
|
||||
.. note::
|
||||
|
||||
Projects should not try to set ``CMAKE_<LANG>_HOST_COMPILER`` to match
|
||||
:variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>` themselves.
|
||||
It is the end-user's responsibility, not the project's, to ensure that
|
||||
NVCC targets the same ABI as the C++ compiler.
|
||||
|
||||
.. note::
|
||||
|
||||
Ignored when using :ref:`Visual Studio Generators`.
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -732,10 +732,16 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
|
||||
// The link and compile lines for ABI detection step need to not use
|
||||
// response files so we can extract implicit includes given to
|
||||
// the underlying host compiler
|
||||
if (testLangs.find("CUDA") != testLangs.end()) {
|
||||
fprintf(fout, "set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES OFF)\n");
|
||||
fprintf(fout, "set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)\n");
|
||||
fprintf(fout, "set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS OFF)\n");
|
||||
static std::array<std::string, 2> const noRSP{ { "CUDA", "HIP" } };
|
||||
for (std::string const& lang : noRSP) {
|
||||
if (testLangs.find(lang) != testLangs.end()) {
|
||||
fprintf(fout, "set(CMAKE_%s_USE_RESPONSE_FILE_FOR_INCLUDES OFF)\n",
|
||||
lang.c_str());
|
||||
fprintf(fout, "set(CMAKE_%s_USE_RESPONSE_FILE_FOR_LIBRARIES OFF)\n",
|
||||
lang.c_str());
|
||||
fprintf(fout, "set(CMAKE_%s_USE_RESPONSE_FILE_FOR_OBJECTS OFF)\n",
|
||||
lang.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(fout, "set(CMAKE_VERBOSE_MAKEFILE 1)\n");
|
||||
|
||||
@@ -13,7 +13,7 @@ endif()
|
||||
unset(expect_Fortran)
|
||||
set(expect_NoSuchLanguage 0)
|
||||
|
||||
set(LANGUAGES C CXX Fortran CUDA NoSuchLanguage)
|
||||
set(LANGUAGES C CXX Fortran CUDA HIP NoSuchLanguage)
|
||||
if(APPLE)
|
||||
list(APPEND LANGUAGES OBJC OBJCXX)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
cmake_minimum_required(VERSION 3.27)
|
||||
project(ArchSpecial HIP)
|
||||
|
||||
if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA" AND
|
||||
CMAKE_HIP_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
|
||||
set(compile_options -Wno-deprecated-gpu-targets)
|
||||
endif()
|
||||
|
||||
function(verify_output flag)
|
||||
string(REPLACE "-" "_" architectures "${flag}")
|
||||
string(TOUPPER "${architectures}" architectures)
|
||||
set(architectures "${CMAKE_HIP_ARCHITECTURES_${architectures}}")
|
||||
list(TRANSFORM architectures REPLACE "-real" "")
|
||||
|
||||
if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA")
|
||||
set(match_regex "-arch compute_([0-9]+)")
|
||||
endif()
|
||||
|
||||
string(REGEX MATCHALL "${match_regex}" target_cpus "${output}")
|
||||
|
||||
foreach(cpu ${target_cpus})
|
||||
string(REGEX MATCH "${match_regex}" dont_care "${cpu}")
|
||||
list(APPEND command_archs "${CMAKE_MATCH_1}")
|
||||
endforeach()
|
||||
|
||||
list(SORT command_archs)
|
||||
list(REMOVE_DUPLICATES command_archs)
|
||||
if(NOT "${command_archs}" STREQUAL "${architectures}")
|
||||
message(FATAL_ERROR "Architectures used for \"${flag}\" don't match the reference (\"${command_archs}\" != \"${architectures}\").")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(try_compile_flags -v ${compile_options})
|
||||
|
||||
set(CMAKE_HIP_ARCHITECTURES all)
|
||||
try_compile(all_archs_compiles
|
||||
${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_archs_compiles
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.hip
|
||||
COMPILE_DEFINITIONS ${try_compile_flags}
|
||||
OUTPUT_VARIABLE output
|
||||
)
|
||||
verify_output(all)
|
||||
|
||||
set(CMAKE_HIP_ARCHITECTURES all-major)
|
||||
try_compile(all_major_archs_compiles
|
||||
${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_major_archs_compiles
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.hip
|
||||
COMPILE_DEFINITIONS ${try_compile_flags}
|
||||
OUTPUT_VARIABLE output
|
||||
)
|
||||
verify_output(all-major)
|
||||
|
||||
set(CMAKE_HIP_ARCHITECTURES native)
|
||||
try_compile(native_archs_compiles
|
||||
${CMAKE_CURRENT_BINARY_DIR}/try_compile/native_archs_compiles
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.hip
|
||||
COMPILE_DEFINITIONS ${try_compile_flags}
|
||||
OUTPUT_VARIABLE output
|
||||
)
|
||||
verify_output(native)
|
||||
|
||||
if(all_archs_compiles AND all_major_archs_compiles AND native_archs_compiles)
|
||||
set(CMAKE_HIP_ARCHITECTURES all)
|
||||
add_executable(HIPArchSpecial main.hip)
|
||||
target_compile_options(HIPArchSpecial PRIVATE ${compile_options})
|
||||
endif()
|
||||
@@ -0,0 +1,3 @@
|
||||
int main()
|
||||
{
|
||||
}
|
||||
@@ -5,6 +5,9 @@ macro (add_hip_test_macro name)
|
||||
endmacro ()
|
||||
|
||||
add_hip_test_macro(HIP.ArchitectureOff HIPOnlyArchitectureOff)
|
||||
if(CMake_TEST_HIP STREQUAL "nvidia")
|
||||
add_hip_test_macro(HIP.ArchSpecial HIPArchSpecial)
|
||||
endif()
|
||||
add_hip_test_macro(HIP.CompileFlags HIPOnlyCompileFlags)
|
||||
add_hip_test_macro(HIP.EnableStandard HIPEnableStandard)
|
||||
add_hip_test_macro(HIP.InferHipLang1 HIPInferHipLang1)
|
||||
|
||||
@@ -17,3 +17,7 @@ set_target_properties(MixedStaticLib PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
add_executable(HIPMixedLanguage main.cxx)
|
||||
target_link_libraries(HIPMixedLanguage PRIVATE MixedStaticLib MixedSharedLib)
|
||||
|
||||
add_executable(HIPMixedLanguageCXX main.cxx)
|
||||
target_link_libraries(HIPMixedLanguageCXX PRIVATE MixedStaticLib MixedSharedLib)
|
||||
set_property(TARGET HIPMixedLanguageCXX PROPERTY LINKER_LANGUAGE CXX)
|
||||
|
||||
Reference in New Issue
Block a user