CUDA编译器无法编译简单的测试程序

CUDA compiler is unable to compile a simple test program

我正在尝试获取 NVIDIA 的 CUDA 设置并将其安装在我的 PC 上,该电脑具有 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 Studio19\Community\VC\Tools\MSVC.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-01.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 Studio17\Community\VC\Tools\MSVC.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-01.7846.88\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_23e94.dir --rc=C:\PROGRA~2\WI3CF2~1\bin0177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\bin0177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~217\COMMUN~1\VC\Tools\MSVC16~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~217\COMMUN~1\VC\Tools\MSVC16~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-01.7846.88\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.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:/程序Files/NVIDIA GPU 计算Toolkit/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 2017 和这些设置