CheckLanguage: CMAKE_HIP_PLATFORM=nvidia fails with CMake 3.28.1
I was trying to make use of -DCMAKE_HIP_PLATFORM=nvidia
, which I was happy was introduced with CMake 3.28.
https://cmake.org/cmake/help/latest/variable/CMAKE_HIP_PLATFORM.html
However, there seems to be a bug in the code.
cmake_minimum_required(VERSION 3.28)
project(HipTest LANGUAGES CXX)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
endif()
check_language(HIP)
if(CMAKE_HIP_COMPILER)
enable_language(HIP)
endif()
Without specifying CMAKE_HIP_PLATFORM
, this works fine for me.
[bash][Celeborn]:cmake > ~/software/kitware/cmake-3.28.1/bin/cmake -S hip -B build
-- The CXX compiler identification is GNU 9.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - /home/krasznaa/software/nvidia/cuda-12.3.1/bin/nvcc
-- The CUDA compiler identification is NVIDIA 12.3.103
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /home/krasznaa/software/nvidia/cuda-12.3.1/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Looking for a HIP compiler
-- Looking for a HIP compiler - /opt/rocm-5.7.1/llvm/bin/clang++
-- The HIP compiler identification is Clang 17.0.0
-- Detecting HIP compiler ABI info
-- Detecting HIP compiler ABI info - done
-- Check for working HIP compiler: /opt/rocm-5.7.1/llvm/bin/clang++ - skipped
-- Detecting HIP compile features
-- Detecting HIP compile features - done
-- Configuring done (27.8s)
-- Generating done (0.0s)
-- Build files have been written to: /home/krasznaa/Development/cmake/build
[bash][Celeborn]:cmake >
(I'm only setting up CUDA in this example to show that CUDA, as a backend for HIP, is available just fine in my runtime environment. I also tested in a "real project" that compiling HIP code for an AMD backend works correctly like this.)
But when I try the following, it fails:
[bash][Celeborn]:cmake > ~/software/kitware/cmake-3.28.1/bin/cmake -DCMAKE_HIP_PLATFORM=nvidia -S hip -B build
-- The CXX compiler identification is GNU 9.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - /home/krasznaa/software/nvidia/cuda-12.3.1/bin/nvcc
-- The CUDA compiler identification is NVIDIA 12.3.103
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /home/krasznaa/software/nvidia/cuda-12.3.1/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Looking for a HIP compiler
-- Looking for a HIP compiler - /opt/rocm-5.7.1/llvm/bin/clang++
-- The HIP compiler identification is Clang 17.0.0
CMake Error at /home/krasznaa/software/kitware/cmake-3.28.1/share/cmake-3.28/Modules/CMakeHIPInformation.cmake:159 (find_package):
Could not find a package configuration file provided by "hip-lang" with any
of the following names:
hip-langConfig.cmake
hip-lang-config.cmake
Add the installation prefix of "hip-lang" to CMAKE_PREFIX_PATH or set
"hip-lang_DIR" to a directory containing one of the above files. If
"hip-lang" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
CMakeLists.txt:13 (enable_language)
-- Configuring incomplete, errors occurred!
[bash][Celeborn]:cmake >
And looking at the code, I can see why.
- The failure happens here: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeHIPInformation.cmake?ref_type=heads#L159
- That search is preceded by a very forceful setting for
hip-lang_DIR
(https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeHIPInformation.cmake?ref_type=heads#L158), which relies onCMAKE_HIP_COMPILER_ROCM_LIB
. - As far as I can see, that variable is only set here: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeDetermineHIPCompiler.cmake?ref_type=heads#L210
- Which is inside of a big
if(CMAKE_HIP_PLATFORM STREQUAL "amd")
block.😕
This does not seem intentional. CMAKE_HIP_PLATFORM=nvidia
, was setting CMAKE_HIP_COMPILER_ROCM_LIB
by hand. As I just don't see how my setup should be inappropriate for this to work.
While at it: I'm very happy that CMAKE_HIP_PLATFORM
, which I suggested a while ago in https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208, is finally becoming a thing. But as I wrote there, ideally CMAKE_HIP_PLATFORM
should just be a global default. There should also be a HIP_PLATFORM
target property. And possibly even a source file property with the same name. So that one could mix AMD and NVIDIA backended builds inside of the same project.
Pinging @brad.king and @Maetveis, who I see have been modifying this code in the past.
P.S. My setup does work with the CMake code (https://github.com/acts-project/vecmem/tree/main/cmake/hip) that I'd so like to retire at one point. Once CMake's own code starts working properly...