c++ - CUDA 在 Windows 上编译问题,Cmake 错误 : No CUDA toolset found

标签 c++ cmake compiler-errors cuda nvcc

所以我已经在我的 Linux 上成功地开发了我的 CUDA 程序,但我也想支持 Windows 平台。但是,我一直在努力正确编译它。我使用:

  • window 10
  • CMake 3.15
  • Visual Studio 2017
  • CUDA 工具包 10.1

当使用旧的已弃用的 Cmake CUDA 支持使用 find_package(CUDA 10.1 REQUIRED) 时,它会在使用时正确报告工具包的正确路径。但是,据我了解,最新的 Cmake 不再正确支持旧方法,并且 cuda_add_library 等不再正确链接。所以我根据 this 将我的“CMakeLists.txt”文件重新格式化为以下格式:

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

但是,我从第 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)

我尝试了各种在线建议,例如将以下内容添加到“CMakeLists.txt”:

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

或者在 Cmake 中添加以下变量: enter image description here

这是我在 Linux 上编译成功时使用的 'CMakeLists.txt' 文件。区别在于我使用 Cmake 3.5 和 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})

最佳答案

对于 Windows 10、VS2019 社区和 CUDA 11.3,以下对我有用:

  1. 使用 7-zip 或 WinZip 解压完整的安装包
  2. 从这个提取的目录复制四个文件 .\visual_studio_integration\CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtensions 进入 VS2019 安装的 MSBuild 文件夹 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations

这四个文件是:

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

我曾尝试使用 Visual Studio Integration 安装(并重新安装)CUDA,但 CMake 无法找到 CUDA 安装(即使定义了 CUDA_PATH 和 CMAKE_CUDA_COMPILER)。

关于c++ - CUDA 在 Windows 上编译问题,Cmake 错误 : No CUDA toolset found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56636714/

相关文章:

c++ - 显式调用析构函数的行为

c++ - 为什么最低()和最大()之间生成的所有随机数都等于无穷大?

c++ - 从命令行运行 Borland turbo c++ 10 IDE 项目

c++ - 使用 CMAKE 构建和安装静态库

path - cmake:unix上的默认包含路径

c++ - 如何配置 CMake 以使用 -fPIC 构建库?

compiler-errors - 斧头: "Int cannot be called"

c++ - C# 的 readonly 字段修饰符的 C++ 等价物是什么?

scala - 未分配给变量时扩展函数缺少参数类型

C++ 堆栈实现硬件错误