Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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})
like image 422
Mineral Avatar asked Jun 17 '19 18:06

Mineral


People also ask

Why is Cuda not showing up in CMake?

If you have only the first one installed (i.e. you have all you need to develop with cuda) but not the latter, then CMake won't find cuda! just run the installer again and select "Visual Studio Integration" component (even without reinstalling the rest) Share Improve this answer Follow answered Nov 5 '20 at 20:20 MicheleMichele

What is the cxx compiler identification for CMake?

-- The CXX compiler identification is MSVC 19.28.29915.0 CMake Error at C:/Program Files/cmake/cmake-3.19.2-win64-x64/share/cmake-3.19/Modules/CMakeDetermineCompilerId.cmake:412 (message): No CUDA toolset found.

What is Compt compiler detection in CMake?

Compiler detection in CMake across all languages ( C++, C, CUDA ) is the expectation that it is possible to run a simple executable in the current environment to extract compiler vendor name, and other information.

What file do you use to compile your CMake lists?

I've tried a variation of suggestions online such as adding the following to 'CMakeLists.txt': 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:


2 Answers

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).

like image 83
bjacobowski Avatar answered Sep 18 '22 05:09

bjacobowski


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.

like image 23
Mineral Avatar answered Sep 19 '22 05:09

Mineral