FindCudaToolkit fails on Windows with: Unable to find cuda_runtime.h in undefined directory for CUDAToolkit_INCLUDE_DIR
find_package(CUDAToolkit 10.1.243 REQUIRED)
eventually runs in the cmake code 'nvcc` and it fails/error. This causes a cascade for the Find to overall fail.
At https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindCUDAToolkit.cmake#L525 is a bug that was introduced with changes starting at commit 3cef91a3
In the problem commit above, when nvcc is run it has an error. Therefore the MATCHES under it fails. Therefore the value of CMAKE_MATCH_1 is undefined cascading to create a string "undefined/bin" which the get_filename_component() munges into unusable path. Then then breaks all further code in the Find.
If I copy/paste back one commit FindCUDAToolkit.cmake
at 4ea6d3c3 the configure is successful and has no problems. Or I can install an older cmake like official cmake-3.19.1-win64-x64.msi
Setup
- Microsoft Windows [Version 10.0.19042.928]
- VS Studio v16.9.4 Community
- CMake 3.20.2 from official
cmake-3.20.2-windows-x86_64.msi
- CUDA 10.1.243 via official
cuda_10.1.243_win10_network.exe
Repro
- Install as above
- Create apps that need CUDA
- Create CMakeLists.txt having
find_package(CUDAToolkit 10.1.243 REQUIRED)
- cmake configure
Result
Configure fatal fails.
[cmake] -- Unable to find cuda_runtime.h in "C:/njs/dp.kinect3/undefined/include" for CUDAToolkit_INCLUDE_DIR.
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake] Could NOT find CUDAToolkit (missing: CUDAToolkit_INCLUDE_DIR) (found
[cmake] suitable version "10.1.243", minimum required is "10.1.243")
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake] C:/Program Files/CMake/share/cmake-3.20/Modules/FindCUDAToolkit.cmake:796 (find_package_handle_standard_args)
[cmake] C:/njs/vcpkg/scripts/buildsystems/vcpkg.cmake:861 (_find_package)
[cmake] CMakeLists.txt:62 (find_package)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "C:/njs/dp.kinect3/build/CMakeFiles/CMakeOutput.log".
[cmake] See also "C:/njs/dp.kinect3/build/CMakeFiles/CMakeError.log".
Expected
No errors. Good configure.
Notes
Notice in error the path is was checking. The "undefined" is ${CMAKE_MATCH_1}
Unable to find cuda_runtime.h in "C:/njs/dp.kinect3/undefined/include"
I did some debugging and the call you make to nvcc does not do anything useful on my machine. At a plain cmd prompt I got...
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin>nvcc.exe -v __cmake_determine_cuda
nvcc fatal : Cannot find compiler 'cl.exe' in PATH
At a x64 Native Tools Command Prompt for VS 2019, I typed the same nvcc.exe -v __cmake_determine_cuda
which caused somehow vcvars64.bat
to be run with 100+ lines of output showing settings and env vars
Then under those lines I got...
<<<REDACTED MAYBE 100 LINES ABOVE THIS>>>
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=.
#$ _THERE_=.
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_SIZE_=64
#$ _WIN_PLATFORM_=x64
#$ TOP=./..
#$ NVVMIR_LIBRARY_DIR=./../nvvm/libdevice
#$ PATH= <<<<REDACTED MAYBE 40 LINES HERE>>>>
#$ INCLUDES="-I./../include"
#$ LIBRARIES= "/LIBPATH:./../lib/x64"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
nvcc fatal : Don't know what to do with '__cmake_determine_cuda'