From 735f41fc2d91bac11506ebf355136b0dbd8ac8c7 Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Wed, 15 Sep 2021 16:33:41 -0400 Subject: HIP: Use 'rocm_agent_enumerator' to determine CMAKE_HIP_ARCHITECTURES --- Help/variable/CMAKE_HIP_ARCHITECTURES.rst | 3 ++- Modules/CMakeDetermineHIPCompiler.cmake | 37 ++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Help/variable/CMAKE_HIP_ARCHITECTURES.rst b/Help/variable/CMAKE_HIP_ARCHITECTURES.rst index 0cf0201..bcc6b35 100644 --- a/Help/variable/CMAKE_HIP_ARCHITECTURES.rst +++ b/Help/variable/CMAKE_HIP_ARCHITECTURES.rst @@ -5,7 +5,8 @@ CMAKE_HIP_ARCHITECTURES Default value for :prop_tgt:`HIP_ARCHITECTURES` property of targets. -This is initialized to the default architecture chosen by the compiler. +This is initialized to the architectures reported by ``rocm_agent_enumerator``, +if available, and otherwise to the 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/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index ed0110a..4f0b754 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -85,12 +85,43 @@ if(MSVC_HIP_ARCHITECTURE_ID) endif() if(NOT DEFINED CMAKE_HIP_ARCHITECTURES) - # Analyze output from hipcc to get the current GPU architecture. - if(CMAKE_HIP_COMPILER_PRODUCED_OUTPUT MATCHES " -target-cpu ([a-z0-9]+) ") + # Use 'rocm_agent_enumerator' to get the current GPU architecture. + set(_CMAKE_HIP_ARCHITECTURES) + find_program(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR + NAMES rocm_agent_enumerator + NO_CACHE) + if(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR) + execute_process(COMMAND "${_CMAKE_HIP_ROCM_AGENT_ENUMERATOR}" -t GPU + RESULT_VARIABLE _CMAKE_ROCM_AGENT_ENUMERATOR_RESULT + OUTPUT_VARIABLE _CMAKE_ROCM_AGENT_ENUMERATOR_STDOUT + ERROR_VARIABLE _CMAKE_ROCM_AGENT_ENUMERATOR_STDERR + ) + if(_CMAKE_ROCM_AGENT_ENUMERATOR_RESULT EQUAL 0) + separate_arguments(_hip_archs NATIVE_COMMAND "${_CMAKE_ROCM_AGENT_ENUMERATOR_STDOUT}") + foreach(_hip_arch ${_hip_archs}) + if(_hip_arch STREQUAL "gfx000") + continue() + endif() + string(FIND ${_hip_arch} ":" pos) + if(NOT pos STREQUAL "-1") + string(SUBSTRING ${_hip_arch} 0 ${pos} _hip_arch) + endif() + list(APPEND _CMAKE_HIP_ARCHITECTURES "${_hip_arch}") + endforeach() + endif() + unset(_CMAKE_ROCM_AGENT_ENUMERATOR_RESULT) + unset(_CMAKE_ROCM_AGENT_ENUMERATOR_STDOUT) + unset(_CMAKE_ROCM_AGENT_ENUMERATOR_STDERR) + endif() + unset(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR) + if(_CMAKE_HIP_ARCHITECTURES) + set(CMAKE_HIP_ARCHITECTURES "${_CMAKE_HIP_ARCHITECTURES}" CACHE STRING "HIP architectures") + elseif(CMAKE_HIP_COMPILER_PRODUCED_OUTPUT MATCHES " -target-cpu ([a-z0-9]+) ") set(CMAKE_HIP_ARCHITECTURES "${CMAKE_MATCH_1}" CACHE STRING "HIP architectures") else() - message(FATAL_ERROR "Failed to find a working HIP architecture.") + message(FATAL_ERROR "Failed to find a default HIP architecture.") endif() + unset(_CMAKE_HIP_ARCHITECTURES) endif() # configure variables set in this file for fast reload later on -- cgit v0.12 From b125e9809a1a3f3e28fc1682c8a33c3a928f79b5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 16 Sep 2021 13:36:40 -0400 Subject: HIP: Detect ROCm path earlier Fail early if it is not found. Use the detected location as a hint to find `rocm_agent_enumerator`. Also remove the leading `_` prefix in case we want to document this publicly later. --- Modules/CMakeDetermineCompilerId.cmake | 11 ----------- Modules/CMakeDetermineHIPCompiler.cmake | 14 ++++++++++++++ Modules/CMakeHIPRuntime.cmake.in | 8 ++++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index e933cf4..65e7236 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -172,17 +172,6 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_${lang}_COMPILER "${output}/clang++" PARENT_SCOPE) endif() endif() - if(lang STREQUAL "HIP") - execute_process( - COMMAND "${_hipcc_dir}/hipconfig" - --rocmpath - OUTPUT_VARIABLE output - RESULT_VARIABLE result - ) - if(result EQUAL 0) - set(_CMAKE_HIP_COMPILER_ROCM_ROOT "${output}" PARENT_SCOPE) - endif() - endif() endif() if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index 4f0b754..394f8e2 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -52,7 +52,20 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN) CMAKE_DETERMINE_COMPILER_ID(HIP HIPFLAGS CMakeHIPCompilerId.hip) _cmake_find_compiler_sysroot(HIP) +endif() +if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT) + execute_process( + COMMAND hipconfig --rocmpath + OUTPUT_VARIABLE _CMAKE_HIPCONFIG_ROCMPATH + RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT + ) + if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_ROCMPATH}") + set(CMAKE_HIP_COMPILER_ROCM_ROOT "${_CMAKE_HIPCONFIG_ROCMPATH}") + endif() +endif() +if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT) + message(FATAL_ERROR "Failed to find ROCm root directory.") endif() if (NOT _CMAKE_TOOLCHAIN_LOCATION) @@ -89,6 +102,7 @@ if(NOT DEFINED CMAKE_HIP_ARCHITECTURES) set(_CMAKE_HIP_ARCHITECTURES) find_program(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR NAMES rocm_agent_enumerator + HINTS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/bin" NO_CACHE) if(_CMAKE_HIP_ROCM_AGENT_ENUMERATOR) execute_process(COMMAND "${_CMAKE_HIP_ROCM_AGENT_ENUMERATOR}" -t GPU diff --git a/Modules/CMakeHIPRuntime.cmake.in b/Modules/CMakeHIPRuntime.cmake.in index ade26bb..3b345aa 100644 --- a/Modules/CMakeHIPRuntime.cmake.in +++ b/Modules/CMakeHIPRuntime.cmake.in @@ -4,7 +4,7 @@ function(_CMAKE_FIND_HIP_RUNTIME ) # Determined when hipcc is the HIP compiler - set(_CMAKE_HIP_COMPILER_ROCM_ROOT "@_CMAKE_HIP_COMPILER_ROCM_ROOT@") + set(CMAKE_HIP_COMPILER_ROCM_ROOT "@CMAKE_HIP_COMPILER_ROCM_ROOT@") # Forward facing value that can be provided by the user set(CMAKE_HIP_COMPILER_TOOLKIT_ROOT @CMAKE_HIP_COMPILER_TOOLKIT_ROOT@) @@ -24,10 +24,10 @@ function(_CMAKE_FIND_HIP_RUNTIME ) set(explicit_search_only TRUE) set(error_message_location "CMAKE_HIP_COMPILER_TOOLKIT_ROOT") set(error_message_location "the environment variable CMAKE_HIP_COMPILER_TOOLKIT_ROOT [\"$ENV{CMAKE_HIP_COMPILER_TOOLKIT_ROOT}\"]") - elseif(DEFINED _CMAKE_HIP_COMPILER_ROCM_ROOT) - set(rocm_root_dirs "${_CMAKE_HIP_COMPILER_ROCM_ROOT}") + elseif(DEFINED CMAKE_HIP_COMPILER_ROCM_ROOT) + set(rocm_root_dirs "${CMAKE_HIP_COMPILER_ROCM_ROOT}") set(explicit_search_only TRUE) - set(error_message_location "the associated hipconfig --rocmpath [\"${_CMAKE_HIP_COMPILER_ROCM_ROOT}\"]") + set(error_message_location "the associated hipconfig --rocmpath [\"${CMAKE_HIP_COMPILER_ROCM_ROOT}\"]") endif() # Guess on where rocm is installed -- cgit v0.12 From a71f0fc9c7762a06d0bfdd64d0d490919e12357a Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 13 Sep 2021 17:31:28 +0000 Subject: HIP: Remove ROMClang compiler id and use Clang directly Since commit bd844387df (ROCMClang: Add the ROCm toolkit derived clang compiler to CMake, 2020-08-28, v3.21.0-rc1~66^2~6) and commit ff0d2858e1 (HIP: Extract clang compiler details from hipcc, 2020-10-21, v3.21.0-rc1~66^2~5), the separate `ROCMClang` compiler id for `hipcc` has caused a few problems: * The compiler id changed from behavior of CMake 3.20 and below, breaking projects that already built with `hipcc` treated as `Clang`. * The implementation of `target_compile_features` was incomplete for the `ROCMClang` identity. * Only `hipcc` was identified as `ROCMClang`, so after it is unwrapped to the underlying `clang++`, future runs of new CMake versions on an existing build tree would not repeat this. * Clang should be usable as a HIP compiler without the `hipcc` wrapper. Remove the `ROMClang` compiler identity, and revise HIP language support to work directly with a Clang compiler. Reject direct `hipcc` usage as a HIP compiler. For now it cannot be supported because it interferes with flags CMake needs to pass to Clang. Fixes: #22536, #22460, #22593 --- Help/release/3.21.rst | 10 +++++ Help/variable/CMAKE_LANG_COMPILER_ID.rst | 1 - Modules/CMakeCompilerIdDetection.cmake | 3 -- Modules/CMakeDetermineCompiler.cmake | 2 +- Modules/CMakeDetermineCompilerId.cmake | 24 ----------- Modules/CMakeDetermineHIPCompiler.cmake | 24 ++++++++++- Modules/Compiler/ROCMClang-ASM.cmake | 2 - Modules/Compiler/ROCMClang-C.cmake | 7 ---- Modules/Compiler/ROCMClang-CXX.cmake | 7 ---- Modules/Compiler/ROCMClang-DetermineCompiler.cmake | 19 --------- Modules/Compiler/ROCMClang-FindBinUtils.cmake | 1 - Modules/Compiler/ROCMClang-HIP.cmake | 49 ---------------------- Modules/Compiler/ROCMClang-OBJC.cmake | 7 ---- Modules/Compiler/ROCMClang-OBJCXX.cmake | 7 ---- Modules/Compiler/ROCMClang.cmake | 35 ---------------- Modules/WriteCompilerDetectionHeader.cmake | 1 - Tests/HIP/WithDefs/CMakeLists.txt | 2 +- 17 files changed, 35 insertions(+), 166 deletions(-) delete mode 100644 Modules/Compiler/ROCMClang-ASM.cmake delete mode 100644 Modules/Compiler/ROCMClang-C.cmake delete mode 100644 Modules/Compiler/ROCMClang-CXX.cmake delete mode 100644 Modules/Compiler/ROCMClang-DetermineCompiler.cmake delete mode 100644 Modules/Compiler/ROCMClang-FindBinUtils.cmake delete mode 100644 Modules/Compiler/ROCMClang-HIP.cmake delete mode 100644 Modules/Compiler/ROCMClang-OBJC.cmake delete mode 100644 Modules/Compiler/ROCMClang-OBJCXX.cmake delete mode 100644 Modules/Compiler/ROCMClang.cmake diff --git a/Help/release/3.21.rst b/Help/release/3.21.rst index 5d8c200..a468817 100644 --- a/Help/release/3.21.rst +++ b/Help/release/3.21.rst @@ -319,3 +319,13 @@ Changes made since CMake 3.21.0 include the following. * The :generator:`Visual Studio 17 2022` generator is now based on "Visual Studio 2022 Preview 4". Previously it was based on "Preview 3.1". + +* The AMD ROCm Platform ``hipcc`` compiler was identifed by CMake 3.21.0 + through 3.21.2 as a distinct compiler with id ``ROCMClang``. This has + been removed because it caused regressions. Instead: + + * ``hipcc`` may no longer be used as a ``HIP`` compiler because it + interferes with flags CMake needs to pass to Clang. Use Clang directly. + + * ``hipcc`` may once again be used as a ``CXX`` compiler, and is treated as + whatever compiler it selects underneath, as CMake 3.20 and below did. diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst index f23b7a2..0abedde 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst +++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst @@ -34,7 +34,6 @@ include: OpenWatcom = Open Watcom (openwatcom.org) PGI = The Portland Group (pgroup.com) PathScale = PathScale (pathscale.com) - ROCMClang = ROCm Toolkit Clang-based Compiler (rocmdocs.amd.com) SDCC = Small Device C Compiler (sdcc.sourceforge.net) SunPro = Oracle Solaris Studio (oracle.com) TI = Texas Instruments (ti.com) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index dd70d82..e6b3ee3 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -82,9 +82,6 @@ function(compiler_id_detection outvar lang) AppleClang ARMClang ) - if(NOT __skip_rocmclang) - list(APPEND ordered_compilers ROCMClang) - endif() list(APPEND ordered_compilers Clang GNU diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index 6430793..c967ab7 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -32,7 +32,7 @@ macro(_cmake_find_compiler lang) endif() # Look for directories containing compilers of reference languages. - set(_${lang}_COMPILER_HINTS) + set(_${lang}_COMPILER_HINTS "${CMAKE_${lang}_COMPILER_HINTS}") foreach(l ${_languages}) if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}") get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 65e7236..30b4aec 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -150,30 +150,6 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endif() - # When invoked with HIPCC we need to extract the path to the underlying - # clang compiler when possible. This fixes the following issues: - # env variables can change how hipcc behaves - # allows us to properly find the binutils bundled with hip - if(CMAKE_${lang}_COMPILER_ID STREQUAL "ROCMClang" - AND CMAKE_${lang}_COMPILER MATCHES ".*hipcc") - get_filename_component(_hipcc_dir "${CMAKE_${lang}_COMPILER}" DIRECTORY) - execute_process( - COMMAND "${_hipcc_dir}/hipconfig" - --hipclangpath - OUTPUT_VARIABLE output - RESULT_VARIABLE result - ) - if(result EQUAL 0 AND EXISTS "${output}") - if(lang STREQUAL "C") - set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${output}/clang") - set(CMAKE_${lang}_COMPILER "${output}/clang" PARENT_SCOPE) - else() - set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${output}/clang++") - set(CMAKE_${lang}_COMPILER "${output}/clang++" PARENT_SCOPE) - endif() - endif() - endif() - if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index 394f8e2..5c8849e 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -15,6 +15,13 @@ if(NOT CMAKE_HIP_COMPILER) # prefer the environment variable HIPCXX if(NOT $ENV{HIPCXX} STREQUAL "") + if("$ENV{HIPCXX}" MATCHES "hipcc") + message(FATAL_ERROR + "The HIPCXX environment variable is set to the hipcc wrapper:\n" + " $ENV{HIPCXX}\n" + "This is not supported. Use Clang directly, or let CMake pick a default." + ) + endif() get_filename_component(CMAKE_HIP_COMPILER_INIT $ENV{HIPCXX} PROGRAM PROGRAM_ARGS CMAKE_HIP_FLAGS_ENV_INIT) if(CMAKE_HIP_FLAGS_ENV_INIT) set(CMAKE_HIP_COMPILER_ARG1 "${CMAKE_HIP_FLAGS_ENV_INIT}" CACHE STRING "Arguments to CXX compiler") @@ -26,10 +33,25 @@ if(NOT CMAKE_HIP_COMPILER) # finally list compilers to try if(NOT CMAKE_HIP_COMPILER_INIT) - set(CMAKE_HIP_COMPILER_LIST hipcc clang++) + 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}") + endif() endif() _cmake_find_compiler(HIP) +elseif(CMAKE_HIP_COMPILER MATCHES "hipcc") + message(FATAL_ERROR + "CMAKE_HIP_COMPILER is set to the hipcc wrapper:\n" + " ${CMAKE_HIP_COMPILER}\n" + "This is not supported. Use Clang directly, or let CMake pick a default." + ) else() _cmake_find_compiler_path(HIP) endif() diff --git a/Modules/Compiler/ROCMClang-ASM.cmake b/Modules/Compiler/ROCMClang-ASM.cmake deleted file mode 100644 index 85d1110..0000000 --- a/Modules/Compiler/ROCMClang-ASM.cmake +++ /dev/null @@ -1,2 +0,0 @@ -include(Compiler/ROCMClang) -__compiler_rocmclang(ASM) diff --git a/Modules/Compiler/ROCMClang-C.cmake b/Modules/Compiler/ROCMClang-C.cmake deleted file mode 100644 index cdfa95d..0000000 --- a/Modules/Compiler/ROCMClang-C.cmake +++ /dev/null @@ -1,7 +0,0 @@ -include(Compiler/ROCMClang) -__compiler_rocmclang(C) - -set(_rocm_clang_ver "${CMAKE_C_COMPILER_VERSION_INTERNAL}") -set(CMAKE_C_COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION_INTERNAL}") -include(Compiler/Clang-C) -set(CMAKE_C_COMPILER_VERSION "${_rocm_clang_ver}") diff --git a/Modules/Compiler/ROCMClang-CXX.cmake b/Modules/Compiler/ROCMClang-CXX.cmake deleted file mode 100644 index 5739c8e..0000000 --- a/Modules/Compiler/ROCMClang-CXX.cmake +++ /dev/null @@ -1,7 +0,0 @@ -include(Compiler/ROCMClang) -__compiler_rocmclang(CXX) - -set(_rocm_clang_ver "${CMAKE_CXX_COMPILER_VERSION_INTERNAL}") -set(CMAKE_CXX_COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION_INTERNAL}") -include(Compiler/Clang-CXX) -set(CMAKE_CXX_COMPILER_VERSION "${_rocm_clang_ver}") diff --git a/Modules/Compiler/ROCMClang-DetermineCompiler.cmake b/Modules/Compiler/ROCMClang-DetermineCompiler.cmake deleted file mode 100644 index c2fc99b..0000000 --- a/Modules/Compiler/ROCMClang-DetermineCompiler.cmake +++ /dev/null @@ -1,19 +0,0 @@ - -set(_compiler_id_pp_test "defined(__clang__) && __has_include()") - -set(_compiler_id_version_compute " -# if defined(__clang__) && __has_include() -# include -# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(HIP_VERSION_MAJOR) -# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(HIP_VERSION_MINOR) -# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(HIP_VERSION_PATCH) -# endif") - -set(_compiler_id_simulate " -# if defined(_MSC_VER) -# define @PREFIX@SIMULATE_ID \"MSVC\" -# elif defined(__clang__) -# define @PREFIX@SIMULATE_ID \"Clang\" -# elif defined(__GNUC__) -# define @PREFIX@SIMULATE_ID \"GNU\" -# endif") diff --git a/Modules/Compiler/ROCMClang-FindBinUtils.cmake b/Modules/Compiler/ROCMClang-FindBinUtils.cmake deleted file mode 100644 index e721c87..0000000 --- a/Modules/Compiler/ROCMClang-FindBinUtils.cmake +++ /dev/null @@ -1 +0,0 @@ -include(Compiler/Clang-FindBinUtils) diff --git a/Modules/Compiler/ROCMClang-HIP.cmake b/Modules/Compiler/ROCMClang-HIP.cmake deleted file mode 100644 index 7af7699..0000000 --- a/Modules/Compiler/ROCMClang-HIP.cmake +++ /dev/null @@ -1,49 +0,0 @@ -include(Compiler/ROCMClang) -__compiler_rocmclang(HIP) - -set(_CMAKE_COMPILE_AS_HIP_FLAG "-x hip") -set(_CMAKE_HIP_RDC_FLAG "-fgpu-rdc") - -if(NOT "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") - set(CMAKE_HIP_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") - string(APPEND CMAKE_HIP_FLAGS_DEBUG_INIT " -O") -endif() - -if(CMAKE_HIP_SIMULATE_ID STREQUAL "GNU") - set(CMAKE_HIP_LINKER_WRAPPER_FLAG "-Wl,") - set(CMAKE_HIP_LINKER_WRAPPER_FLAG_SEP ",") -elseif(CMAKE_HIP_SIMULATE_ID STREQUAL "Clang") - set(CMAKE_HIP_LINKER_WRAPPER_FLAG "-Xlinker" " ") - set(CMAKE_HIP_LINKER_WRAPPER_FLAG_SEP) -endif() - -if(NOT CMAKE_HIP_COMPILER_VERSION VERSION_LESS 1.0) - set(CMAKE_HIP98_STANDARD_COMPILE_OPTION "-std=c++98") - set(CMAKE_HIP98_EXTENSION_COMPILE_OPTION "-std=gnu++98") - set(CMAKE_HIP98_STANDARD__HAS_FULL_SUPPORT ON) - - set(CMAKE_HIP11_STANDARD_COMPILE_OPTION "-std=c++11") - set(CMAKE_HIP11_EXTENSION_COMPILE_OPTION "-std=gnu++11") - set(CMAKE_HIP11_STANDARD__HAS_FULL_SUPPORT ON) - - set(CMAKE_HIP14_STANDARD_COMPILE_OPTION "-std=c++14") - set(CMAKE_HIP14_EXTENSION_COMPILE_OPTION "-std=gnu++14") - set(CMAKE_HIP14_STANDARD__HAS_FULL_SUPPORT ON) - - set(CMAKE_HIP17_STANDARD_COMPILE_OPTION "-std=c++17") - set(CMAKE_HIP17_EXTENSION_COMPILE_OPTION "-std=gnu++17") - set(CMAKE_HIP17_STANDARD__HAS_FULL_SUPPORT ON) - - set(CMAKE_HIP20_STANDARD_COMPILE_OPTION "-std=c++20") - set(CMAKE_HIP20_EXTENSION_COMPILE_OPTION "-std=gnu++20") -endif() - -set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "SHARED") -set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "") -set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "") - -# Populated by CMakeHIPRuntime.cmake -set(CMAKE_HIP_RUNTIME_LIBRARIES_STATIC "") -set(CMAKE_HIP_RUNTIME_LIBRARIES_SHARED "") - -__compiler_check_default_language_standard(HIP 3.5 11) diff --git a/Modules/Compiler/ROCMClang-OBJC.cmake b/Modules/Compiler/ROCMClang-OBJC.cmake deleted file mode 100644 index 794973d..0000000 --- a/Modules/Compiler/ROCMClang-OBJC.cmake +++ /dev/null @@ -1,7 +0,0 @@ -include(Compiler/ROCMClang) -__compiler_rocmclang(OBJC) - -set(_rocm_clang_ver "${CMAKE_OBJC_COMPILER_VERSION_INTERNAL}") -set(CMAKE_OBJC_COMPILER_VERSION "${CMAKE_OBJC_COMPILER_VERSION_INTERNAL}") -include(Compiler/Clang-OBJC) -set(CMAKE_OBJC_COMPILER_VERSION "${_rocm_clang_ver}") diff --git a/Modules/Compiler/ROCMClang-OBJCXX.cmake b/Modules/Compiler/ROCMClang-OBJCXX.cmake deleted file mode 100644 index 82238e1..0000000 --- a/Modules/Compiler/ROCMClang-OBJCXX.cmake +++ /dev/null @@ -1,7 +0,0 @@ -include(Compiler/ROCMClang) -__compiler_rocmclang(OBJCXX) - -set(_rocm_clang_ver "${CMAKE_OBJCXX_COMPILER_VERSION_INTERNAL}") -set(CMAKE_OBJCXX_COMPILER_VERSION "${CMAKE_OBJCXX_COMPILER_VERSION_INTERNAL}") -include(Compiler/Clang-OBJCXX) -set(CMAKE_OBJCXX_COMPILER_VERSION "${_rocm_clang_ver}") diff --git a/Modules/Compiler/ROCMClang.cmake b/Modules/Compiler/ROCMClang.cmake deleted file mode 100644 index 6b38c2d..0000000 --- a/Modules/Compiler/ROCMClang.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - - -# This module is shared by multiple languages; use include blocker. -include_guard() - -include(Compiler/CMakeCommonCompilerMacros) - -macro(__compiler_rocmclang lang) - - set(CMAKE_${lang}_VERBOSE_FLAG "-v") - - if(NOT "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC") - # Feature flags. - set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") - set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") - set(CMAKE_HIP_COMPILE_OPTIONS_VISIBILITY -fvisibility=) - - string(APPEND CMAKE_HIP_FLAGS_INIT " ") - string(APPEND CMAKE_HIP_FLAGS_DEBUG_INIT " -g") - string(APPEND CMAKE_HIP_FLAGS_RELEASE_INIT " -O3 -DNDEBUG") - string(APPEND CMAKE_HIP_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG") - string(APPEND CMAKE_HIP_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG") - endif() - - set(CMAKE_SHARED_LIBRARY_CREATE_HIP_FLAGS -shared) - set(CMAKE_INCLUDE_SYSTEM_FLAG_HIP "-isystem ") - - set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1) - set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1) - set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1) - set(CMAKE_${lang}_RESPONSE_FILE_FLAG "@") - set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@") -endmacro() diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake index 54eb40e..0e4e028 100644 --- a/Modules/WriteCompilerDetectionHeader.cmake +++ b/Modules/WriteCompilerDetectionHeader.cmake @@ -384,7 +384,6 @@ elseif(_WCDH_policy STREQUAL "") ) endif() -set(__skip_rocmclang TRUE) include(${CMAKE_CURRENT_LIST_DIR}/CMakeCompilerIdDetection.cmake) function(_load_compiler_variables CompilerId lang) diff --git a/Tests/HIP/WithDefs/CMakeLists.txt b/Tests/HIP/WithDefs/CMakeLists.txt index e2db182..270f957 100644 --- a/Tests/HIP/WithDefs/CMakeLists.txt +++ b/Tests/HIP/WithDefs/CMakeLists.txt @@ -19,7 +19,7 @@ target_compile_options(HIPOnlyWithDefs PRIVATE --offload-arch=gfx900 -DFLAG_COMPILE_LANG_$ - $<$:-DFLAG_LANG_IS_HIP=$> # Host-only defines are possible only on NVCC. + $<$:-DFLAG_LANG_IS_HIP=$> # Host-only defines are possible only on NVCC. ) target_compile_definitions(HIPOnlyWithDefs -- cgit v0.12 From cb93f7262469d0f7e1b7da01ad3586d001234af2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Sep 2021 17:14:22 +0000 Subject: HIP: Simplify detection of HIP runtime CMake package It only makes sense to use the CMake package from the same ROCm installation that the compiler uses. Ask the HIP compiler to report the location of the ROCm installation. Verify up front that it contains the expected CMake package file. --- Modules/CMakeDetermineHIPCompiler.cmake | 20 +++++++ Modules/CMakeHIPCompiler.cmake.in | 1 + Modules/CMakeHIPInformation.cmake | 11 ++-- Modules/CMakeHIPRuntime.cmake.in | 99 --------------------------------- Modules/CMakeTestHIPCompiler.cmake | 21 ------- Modules/Compiler/Clang-HIP.cmake | 2 +- 6 files changed, 29 insertions(+), 125 deletions(-) delete mode 100644 Modules/CMakeHIPRuntime.cmake.in diff --git a/Modules/CMakeDetermineHIPCompiler.cmake b/Modules/CMakeDetermineHIPCompiler.cmake index 5c8849e..7b7d7a3 100644 --- a/Modules/CMakeDetermineHIPCompiler.cmake +++ b/Modules/CMakeDetermineHIPCompiler.cmake @@ -76,6 +76,18 @@ if(NOT CMAKE_HIP_COMPILER_ID_RUN) _cmake_find_compiler_sysroot(HIP) endif() +if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT AND CMAKE_HIP_COMPILER_ID STREQUAL "Clang") + execute_process(COMMAND "${CMAKE_HIP_COMPILER}" -v -print-targets + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _CMAKE_HIP_COMPILER_RESULT + OUTPUT_VARIABLE _CMAKE_HIP_COMPILER_STDOUT + ERROR_VARIABLE _CMAKE_HIP_COMPILER_STDERR + ) + + if(_CMAKE_HIP_COMPILER_RESULT EQUAL 0 AND _CMAKE_HIP_COMPILER_STDERR MATCHES "Found HIP installation: *([^,]*)[,\n]") + set(CMAKE_HIP_COMPILER_ROCM_ROOT "${CMAKE_MATCH_1}") + endif() +endif() if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT) execute_process( COMMAND hipconfig --rocmpath @@ -89,6 +101,14 @@ endif() if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT) message(FATAL_ERROR "Failed to find ROCm root directory.") endif() +if(NOT EXISTS "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/cmake/hip-lang/hip-lang-config.cmake") + message(FATAL_ERROR + "The ROCm root directory:\n" + " ${CMAKE_HIP_COMPILER_ROCM_ROOT}\n" + "does not contain the HIP runtime CMake package, expected at:\n" + " ${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/cmake/hip-lang/hip-lang-config.cmake\n" + ) +endif() if (NOT _CMAKE_TOOLCHAIN_LOCATION) get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_HIP_COMPILER}" PATH) diff --git a/Modules/CMakeHIPCompiler.cmake.in b/Modules/CMakeHIPCompiler.cmake.in index 9a30a45..17633a8 100644 --- a/Modules/CMakeHIPCompiler.cmake.in +++ b/Modules/CMakeHIPCompiler.cmake.in @@ -16,6 +16,7 @@ set(CMAKE_HIP_COMPILER_FRONTEND_VARIANT "@CMAKE_HIP_COMPILER_FRONTEND_VARIANT@") set(CMAKE_HIP_SIMULATE_VERSION "@CMAKE_HIP_SIMULATE_VERSION@") @SET_MSVC_HIP_ARCHITECTURE_ID@ @_SET_CMAKE_HIP_COMPILER_SYSROOT@ +set(CMAKE_HIP_COMPILER_ROCM_ROOT "@CMAKE_HIP_COMPILER_ROCM_ROOT@") set(CMAKE_HIP_COMPILER_ENV_VAR "HIPCXX") diff --git a/Modules/CMakeHIPInformation.cmake b/Modules/CMakeHIPInformation.cmake index ec37e1c..28c5f18 100644 --- a/Modules/CMakeHIPInformation.cmake +++ b/Modules/CMakeHIPInformation.cmake @@ -132,8 +132,11 @@ endif() set(CMAKE_HIP_INFORMATION_LOADED 1) # Load the file and find the relevant HIP runtime. -# This file will only exist after all compiler detection has finished -include(${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPRuntime.cmake OPTIONAL) -if(COMMAND _CMAKE_FIND_HIP_RUNTIME) - _CMAKE_FIND_HIP_RUNTIME() +if(NOT DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET) + set(hip-lang_DIR "${CMAKE_HIP_COMPILER_ROCM_ROOT}/lib/cmake/hip-lang") + find_package(hip-lang CONFIG QUIET NO_DEFAULT_PATH) +endif() +if(DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET) + list(APPEND CMAKE_HIP_RUNTIME_LIBRARIES_STATIC ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET}) + list(APPEND CMAKE_HIP_RUNTIME_LIBRARIES_SHARED ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET}) endif() diff --git a/Modules/CMakeHIPRuntime.cmake.in b/Modules/CMakeHIPRuntime.cmake.in deleted file mode 100644 index 3b345aa..0000000 --- a/Modules/CMakeHIPRuntime.cmake.in +++ /dev/null @@ -1,99 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - - -function(_CMAKE_FIND_HIP_RUNTIME ) - # Determined when hipcc is the HIP compiler - set(CMAKE_HIP_COMPILER_ROCM_ROOT "@CMAKE_HIP_COMPILER_ROCM_ROOT@") - - # Forward facing value that can be provided by the user - set(CMAKE_HIP_COMPILER_TOOLKIT_ROOT @CMAKE_HIP_COMPILER_TOOLKIT_ROOT@) - - if(NOT DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET) - set(message_on_found TRUE) - endif() - - set(explicit_search_only FALSE) - set(rocm_root_dirs ) - if(DEFINED CMAKE_HIP_COMPILER_TOOLKIT_ROOT) - set(rocm_root_dirs "${CMAKE_HIP_COMPILER_TOOLKIT_ROOT}") - set(explicit_search_only TRUE) - set(error_message_location "the variable CMAKE_HIP_COMPILER_TOOLKIT_ROOT [\"${CMAKE_HIP_COMPILER_TOOLKIT_ROOT}\"]") - elseif(DEFINED ENV{CMAKE_HIP_COMPILER_TOOLKIT_ROOT}) - set(rocm_root_dirs "$ENV{CMAKE_HIP_COMPILER_TOOLKIT_ROOT}") - set(explicit_search_only TRUE) - set(error_message_location "CMAKE_HIP_COMPILER_TOOLKIT_ROOT") - set(error_message_location "the environment variable CMAKE_HIP_COMPILER_TOOLKIT_ROOT [\"$ENV{CMAKE_HIP_COMPILER_TOOLKIT_ROOT}\"]") - elseif(DEFINED CMAKE_HIP_COMPILER_ROCM_ROOT) - set(rocm_root_dirs "${CMAKE_HIP_COMPILER_ROCM_ROOT}") - set(explicit_search_only TRUE) - set(error_message_location "the associated hipconfig --rocmpath [\"${CMAKE_HIP_COMPILER_ROCM_ROOT}\"]") - endif() - - # Guess on where rocm is installed - if(NOT rocm_root_dirs AND (UNIX AND NOT APPLE)) - set(platform_base "/opt/rocm-") - - # Finad all default rocm installations - file(GLOB possible_paths "${platform_base}*") - - set(versions) - foreach(p ${possible_paths}) - # Extract version number from end of string - string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+$" p_version ${p}) - if(IS_DIRECTORY ${p} AND p_version) - list(APPEND versions ${p_version}) - endif() - endforeach() - - # Sort numerically in descending order, so we try the newest versions first. - list(SORT versions COMPARE NATURAL ORDER DESCENDING) - - # With a descending list of versions, populate possible paths to search. - set(rocm_root_dirs "/opt/rocm") - foreach(v IN LISTS versions) - list(APPEND rocm_root_dirs "${platform_base}${v}") - endforeach() - endif() - - set(search_rel_path "/lib/cmake/hip-lang/") - list(TRANSFORM rocm_root_dirs APPEND "${search_rel_path}") - - find_package(hip-lang - CONFIG - PATHS ${rocm_root_dirs} - QUIET - NO_DEFAULT_PATH - ) - if(NOT DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET AND NOT explicit_search_only) - find_package(hip-lang CONFIG QUIET) - endif() - - if(DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET) - set(CMAKE_HIP_RUNTIME_LIBRARIES_STATIC - ${CMAKE_HIP_RUNTIME_LIBRARIES_STATIC} - ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET} PARENT_SCOPE) - set(CMAKE_HIP_RUNTIME_LIBRARIES_SHARED - ${CMAKE_HIP_RUNTIME_LIBRARIES_SHARED} - ${_CMAKE_HIP_DEVICE_RUNTIME_TARGET} PARENT_SCOPE) - endif() - - if(DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET AND message_on_found) - message(STATUS "Found HIP runtime: ${hip-lang_DIR}") - elseif(NOT DEFINED _CMAKE_HIP_DEVICE_RUNTIME_TARGET) - if(explicit_search_only) - set(error_message "Failed to find the HIP runtime, Could not find hip-lang-config.cmake at the following location(s):\n") - foreach(p IN LISTS rocm_root_dirs) - string(APPEND error_message "\t${p}\n") - endforeach() - string(APPEND "which are computed from the location specified by ${error_message_location}. \ - Please specify CMAKE_HIP_COMPILER_TOOLKIT_ROOT to the location of") - message(FATAL_ERROR "${error_message}") - else() - message(FATAL_ERROR - "Failed to find the HIP runtime, Could not find hip-lang-config.cmake.\ - Try setting CMAKE_HIP_COMPILER_TOOLKIT_ROOT") - endif() - endif() - -endfunction() diff --git a/Modules/CMakeTestHIPCompiler.cmake b/Modules/CMakeTestHIPCompiler.cmake index 62f0657..5acd806 100644 --- a/Modules/CMakeTestHIPCompiler.cmake +++ b/Modules/CMakeTestHIPCompiler.cmake @@ -81,20 +81,6 @@ unset(__CMAKE_HIP_FLAGS) include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) CMAKE_DETERMINE_COMPILE_FEATURES(HIP) - -# Setup the following: -# Configure the new template file CMakeHipRuntime.cmake to -# - ${CMAKE_PLATFORM_INFO_DIR}/ -# This file will do the actual find_package query. We than have -# CMakeHIPInformation.cmake include `CMakeHipRuntime` -# So it is included once system information has been finished -# -configure_file( - ${CMAKE_ROOT}/Modules/CMakeHIPRuntime.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPRuntime.cmake - @ONLY -) - # Re-configure to save learned information. configure_file( ${CMAKE_ROOT}/Modules/CMakeHIPCompiler.cmake.in @@ -113,10 +99,3 @@ endif() set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE) unset(__CMAKE_HIP_COMPILER_OUTPUT) - -# Load the file and find the relevant HIP runtime. -# This file will only exist after all compiler detection has finished -include(${CMAKE_PLATFORM_INFO_DIR}/CMakeHIPRuntime.cmake) -if(COMMAND _CMAKE_FIND_HIP_RUNTIME) - _CMAKE_FIND_HIP_RUNTIME() -endif() diff --git a/Modules/Compiler/Clang-HIP.cmake b/Modules/Compiler/Clang-HIP.cmake index 1030a43..4dbe2e8 100644 --- a/Modules/Compiler/Clang-HIP.cmake +++ b/Modules/Compiler/Clang-HIP.cmake @@ -15,6 +15,6 @@ set(CMAKE_HIP_RUNTIME_LIBRARY_DEFAULT "SHARED") set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "") set(CMAKE_HIP_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED "") -# Populated by CMakeHIPRuntime.cmake +# Populated by CMakeHIPInformation.cmake set(CMAKE_HIP_RUNTIME_LIBRARIES_STATIC "") set(CMAKE_HIP_RUNTIME_LIBRARIES_SHARED "") -- cgit v0.12