首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何利用CMake 3.23和MSVC 2019制作工作数据自动化系统11.6

如何利用CMake 3.23和MSVC 2019制作工作数据自动化系统11.6
EN

Stack Overflow用户
提问于 2022-04-04 15:20:51
回答 4查看 3.8K关注 0票数 1

我找不到一个解决方案来管理如何在CMake项目中使用标准的MSVC2019编译器的语言CUDA。

我正在尝试配置和编译存储库 (也在这篇博客文章中描述)。

CMakeLists.txt文件内容:

代码语言:javascript
运行
复制
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(hello LANGUAGES CXX CUDA)
enable_language(CUDA)
add_executable(hello hello.cu)

下面是从构建目录中运行的cmake ..命令的输出:

代码语言:javascript
运行
复制
PS C:\GitRepo\cuda_hello\build> cmake ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22000.
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeDetermineCUDACompiler.cmake:311 (message):
  CMAKE_CUDA_ARCHITECTURES must be valid if set.
Call Stack (most recent call first):
  CMakeLists.txt:5 (project)


-- Configuring incomplete, errors occurred!
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeOutput.log".
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeError.log".

这意味着来自architectures_testedCMakeDetermineCUDACompiler.cmake:311是空的..。

如何让CMake完成其配置和构建简单的程序?

我的开发环境

  • 操作系统: Windows 11版本10.0.22000构建22000
  • 编译器: 2019版本16.11.11
  • CMake版本为3.23
  • CUDA版本为11.6

我试过不同版本的每一个软件,并一直有相同的问题。我现在决定继续使用这些版本。

我的GPU配置正确:它使用nvidia-smi显示,我还可以构建和运行deviceQuery CUDA示例:

代码语言:javascript
运行
复制
CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "NVIDIA GeForce GTX 1650"
  CUDA Driver Version / Runtime Version          11.6 / 11.6
  CUDA Capability Major/Minor version number:    7.5
  etc. etc. ...

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.6, CUDA Runtime Version = 11.6, NumDevs = 1
Result = PASS

我的环境路径变量:

代码语言:javascript
运行
复制
PS C:\GitRepo\hello-cuda-cmake-master> $env:path -split ";"
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\libnvvp

C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Python38\Scripts\
C:\Python38\
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
C:\Program Files\PuTTY\
C:\Program Files (x86)\PuTTY\
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
C:\Program Files\TortoiseSVN\bin
C:\Program Files\TortoiseGit\bin
C:\Program Files\Microsoft VS Code\bin
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\Docker\Docker\resources\bin
C:\ProgramData\DockerDesktop\version-bin
C:\Program Files\Git\cmd
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.1.1\
C:\Program Files\CMake\bin
C:\Ruby30-x64\bin
C:\Users\Thibault GEFFROY\.cargo\bin
C:\Users\Thibault GEFFROY\AppData\Local\Microsoft\WindowsApps
C:\Program Files\OpenCppCoverage
C:\intelFPGA\20.1\modelsim_ase\win32aloem

我试过但没有成功的东西

如果我试图插入想要的CMAKE_CUDA_ARCHITECTURES

set(CMAKE_CUDA_ARCHITECTURES 75)

我得到:

代码语言:javascript
运行
复制
PS C:\GitRepo\cuda_hello\build> cmake ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22000.
-- The CUDA compiler identification is unknown
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeDetermineCUDACompiler.cmake:654 (message):
  The CMAKE_CUDA_ARCHITECTURES:

    75

  do not all work with this compiler.  Try:



  instead.
Call Stack (most recent call first):
  CMakeLists.txt:5 (project)


-- Configuring incomplete, errors occurred!
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeOutput.log".
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeError.log".

如果我尝试使用FindCUDA模块来设置CMAKE_CUDA_ARCHITECTURES -- @alfC 这里给出的解决方案--我得到:

代码语言:javascript
运行
复制
PS C:\GitRepo\cuda_hello\build> cmake ..
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/FindCUDA/select_compute_arch.cmake:120 (file):
  file failed to open for writing (Permission denied):

    /detect_cuda_compute_capabilities.cpp
Call Stack (most recent call first):
  CMakeLists.txt:4 (CUDA_DETECT_INSTALLED_GPUS)


CMake Error: The source directory "CMAKE_FLAGS" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/FindCUDA/select_compute_arch.cmake:141 (try_run):
  Failed to configure test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:4 (CUDA_DETECT_INSTALLED_GPUS)


CMake Error: TRY_COMPILE attempt to remove -rf directory that does not contain CMakeTmp:/detect_cuda_compute_capabilities.cpp
-- Configuring incomplete, errors occurred!
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeOutput.log".
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeError.log".

最后,如果我试图调用find_package(CUDA),我会得到:

代码语言:javascript
运行
复制
PS C:\GitRepo\cuda_hello\build> cmake ..
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/FindCUDA.cmake:677 (cmake_initialize_per_config_variable):
  Unknown CMake command "cmake_initialize_per_config_variable".
Call Stack (most recent call first):
  CMakeLists.txt:2 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeOutput.log".
See also "C:/GitRepo/cuda_hello/build/CMakeFiles/CMakeError.log".

编辑1:

回答@einpoklum解决方案

谢谢你的建议,但也不管用。

下面是cmake -B build命令在你的存储库中的输出

代码语言:javascript
运行
复制
PS C:\GitRepo\hello-cuda-cmake-master> cmake -B build
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22000.
-- The CUDA compiler identification is unknown
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeDetermineCUDACompiler.cmake:633 (message):
  Failed to detect a default CUDA architecture.



  Compiler output:

Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/GitRepo/hello-cuda-cmake-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/GitRepo/hello-cuda-cmake-master/build/CMakeFiles/CMakeError.log".

使用PowerShell或MSVC命令提示符输出是相同的。

以下是使用cmake时的cmake变量及其值:

当使用简单的nvcc构建命令:来自MSVC命令提示符的nvcc hello.cu时,我得到:

代码语言:javascript
运行
复制
nvcc fatal   : Could not set up the environment for Microsoft Visual Studio using 'c:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX86/x86/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'

路径是有效的,并且脚本vcvars64.bat存在于这个位置。

如果我将find_package(CUDAToolkit)添加到CMakeLists.txt中会发生什么?

新的CMakeLists.txt

代码语言:javascript
运行
复制
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
find_package(CUDAToolkit)
project(hello LANGUAGES CUDA)
add_executable(hello hello.cu)

产出:

代码语言:javascript
运行
复制
PS C:\GitRepo\hello-cuda-cmake-master> cmake -B build
-- Building for: Visual Studio 16 2019
-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/include (found version "11.6.124")
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22000.
-- The CUDA compiler identification is unknown
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeDetermineCUDACompiler.cmake:633 (message):
  Failed to detect a default CUDA architecture.



  Compiler output:

Call Stack (most recent call first):
  CMakeLists.txt:3 (project)


-- Configuring incomplete, errors occurred!
See also "C:/GitRepo/hello-cuda-cmake-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/GitRepo/hello-cuda-cmake-master/build/CMakeFiles/CMakeError.log".

编辑2:

我正在尝试编译没有CUDA样品 BlackScholes的CMake,并提供了MSVC 2019解决方案。

我最后犯了这个错误:

代码语言:javascript
运行
复制
Severity        Code        Description        Project        File        Line        Suppression State
Error        MSB3721        The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\nvcc.exe" -gencode=arch=compute_35,code=\"sm_35,compute_35\" -gencode=arch=compute_37,code=\"sm_37,compute_37\" -gencode=arch=compute_50,code=\"sm_50,compute_50\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" -gencode=arch=compute_60,code=\"sm_60,compute_60\" -gencode=arch=compute_61,code=\"sm_61,compute_61\" -gencode=arch=compute_70,code=\"sm_70,compute_70\" -gencode=arch=compute_75,code=\"sm_75,compute_75\" -gencode=arch=compute_80,code=\"sm_80,compute_80\" -gencode=arch=compute_86,code=\"sm_86,compute_86\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64" -x cu   -I./ -I../../../Common -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\/include" -I../../../Common -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include"  -G   --keep-dir x64\Debug  -maxrregcount=0  --machine 64 --compile -cudart static -Xcompiler "/wd 4819"  --threads 0 -g  -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Fdx64/Debug/vc142.pdb /FS /Zi /RTC1 /MTd " -o "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v11.6\cuda-samples\Samples\5_Domain_Specific\BlackScholes\x64\Debug\BlackScholes.cu.obj" "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v11.6\cuda-samples\Samples\5_Domain_Specific\BlackScholes\BlackScholes.cu"" exited with code 1.        BlackScholes        C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.6.targets        790

在使用WSL2Ubuntu20.4和安装CUDA后以及这些使用说明构建BlackScholes示例时,我得到了以下输出:

代码语言:javascript
运行
复制
$ sudo make BlackScholes
/usr/local/cuda/bin/nvcc -ccbin g++ -I../../../Common  -m64    -maxrregcount=16 --threads 0 --std=c++11 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o BlackScholes.o -c BlackScholes.cu
nvcc warning : The 'compute_35', 'compute_37', 'sm_35', and 'sm_37' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
ptxas warning : For profile sm_86 adjusting per thread register count of 16 to lower bound of 24
ptxas warning : For profile sm_80 adjusting per thread register count of 16 to lower bound of 24
ptxas warning : For profile sm_70 adjusting per thread register count of 16 to lower bound of 24
ptxas warning : For profile sm_75 adjusting per thread register count of 16 to lower bound of 24
/usr/local/cuda/bin/nvcc -ccbin g++ -I../../../Common  -m64    -maxrregcount=16 --threads 0 --std=c++11 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o BlackScholes_gold.o -c BlackScholes_gold.cpp
nvcc warning : The 'compute_35', 'compute_37', 'sm_35', and 'sm_37' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
/usr/local/cuda/bin/nvcc -ccbin g++   -m64      -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o BlackScholes BlackScholes.o BlackScholes_gold.o
nvcc warning : The 'compute_35', 'compute_37', 'sm_35', and 'sm_37' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
mkdir -p ../../../bin/x86_64/linux/release
cp BlackScholes ../../../bin/x86_64/linux/release


$ ./BlackScholes
[./BlackScholes] - Starting...
GPU Device 0: "Turing" with compute capability 7.5

Initializing data...
...allocating CPU memory for options.
...allocating GPU memory for options.
...generating input data in CPU mem.
...copying input data to GPU mem.
Data init done.

Executing Black-Scholes GPU kernel (512 iterations)...
Options count             : 8000000
BlackScholesGPU() time    : 0.722482 msec
Effective memory bandwidth: 110.729334 GB/s
Gigaoptions per second    : 11.072933

BlackScholes, Throughput = 11.0729 GOptions/s, Time = 0.00072 s, Size = 8000000 options, NumDevsUsed = 1, Workgroup = 128

Reading back GPU results...
Checking the results...
...running CPU calculations.

Comparing the results...
L1 norm: 1.741792E-07
Max absolute error: 1.192093E-05

Shutting down...
...releasing GPU memory.
...releasing CPU memory.
Shutdown done.

[BlackScholes] - Test Summary

NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.

Test passed
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71739732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档