summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-26 13:40:18 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-09-26 13:40:25 (GMT)
commit5d32320bf33bc874d0f0e0c651235fe6472c8013 (patch)
tree92b397f5d36a1ea9998ac125eac7c5de5487766b
parentccd53590033a32f02319ec09d2cf5e8c11c7e62c (diff)
parentfd982eec10840eabcccc1920c7c32eb0a13d65a9 (diff)
downloadCMake-5d32320bf33bc874d0f0e0c651235fe6472c8013.zip
CMake-5d32320bf33bc874d0f0e0c651235fe6472c8013.tar.gz
CMake-5d32320bf33bc874d0f0e0c651235fe6472c8013.tar.bz2
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
-rw-r--r--Help/envvar/CUDAHOSTCXX.rst6
-rw-r--r--Help/envvar/HIPHOSTCXX.rst19
-rw-r--r--Help/manual/cmake-env-variables.7.rst1
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/variable/CMAKE_CUDA_HOST_COMPILER.rst34
-rw-r--r--Help/variable/CMAKE_LANG_HOST_COMPILER.rst44
-rw-r--r--Modules/CMakeDetermineCompilerABI.cmake8
-rw-r--r--Modules/CMakeDetermineHIPCompiler.cmake108
-rw-r--r--Modules/CheckLanguage.cmake14
-rw-r--r--Modules/Compiler/NVIDIA-HIP.cmake6
-rw-r--r--Source/cmCoreTryCompile.cxx14
-rw-r--r--Tests/CMakeOnly/CheckLanguage/CMakeLists.txt2
-rw-r--r--Tests/HIP/ArchSpecial/CMakeLists.txt66
-rw-r--r--Tests/HIP/ArchSpecial/main.hip3
-rw-r--r--Tests/HIP/CMakeLists.txt3
-rw-r--r--Tests/HIP/MixedLanguage/CMakeLists.txt4
16 files changed, 233 insertions, 100 deletions
diff --git a/Help/envvar/CUDAHOSTCXX.rst b/Help/envvar/CUDAHOSTCXX.rst
index 74f5d48..4e78afa 100644
--- a/Help/envvar/CUDAHOSTCXX.rst
+++ b/Help/envvar/CUDAHOSTCXX.rst
@@ -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.
diff --git a/Help/envvar/HIPHOSTCXX.rst b/Help/envvar/HIPHOSTCXX.rst
new file mode 100644
index 0000000..871fbfb
--- /dev/null
+++ b/Help/envvar/HIPHOSTCXX.rst
@@ -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`.
diff --git a/Help/manual/cmake-env-variables.7.rst b/Help/manual/cmake-env-variables.7.rst
index 356e73d..55f07b7 100644
--- a/Help/manual/cmake-env-variables.7.rst
+++ b/Help/manual/cmake-env-variables.7.rst
@@ -84,6 +84,7 @@ Environment Variables for Languages
/envvar/FFLAGS
/envvar/HIPCXX
/envvar/HIPFLAGS
+ /envvar/HIPHOSTCXX
/envvar/ISPC
/envvar/ISPCFLAGS
/envvar/OBJC
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 536046a..d9df773 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -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
diff --git a/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst b/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst
index 6e2d756..498e2e5 100644
--- a/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst
+++ b/Help/variable/CMAKE_CUDA_HOST_COMPILER.rst
@@ -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.
diff --git a/Help/variable/CMAKE_LANG_HOST_COMPILER.rst b/Help/variable/CMAKE_LANG_HOST_COMPILER.rst
new file mode 100644
index 0000000..cf3ba62
--- /dev/null
+++ b/Help/variable/CMAKE_LANG_HOST_COMPILER.rst
@@ -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`.
diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake
index 13bfeec..7d8fa19 100644
--- a/Modules/CMakeDetermineCompilerABI.cmake
+++ b/Modules/CMakeDetermineCompilerABI.cmake
@@ -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
diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake
index 21322f1..e667099 100644
--- a/Modules/CMakeDetermineHIPCompiler.cmake
+++ b/Modules/CMakeDetermineHIPCompiler.cmake
@@ -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)
+if(CMAKE_HIP_PLATFORM STREQUAL "amd")
+ # For this platform 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.
+ 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 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(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"
- )
+ "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)
diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake
index 04e721c..94948b9 100644
--- a/Modules/CheckLanguage.cmake
+++ b/Modules/CheckLanguage.cmake
@@ -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()
diff --git a/Modules/Compiler/NVIDIA-HIP.cmake b/Modules/Compiler/NVIDIA-HIP.cmake
index e144ff8..c888bc7 100644
--- a/Modules/Compiler/NVIDIA-HIP.cmake
+++ b/Modules/Compiler/NVIDIA-HIP.cmake
@@ -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")
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 0674d5a..ee40bd5 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -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");
diff --git a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
index 0c76158..f005843 100644
--- a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
+++ b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
@@ -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()
diff --git a/Tests/HIP/ArchSpecial/CMakeLists.txt b/Tests/HIP/ArchSpecial/CMakeLists.txt
new file mode 100644
index 0000000..2bc6bd2
--- /dev/null
+++ b/Tests/HIP/ArchSpecial/CMakeLists.txt
@@ -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()
diff --git a/Tests/HIP/ArchSpecial/main.hip b/Tests/HIP/ArchSpecial/main.hip
new file mode 100644
index 0000000..5047a34
--- /dev/null
+++ b/Tests/HIP/ArchSpecial/main.hip
@@ -0,0 +1,3 @@
+int main()
+{
+}
diff --git a/Tests/HIP/CMakeLists.txt b/Tests/HIP/CMakeLists.txt
index 26d7459..f1e2e51 100644
--- a/Tests/HIP/CMakeLists.txt
+++ b/Tests/HIP/CMakeLists.txt
@@ -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)
diff --git a/Tests/HIP/MixedLanguage/CMakeLists.txt b/Tests/HIP/MixedLanguage/CMakeLists.txt
index 4f6dd3b..af58ade 100644
--- a/Tests/HIP/MixedLanguage/CMakeLists.txt
+++ b/Tests/HIP/MixedLanguage/CMakeLists.txt
@@ -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)