summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-18 18:11:41 (GMT)
committerBrad King <brad.king@kitware.com>2023-09-21 19:34:37 (GMT)
commit127b6fa06bf53ad9f31d041a7d11434ca2856c8e (patch)
tree26f2bdb717a1592b9a31fb6bc1cdff37f42a1373
parent90e23f40ee27c0990b30b3640731e89539cb3990 (diff)
downloadCMake-127b6fa06bf53ad9f31d041a7d11434ca2856c8e.zip
CMake-127b6fa06bf53ad9f31d041a7d11434ca2856c8e.tar.gz
CMake-127b6fa06bf53ad9f31d041a7d11434ca2856c8e.tar.bz2
HIP: Add CMAKE_HIP_PLATFORM variable to specify GPU platform
For now, require the value to be `amd`, since that is the only platform we currently support.
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/prop_tgt/HIP_ARCHITECTURES.rst3
-rw-r--r--Help/release/dev/hip-nvidia.rst6
-rw-r--r--Help/variable/CMAKE_HIP_ARCHITECTURES.rst10
-rw-r--r--Help/variable/CMAKE_HIP_PLATFORM.rst19
-rw-r--r--Modules/CMakeDetermineHIPCompiler.cmake28
-rw-r--r--Source/cmCoreTryCompile.cxx2
-rw-r--r--Tests/HIP/ArchitectureOff/CMakeLists.txt6
-rw-r--r--Tests/HIP/CompileFlags/CMakeLists.txt5
-rw-r--r--Tests/HIP/TryCompile/CMakeLists.txt5
10 files changed, 70 insertions, 15 deletions
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index fa7a90f..536046a 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -590,6 +590,7 @@ Variables for Languages
/variable/CMAKE_Fortran_MODOUT_FLAG
/variable/CMAKE_HIP_ARCHITECTURES
/variable/CMAKE_HIP_EXTENSIONS
+ /variable/CMAKE_HIP_PLATFORM
/variable/CMAKE_HIP_STANDARD
/variable/CMAKE_HIP_STANDARD_REQUIRED
/variable/CMAKE_ISPC_HEADER_DIRECTORY
diff --git a/Help/prop_tgt/HIP_ARCHITECTURES.rst b/Help/prop_tgt/HIP_ARCHITECTURES.rst
index 06f956b..58a813d 100644
--- a/Help/prop_tgt/HIP_ARCHITECTURES.rst
+++ b/Help/prop_tgt/HIP_ARCHITECTURES.rst
@@ -3,7 +3,8 @@ HIP_ARCHITECTURES
.. versionadded:: 3.21
-List of AMD GPU architectures to generate device code for.
+List of GPU architectures to for which to generate device code.
+Architecture names are interpreted based on :variable:`CMAKE_HIP_PLATFORM`.
A non-empty false value (e.g. ``OFF``) disables adding architectures.
This is intended to support packagers and rare cases where full control
diff --git a/Help/release/dev/hip-nvidia.rst b/Help/release/dev/hip-nvidia.rst
new file mode 100644
index 0000000..f4617e7
--- /dev/null
+++ b/Help/release/dev/hip-nvidia.rst
@@ -0,0 +1,6 @@
+hip-nvidia
+----------
+
+* The :variable:`CMAKE_HIP_PLATFORM` variable was added to specify
+ the GPU platform for which HIP language sources are to be compiled
+ (``amd``).
diff --git a/Help/variable/CMAKE_HIP_ARCHITECTURES.rst b/Help/variable/CMAKE_HIP_ARCHITECTURES.rst
index bcc6b35..3f17983 100644
--- a/Help/variable/CMAKE_HIP_ARCHITECTURES.rst
+++ b/Help/variable/CMAKE_HIP_ARCHITECTURES.rst
@@ -3,10 +3,14 @@ CMAKE_HIP_ARCHITECTURES
.. versionadded:: 3.21
-Default value for :prop_tgt:`HIP_ARCHITECTURES` property of targets.
+List of GPU architectures to for which to generate device code.
+Architecture names are interpreted based on :variable:`CMAKE_HIP_PLATFORM`.
-This is initialized to the architectures reported by ``rocm_agent_enumerator``,
-if available, and otherwise to the default chosen by the compiler.
+This is initialized based on the value of :variable:`CMAKE_HIP_PLATFORM`:
+
+``amd``
+ Uses architectures reported by ``rocm_agent_enumerator``, if available,
+ and otherwise to a default chosen by the compiler.
This variable is used to initialize the :prop_tgt:`HIP_ARCHITECTURES` property
on all targets. See the target property for additional information.
diff --git a/Help/variable/CMAKE_HIP_PLATFORM.rst b/Help/variable/CMAKE_HIP_PLATFORM.rst
new file mode 100644
index 0000000..1715066
--- /dev/null
+++ b/Help/variable/CMAKE_HIP_PLATFORM.rst
@@ -0,0 +1,19 @@
+CMAKE_HIP_PLATFORM
+------------------
+
+.. versionadded:: 3.28
+
+GPU platform for which HIP language sources are to be compiled.
+
+The value must be one of:
+
+``amd``
+ AMD GPUs
+
+If not specified, the default is ``amd``.
+
+:variable:`CMAKE_HIP_ARCHITECTURES` entries are interpreted with
+as architectures of the GPU platform.
+
+:variable:`CMAKE_HIP_COMPILER <CMAKE_<LANG>_COMPILER>` must target
+the same GPU platform.
diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake
index 9a40e82..e55648a 100644
--- a/Modules/CMakeDetermineHIPCompiler.cmake
+++ b/Modules/CMakeDetermineHIPCompiler.cmake
@@ -10,6 +10,16 @@ if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR
message(FATAL_ERROR "HIP language not currently supported by \"${CMAKE_GENERATOR}\" generator")
endif()
+if(NOT CMAKE_HIP_PLATFORM)
+ set(CMAKE_HIP_PLATFORM "amd" CACHE STRING "HIP platform" FORCE)
+endif()
+if(NOT CMAKE_HIP_PLATFORM MATCHES "^(amd)$")
+ message(FATAL_ERROR
+ "The CMAKE_HIP_PLATFORM has unsupported value:\n"
+ " '${CMAKE_HIP_PLATFORM}'\n"
+ "It must be 'amd'."
+ )
+endif()
if(NOT CMAKE_HIP_COMPILER)
set(CMAKE_HIP_COMPILER_INIT NOTFOUND)
@@ -34,15 +44,17 @@ if(NOT CMAKE_HIP_COMPILER)
# finally list compilers to try
if(NOT CMAKE_HIP_COMPILER_INIT)
- set(CMAKE_HIP_COMPILER_LIST clang++)
+ if(CMAKE_HIP_PLATFORM STREQUAL "amd")
+ set(CMAKE_HIP_COMPILER_LIST clang++)
- # Look for the Clang coming with ROCm to support HIP.
- execute_process(COMMAND hipconfig --hipclangpath
- OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH
- RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT
- )
- if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
- set(CMAKE_HIP_COMPILER_HINTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
+ # Look for the Clang coming with ROCm to support HIP.
+ execute_process(COMMAND hipconfig --hipclangpath
+ OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH
+ RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT
+ )
+ if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
+ set(CMAKE_HIP_COMPILER_HINTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
+ endif()
endif()
endif()
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 2ec62d9..0674d5a 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -78,6 +78,7 @@ std::string const kCMAKE_EXECUTABLE_ENABLE_EXPORTS =
std::string const kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS =
"CMAKE_SHARED_LIBRARY_ENABLE_EXPORTS";
std::string const kCMAKE_HIP_ARCHITECTURES = "CMAKE_HIP_ARCHITECTURES";
+std::string const kCMAKE_HIP_PLATFORM = "CMAKE_HIP_PLATFORM";
std::string const kCMAKE_HIP_RUNTIME_LIBRARY = "CMAKE_HIP_RUNTIME_LIBRARY";
std::string const kCMAKE_ISPC_INSTRUCTION_SETS = "CMAKE_ISPC_INSTRUCTION_SETS";
std::string const kCMAKE_ISPC_HEADER_SUFFIX = "CMAKE_ISPC_HEADER_SUFFIX";
@@ -1081,6 +1082,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
vars.insert(kCMAKE_EXECUTABLE_ENABLE_EXPORTS);
vars.insert(kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS);
vars.insert(kCMAKE_HIP_ARCHITECTURES);
+ vars.insert(kCMAKE_HIP_PLATFORM);
vars.insert(kCMAKE_HIP_RUNTIME_LIBRARY);
vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS);
vars.insert(kCMAKE_ISPC_HEADER_SUFFIX);
diff --git a/Tests/HIP/ArchitectureOff/CMakeLists.txt b/Tests/HIP/ArchitectureOff/CMakeLists.txt
index b40301a..9d0bf05 100644
--- a/Tests/HIP/ArchitectureOff/CMakeLists.txt
+++ b/Tests/HIP/ArchitectureOff/CMakeLists.txt
@@ -3,7 +3,11 @@ project(HIPArchitecture HIP)
# Make sure CMake doesn't pass architectures if HIP_ARCHITECTURES is OFF.
set(CMAKE_HIP_ARCHITECTURES OFF)
-string(APPEND CMAKE_HIP_FLAGS " --offload-arch=gfx908")
+
+# Pass our own architecture flags instead.
+if(CMAKE_HIP_PLATFORM STREQUAL "amd")
+ string(APPEND CMAKE_HIP_FLAGS " --offload-arch=gfx908")
+endif()
add_executable(HIPOnlyArchitectureOff main.hip)
get_property(hip_archs TARGET HIPOnlyArchitectureOff PROPERTY HIP_ARCHITECTURES)
diff --git a/Tests/HIP/CompileFlags/CMakeLists.txt b/Tests/HIP/CompileFlags/CMakeLists.txt
index c808313..46a94a3 100644
--- a/Tests/HIP/CompileFlags/CMakeLists.txt
+++ b/Tests/HIP/CompileFlags/CMakeLists.txt
@@ -3,6 +3,9 @@ project(CompileFlags HIP)
add_executable(HIPOnlyCompileFlags main.hip)
-set_property(TARGET HIPOnlyCompileFlags PROPERTY HIP_ARCHITECTURES gfx803)
+if(CMAKE_HIP_PLATFORM STREQUAL "amd")
+ set(hip_archs gfx803)
+endif()
+set_property(TARGET HIPOnlyCompileFlags PROPERTY HIP_ARCHITECTURES ${hip_archs})
target_compile_options(HIPOnlyCompileFlags PRIVATE -DALWAYS_DEFINE)
diff --git a/Tests/HIP/TryCompile/CMakeLists.txt b/Tests/HIP/TryCompile/CMakeLists.txt
index 92a834c..c98e59c 100644
--- a/Tests/HIP/TryCompile/CMakeLists.txt
+++ b/Tests/HIP/TryCompile/CMakeLists.txt
@@ -4,7 +4,10 @@ project (TryCompile HIP)
#Goal for this example:
# Verify try_compile with HIP language works
set(CMAKE_HIP_STANDARD 14)
-set(CMAKE_HIP_ARCHITECTURES gfx803 gfx900)
+
+if(CMAKE_HIP_PLATFORM STREQUAL "amd")
+ set(CMAKE_HIP_ARCHITECTURES gfx803 gfx900)
+endif()
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"