diff options
author | Robert Maynard <rmaynard@nvidia.com> | 2021-02-03 22:39:26 (GMT) |
---|---|---|
committer | Robert Maynard <rmaynard@nvidia.com> | 2021-02-08 20:13:01 (GMT) |
commit | 3cef91a32159bd3e311b5c1d76798ae40a156ccb (patch) | |
tree | c6ab164a9c0ee9566074e008573accdf0c86b3d5 /Modules/CMakeDetermineCUDACompiler.cmake | |
parent | b06a480b5726a44cefb98cf84f0d874c37d1a95c (diff) | |
download | CMake-3cef91a32159bd3e311b5c1d76798ae40a156ccb.zip CMake-3cef91a32159bd3e311b5c1d76798ae40a156ccb.tar.gz CMake-3cef91a32159bd3e311b5c1d76798ae40a156ccb.tar.bz2 |
CUDA: Always extract CUDA Toolkit root from nvcc verbose output
Fixes #21750, #21763
Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro)
each of which has a different layout, we need to extract the CUDA toolkit root from the compiler
itself, allowing us to support numerious different scattered toolkit layouts.
The NVIDIA HPC SDK specifically ships two copies of nvcc one in
`compilers/bin/` and one in `cuda/bin`. Thus when using
`compilers/bin/nvcc` the Toolkit root logic fails.
Diffstat (limited to 'Modules/CMakeDetermineCUDACompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineCUDACompiler.cmake | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index c77fc3a..468b8a1 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -172,23 +172,21 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) endif() endif() - # If NVCC is a symlink due to a wrapper script (e.g. ccache or colornvcc), then invoke it to find the - # real non-scattered toolkit. - if(IS_SYMLINK ${_CUDA_NVCC_EXECUTABLE}) - execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) - if(NVCC_ERR MATCHES " _HERE_=([^\r\n]*)") - set(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_MATCH_1}") - else() - message(FATAL_ERROR "Could not execute nvcc with -v.") - endif() - unset(NVCC_ERR) + # Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro) + # each of which has a different layout, we need to extract the CUDA toolkit root from the compiler + # itself, allowing us to support numerous different scattered toolkit layouts + execute_process(COMMAND ${_CUDA_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda" ERROR_VARIABLE NVCC_ERR) + if(NVCC_ERR MATCHES "TOP=([^\r\n]*)") + get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_MATCH_1}" ABSOLUTE) else() get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${_CUDA_NVCC_EXECUTABLE}" DIRECTORY) + get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) endif() + unset(NVCC_ERR) + + set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/bin/nvlink${CMAKE_EXECUTABLE_SUFFIX}") + set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/bin/fatbinary${CMAKE_EXECUTABLE_SUFFIX}") - set(CMAKE_CUDA_DEVICE_LINKER "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/nvlink${CMAKE_EXECUTABLE_SUFFIX}") - set(CMAKE_CUDA_FATBINARY "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/fatbinary${CMAKE_EXECUTABLE_SUFFIX}") - get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}" DIRECTORY) # In a non-scattered installation the following are equivalent to CMAKE_CUDA_COMPILER_TOOLKIT_ROOT. # We first check for a non-scattered installation to prefer it over a scattered installation. |