mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 06:09:52 -06:00
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.
This commit is contained in:
@@ -590,6 +590,7 @@ Variables for Languages
|
|||||||
/variable/CMAKE_Fortran_MODOUT_FLAG
|
/variable/CMAKE_Fortran_MODOUT_FLAG
|
||||||
/variable/CMAKE_HIP_ARCHITECTURES
|
/variable/CMAKE_HIP_ARCHITECTURES
|
||||||
/variable/CMAKE_HIP_EXTENSIONS
|
/variable/CMAKE_HIP_EXTENSIONS
|
||||||
|
/variable/CMAKE_HIP_PLATFORM
|
||||||
/variable/CMAKE_HIP_STANDARD
|
/variable/CMAKE_HIP_STANDARD
|
||||||
/variable/CMAKE_HIP_STANDARD_REQUIRED
|
/variable/CMAKE_HIP_STANDARD_REQUIRED
|
||||||
/variable/CMAKE_ISPC_HEADER_DIRECTORY
|
/variable/CMAKE_ISPC_HEADER_DIRECTORY
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ HIP_ARCHITECTURES
|
|||||||
|
|
||||||
.. versionadded:: 3.21
|
.. 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.
|
A non-empty false value (e.g. ``OFF``) disables adding architectures.
|
||||||
This is intended to support packagers and rare cases where full control
|
This is intended to support packagers and rare cases where full control
|
||||||
|
|||||||
6
Help/release/dev/hip-nvidia.rst
Normal file
6
Help/release/dev/hip-nvidia.rst
Normal file
@@ -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``).
|
||||||
@@ -3,10 +3,14 @@ CMAKE_HIP_ARCHITECTURES
|
|||||||
|
|
||||||
.. versionadded:: 3.21
|
.. 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``,
|
This is initialized based on the value of :variable:`CMAKE_HIP_PLATFORM`:
|
||||||
if available, and otherwise to the default chosen by the compiler.
|
|
||||||
|
``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
|
This variable is used to initialize the :prop_tgt:`HIP_ARCHITECTURES` property
|
||||||
on all targets. See the target property for additional information.
|
on all targets. See the target property for additional information.
|
||||||
|
|||||||
19
Help/variable/CMAKE_HIP_PLATFORM.rst
Normal file
19
Help/variable/CMAKE_HIP_PLATFORM.rst
Normal file
@@ -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.
|
||||||
@@ -10,6 +10,16 @@ if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR
|
|||||||
message(FATAL_ERROR "HIP language not currently supported by \"${CMAKE_GENERATOR}\" generator")
|
message(FATAL_ERROR "HIP language not currently supported by \"${CMAKE_GENERATOR}\" generator")
|
||||||
endif()
|
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)
|
if(NOT CMAKE_HIP_COMPILER)
|
||||||
set(CMAKE_HIP_COMPILER_INIT NOTFOUND)
|
set(CMAKE_HIP_COMPILER_INIT NOTFOUND)
|
||||||
@@ -34,15 +44,17 @@ if(NOT CMAKE_HIP_COMPILER)
|
|||||||
|
|
||||||
# finally list compilers to try
|
# finally list compilers to try
|
||||||
if(NOT CMAKE_HIP_COMPILER_INIT)
|
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.
|
# Look for the Clang coming with ROCm to support HIP.
|
||||||
execute_process(COMMAND hipconfig --hipclangpath
|
execute_process(COMMAND hipconfig --hipclangpath
|
||||||
OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH
|
OUTPUT_VARIABLE _CMAKE_HIPCONFIG_CLANGPATH
|
||||||
RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT
|
RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT
|
||||||
)
|
)
|
||||||
if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
|
if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
|
||||||
set(CMAKE_HIP_COMPILER_HINTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
|
set(CMAKE_HIP_COMPILER_HINTS "${_CMAKE_HIPCONFIG_CLANGPATH}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ std::string const kCMAKE_EXECUTABLE_ENABLE_EXPORTS =
|
|||||||
std::string const kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS =
|
std::string const kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS =
|
||||||
"CMAKE_SHARED_LIBRARY_ENABLE_EXPORTS";
|
"CMAKE_SHARED_LIBRARY_ENABLE_EXPORTS";
|
||||||
std::string const kCMAKE_HIP_ARCHITECTURES = "CMAKE_HIP_ARCHITECTURES";
|
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_HIP_RUNTIME_LIBRARY = "CMAKE_HIP_RUNTIME_LIBRARY";
|
||||||
std::string const kCMAKE_ISPC_INSTRUCTION_SETS = "CMAKE_ISPC_INSTRUCTION_SETS";
|
std::string const kCMAKE_ISPC_INSTRUCTION_SETS = "CMAKE_ISPC_INSTRUCTION_SETS";
|
||||||
std::string const kCMAKE_ISPC_HEADER_SUFFIX = "CMAKE_ISPC_HEADER_SUFFIX";
|
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_EXECUTABLE_ENABLE_EXPORTS);
|
||||||
vars.insert(kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS);
|
vars.insert(kCMAKE_SHARED_LIBRARY_ENABLE_EXPORTS);
|
||||||
vars.insert(kCMAKE_HIP_ARCHITECTURES);
|
vars.insert(kCMAKE_HIP_ARCHITECTURES);
|
||||||
|
vars.insert(kCMAKE_HIP_PLATFORM);
|
||||||
vars.insert(kCMAKE_HIP_RUNTIME_LIBRARY);
|
vars.insert(kCMAKE_HIP_RUNTIME_LIBRARY);
|
||||||
vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS);
|
vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS);
|
||||||
vars.insert(kCMAKE_ISPC_HEADER_SUFFIX);
|
vars.insert(kCMAKE_ISPC_HEADER_SUFFIX);
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ project(HIPArchitecture HIP)
|
|||||||
|
|
||||||
# Make sure CMake doesn't pass architectures if HIP_ARCHITECTURES is OFF.
|
# Make sure CMake doesn't pass architectures if HIP_ARCHITECTURES is OFF.
|
||||||
set(CMAKE_HIP_ARCHITECTURES 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)
|
add_executable(HIPOnlyArchitectureOff main.hip)
|
||||||
get_property(hip_archs TARGET HIPOnlyArchitectureOff PROPERTY HIP_ARCHITECTURES)
|
get_property(hip_archs TARGET HIPOnlyArchitectureOff PROPERTY HIP_ARCHITECTURES)
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ project(CompileFlags HIP)
|
|||||||
|
|
||||||
add_executable(HIPOnlyCompileFlags main.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)
|
target_compile_options(HIPOnlyCompileFlags PRIVATE -DALWAYS_DEFINE)
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ project (TryCompile HIP)
|
|||||||
#Goal for this example:
|
#Goal for this example:
|
||||||
# Verify try_compile with HIP language works
|
# Verify try_compile with HIP language works
|
||||||
set(CMAKE_HIP_STANDARD 14)
|
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)
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
|
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
|||||||
Reference in New Issue
Block a user