CUDA compile problems on Windows, Cmake error: No CUDA toolset found
Asked Answered
C

9

11

so I've been successfully working on my CUDA program on my Linux but I would like to support Windows platform as well. However, I've been struggling with correctly compiling it. I use :

  • Windows 10
  • Cmake 3.15
  • Visual Studio 2017
  • CUDA Toolkit 10.1

When using the old deprecated Cmake CUDA support of using find_package(CUDA 10.1 REQUIRED) it correctly reports the correct path to the toolkit when using it. However, it is my understanding that the latest Cmake does not properly support the old method anymore and that cuda_add_libraryetc don't properly link anymore. So I have reformatted my 'CMakeLists.txt' file to the following based on this:

cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(myproject LANGUAGES CXX CUDA)

add_library(mylib SHARED mycudalib.cu)

# My code requires C++ 11 for the CUDA library, not sure which ones of these 
# will do the trick correctly. Never got the compiler this far.
target_compile_features(mylib PUBLIC cxx_std_11)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CUDA_STANDARD 11)    


set_target_properties( mylib PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

add_executable(test_mylib test.cpp)

target_link_libraries(test_mylib mylib ${CUDA_CUFFT_LIBRARIES})

However, I get the following error from line 2:

CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeDetermineCompilerId.cmake:345 (message):
  No CUDA toolset found.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeDetermineCompilerId.cmake:32 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeDetermineCUDACompiler.cmake:72 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:2 (project)

I've tried a variation of suggestions online such as adding the following to 'CMakeLists.txt':

set(CMAKE_CUDA_COMPILER "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc")

or adding the following variable to Cmake: enter image description here

This is the 'CMakeLists.txt' file I use on Linux to compile succesfully. The difference is there I use Cmake 3.5 and CUDA Toolkit 9.0:

cmake_minimum_required(VERSION 3.5)
project( myproject)
find_package(CUDA 9.0 REQUIRED)
if(CUDA_FOUND)  
        list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
endif(CUDA_FOUND)

cuda_add_library(mylib SHARED mycudalib.cu)
cuda_add_executable(test_mylib test.cpp)
target_link_libraries(test_mylib mylib ${CUDA_CUFFT_LIBRARIES})
Cymophane answered 17/6, 2019 at 18:9 Comment(0)
C
14

I have tried it on a different PC now and it works fine. So I had absolutely no idea why it's not working on this one. As CUDA_PATH is correctly setup in my system variables.

Then looking into it further, by uninstalling the 'Build Tools' of Visual Studio and only having the Community IDE installed, CMake used the IDE instead of the Build Tools and then it started working fine.

Cymophane answered 19/6, 2019 at 10:53 Comment(3)
I just ran into the same issue with the Build Tools. If you want to keep the Build Tools installed, you just need to copy everything from: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\extras\visual_studio_integration\MSBuildExtensions To: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\BuildCustomizations Change your CUDA and VS versions in those paths as necessary. For some reason the CUDA toolkit installer doesn't consider the Build Tools installs when choosing where to add the integrations.Letterpress
After replicating this copy step, the error persists. Has anyone found additional constraints or workarounds?Tearoom
@MatthewDixon your comment should be made an answer. thanksCrossquestion
P
18

For Windows 10, VS2019 Community, and CUDA 11.3, the following worked for me:

  1. Extract the full installation package with 7-zip or WinZip
  2. Copy the four files from this extracted directory .\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions into the MSBuild folder of your VS2019 install C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations

The four files are:

  • CUDA 11.3.props
  • CUDA 11.3.targets
  • CUDA 11.3.xml
  • Nvda.Build.CudaTasks.v11.3.dll

I had tried installing (and reinstalling) CUDA with Visual Studio Integration, but CMake wasn't able to find the CUDA installation (even with CUDA_PATH and CMAKE_CUDA_COMPILER defined).

Prunella answered 24/6, 2021 at 18:16 Comment(1)
Note that you actually install the CUDA toolkit from an executable (not extract from 7-zip). Then, in the CUDA subfolder you listed (e.g. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\extras\visual_studio_integration\MSBuildExtensions for CUDA 10.2, you'll find the 4 files you listed. Those you copy to the MS Visual Studio folder you listed.Burress
C
14

I have tried it on a different PC now and it works fine. So I had absolutely no idea why it's not working on this one. As CUDA_PATH is correctly setup in my system variables.

Then looking into it further, by uninstalling the 'Build Tools' of Visual Studio and only having the Community IDE installed, CMake used the IDE instead of the Build Tools and then it started working fine.

Cymophane answered 19/6, 2019 at 10:53 Comment(3)
I just ran into the same issue with the Build Tools. If you want to keep the Build Tools installed, you just need to copy everything from: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\extras\visual_studio_integration\MSBuildExtensions To: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\BuildCustomizations Change your CUDA and VS versions in those paths as necessary. For some reason the CUDA toolkit installer doesn't consider the Build Tools installs when choosing where to add the integrations.Letterpress
After replicating this copy step, the error persists. Has anyone found additional constraints or workarounds?Tearoom
@MatthewDixon your comment should be made an answer. thanksCrossquestion
K
5

For anyone battling CMake and CUDA, my solution to this problem was to add the following to the CMake command:

-DCMAKE_GENERATOR_TOOLSET="cuda=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2"

As well as copying the 4 VS integration files (from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\extras\visual_studio_integration\MSBuildExtensions) to both:

  • C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\BuildCustomizations
  • and C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations

After all this CMake was happy with CUDA and started compiling. I didn't reinstall CUDA or anything.

Kalimantan answered 12/9, 2023 at 2:51 Comment(1)
After about 10 hours trying get this working, this was the thing that worked.Oblivion
A
3

Look at this. It may solve your issues. https://gitlab.kitware.com/cmake/cmake/issues/19029

Seems like Nvidia cuda installer has some issues with installing the VS integration with vs 2017. Check if you can find this file in your vs installing path.

C:/Program Files (x86)/Microsoft Visual 
Studio/2017/Professional/Common7/IDE/VC/VCTargets/BuildCustomizations/CUDA 
10.1.xml
Anima answered 24/6, 2019 at 11:50 Comment(2)
This file is missing on my system (well, I am using 2019, so it's missing from C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\VC\VCTargets). Is there an installer option which will installs that file?Footie
I have no idea. Finally, I decided to use instead just use VS 2015. And it works quite well so far.Anima
C
3

I was trying to build darknet from source and came across this issue.

What resolved it for me was the following:

  • making sure no other Visual Studio or Visual Studio Build Tool was installed except for VS2019. (I configured this using the uninstall feature of the ~1 mb vs_community.exe installer program)
  • REINSTALLING CUDA 10.1, using the 2.5 gb installer, and in that process, making sure 'VS Integration' is installed (for me... this was a 'reinstall' since I had already installed it, but with a bunch of VS2019,VS2017 + Build Tools all installed at once!!) during the installation.

At that point, my cudnn files were still in the bin/lib/include folder of the 10.1 installation, and I hit "Configure" in CMake again.

Success! No errors. (CMake 3.18, VS2019, CUDA 10.1.243, cudnn 7.6.5)

Capsicum answered 27/8, 2020 at 0:2 Comment(0)
J
3

I had a similar problem, and probably @James claim is right, it is just visual studio and cuda integration mismatch. I followed @bjacobowski's solution. For any future reference, I integrated CUDA 12.1 and Visual Studio 2022 community edition.

  • I copied the four files from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\extras\visual_studio_integration\MSBuildExtensions
  • And pasted into C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations
Jaimie answered 25/8, 2023 at 16:3 Comment(1)
Yeah, confirmed that copying these four files fixes the problem with VS2020.Geek
U
2

I just have the same issue of No CUDA toolset found with different versions, and my system:

-Windows 11 -Cmake 3.20.0 -Visual Studio 2019 -CUDA Toolkit 11.6

Some netizens said that it happened if you installed Visual Studio before you install CUDA. So, I tried and reinstall CUDA, finally it work now. You also can try it. Good luck.

enter image description here

Ursel answered 23/1, 2022 at 7:24 Comment(0)
A
1

Roy Shilkrot provided the crucial hint that led to a solution for me on Windows 11 with CUDA 12.4:

First, set the CMAKE_ARGS environment variable to enable CUDA and specify the CUDA toolkit path:

```powershell
$env:CMAKE_ARGS="-DLLAMA_CUDA=on -DCMAKE_GENERATOR_TOOLSET='cuda=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4'"

Then, install llama-cpp-python using pip with the specified options to force reinstall, upgrade, and use a specific extra index URL:

pip install llama-cpp-python --force-reinstall --upgrade --no-cache-dir --verbose --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124

Reference: https://github.com/abetlen/llama-cpp-python

Antinomian answered 23/6 at 14:49 Comment(0)
C
0

For anyone else who has a similar problem, I FINALLY realized my issue! My cuda toolset was x64, but my cmake build script by default was trying to build x86. Passing -A x64 to my cmake command fixed the issue. In my particular case, I was building llama.cpp, and my command was:

cmake .. -DLLAMA_CUBLAS=ON -A x64

Casie answered 26/10, 2023 at 20:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.