我正在尝试获取 NVIDIA 的 CUDA 设置并将其安装在具有 NVIDIA GEFORCE RTX 2080 SUPER 显卡的电脑上。经过几个小时的尝试不同的事情和大量的研究后,我已经让 CUDA 使用命令提示符工作,尽管尝试在 CLion 中使用 CUDA 是行不通的。
使用
nvcc main.cu -o build.exe
从命令行生成可执行文件,我可以在 GPU 上运行它,但是在尝试使用 CLion 时出现以下错误:
我相信这是相关的部分,但是如果需要的话还有更多
-- The CUDA compiler identification is unknown
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe -- broken
CMake Error at C:/Users/penci/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/201.7846.88/bin/cmake/win/share/cmake-3.16/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA PLEASE/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_03473\fast && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x86\nmake.exe" -f CMakeFiles\cmTC_03473.dir\build.make /nologo -L CMakeFiles\cmTC_03473.dir\build
Building CUDA object CMakeFiles/cmTC_03473.dir/main.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v11.0\bin\nvcc.exe -x cu -c "C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA PLEASE\cmake-build-debug\CMakeFiles\CMakeTmp\main.cu" -o CMakeFiles\cmTC_03473.dir\main.cu.obj
感谢您的帮助!
================================编辑1 ================= ============
这是 CLion 的完整输出(它也使用不同的项目,但仍然是完全相同的输出)
C:\Users\penci\AppData\Local\JetBrains\CLion2020.1\cygwin_cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST
-- The CUDA compiler identification is NVIDIA 11.0.194
-- Check for working CUDA compiler: /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe
-- Check for working CUDA compiler: /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe -- broken
CMake Error at /cygdrive/c/Users/penci/AppData/Local/JetBrains/CLion2020.1/cygwin_cmake/share/cmake-3.16.5/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make.exe cmTC_03d85/fast && /usr/bin/make -f CMakeFiles/cmTC_03d85.dir/build.make CMakeFiles/cmTC_03d85.dir/build
make[1]: Entering directory '/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp'
Building CUDA object CMakeFiles/cmTC_03d85.dir/main.cu.o
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe" -x cu -c /cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_03d85.dir/main.cu.o
c1xx: fatal error C1083: Cannot open source file: 'C:/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp/main.cu': No such file or directory
main.cu
make[1]: *** [CMakeFiles/cmTC_03d85.dir/build.make:66: CMakeFiles/cmTC_03d85.dir/main.cu.o] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_03d85/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/cygdrive/c/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
==================================编辑2================ ===============
切换到 MSVC 2017 和 Visual Studio 工具链后,我现在得到一个略有不同的错误:
C:\Users\penci\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.7846.88\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA_TEST
-- The CUDA compiler identification is NVIDIA 11.0.194
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe -- broken
CMake Error at C:/Users/penci/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/201.7846.88/bin/cmake/win/share/cmake-3.16/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_23e94\fast && "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe" -f CMakeFiles\cmTC_23e94.dir\build.make /nologo -L CMakeFiles\cmTC_23e94.dir\build
Building CUDA object CMakeFiles/cmTC_23e94.dir/main.cu.obj
C:\PROGRA~1\NVIDIA~2\CUDA\v11.0\bin\nvcc.exe -D_WINDOWS -Xcompiler=" /GR /EHsc" -Xcompiler="-Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -x cu -c C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA_TEST\cmake-build-debug\CMakeFiles\CMakeTmp\main.cu -o CMakeFiles\cmTC_23e94.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_23e94.dir\,-FS
main.cu
Linking CUDA executable cmTC_23e94.exe
C:\Users\penci\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.7846.88\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_23e94.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo "CMakeFiles\cmTC_23e94.dir\main.cu.obj" @C:\Users\penci\AppData\Local\Temp\nmD0E.tmp
LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_23e94.dir\main.cu.obj /out:cmTC_23e94.exe /implib:cmTC_23e94.lib /pdb:C:\Users\penci\OneDrive\Desktop\Code\C-Cpp\CUDA_TEST\cmake-build-debug\CMakeFiles\CMakeTmp\cmTC_23e94.pdb /version:0.0 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/lib/x64 cudadevrt.lib cudart_static.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_23e94.dir/intermediate.manifest CMakeFiles\cmTC_23e94.dir/manifest.res" failed (exit code 1120) with the following output:
Creating library cmTC_23e94.lib and object cmTC_23e94.exp
MSVCRTD.lib(utility_app.obj) : error LNK2019: unresolved external symbol __imp_RoInitialize referenced in function __scrt_initialize_winrt
cmTC_23e94.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'C:\Users\penci\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.7846.88\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/Users/penci/OneDrive/Desktop/Code/C-Cpp/CUDA_TEST/cmake-build-debug/CMakeFiles/CMakeError.log".
[Finished]
通过确保您的 PATH 更新为包含,我能够在 CLion 中获得简单的“Hello World”编译
C:/Program Files/NVIDIA GPU 计算工具包/CUDA/v11.0/bin
我的 CMakeLists.txt 看起来像这样
cmake_minimum_required(VERSION 3.17)
project(cuda_test CUDA)
find_package(CUDA)
set(CMAKE_CUDA_STANDARD 14)
add_executable(cuda_test main.cu)
set_target_properties(
cuda_test
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
只需添加Visual Studio的工具链(架构选择'amd64),并删除mingw的原始工具链,就可以了。