CUDA compiler is unable to compile a simple test program
Asked Answered
C

2

7

I am trying to get NVIDIA's CUDA setup and installed on my PC which has an NVIDIA GEFORCE RTX 2080 SUPER graphics card. After hours of trying different things and lots of research I have gotten CUDA to work using the Command Prompt, though trying to use CUDA in CLion will not work.

Using

nvcc main.cu -o build.exe

From the command line generates the executable and I can run it on the GPU, however I have the following error when trying to use CLion:

I believe this is the relevant part, however there is more if that is required

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

Thanks for any help!

============================== EDIT 1 =============================

Here is the full output from CLion (It is using a different project too but it is still the exact same output)

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]

=============================== EDIT 2 ===============================

After switching to MSVC 2017 and Visual Studio toolchain I now get a slightly different error:

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]
Cnidoblast answered 23/7, 2020 at 18:45 Comment(11)
need to see at least a few additional lines after the last one you show here.Cenobite
I have added the full output now so hopefully that helpsCnidoblast
Typical issue with Nvidias software, it's not compatible with the most recent MSVC versions. You have to set up the project with an older MSVC tool chain. v141 should work. Nvidia is always 1-2 years behind in compatibility. And doesn't work within cygwin environment.Nebula
And is that by chance a 32bit project you are trying to build with CLion? Looks like it, and that is no longer supported for CUDA.Nebula
I have set up CLion to use MSVC 2017 and the Visual Studio tool chain but I still get an error -- I have put this error in the question now. How would I go about changing it to 64 bit? I have 64 bit windows 10 ProCnidoblast
@Cnidoblast In response to your latest comment, if you're in Visual Studio you should see a box near on the left of the green arrow |> (which is usually Local Windows Debugger). In that box you can select the architecture.Wavelet
@Ext3h: The question plainly states that the compiler works from the command line, so this isn't any sort of compiler incompatibility problem and suggesting so is wrongFun
@Fun try reading the log again. Standalone, he invoked nvcc directly. With CLion first attempt, there is a telling HostX86\x86 in the path for the MSVC tool chain, plus obvious cygwin paths. Neither works with nvcc. Now it's down to a simple linker issue.Nebula
@Cnidoblast You may now be missing -DCMAKE_SYSTEM_VERSION=10 or a similar flag. It appears to be linking against a too old runtime library.Nebula
@Nebula I am using MSVC 2017 in the Visual Studio toolchain and have set it to amd64 (which I think is the 64 bit project?). I have also added -DCMAKE_SYSTEM_VERSION=10 to the CMake options too but I am still getting what appears to be the same error. Have I done something horribly wrong or is it just my system having the wrong versions of things?Cnidoblast
I have also noticed that using MSVC toolchain leads to almost the exact same error except it says that cl.exe is unable to compile a simple test program. Might this have anything to do with the issue?Cnidoblast
L
10

I was able to get a simple "Hello World" compiling in CLion by making sure your PATH is updated to include

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/bin

My CMakeLists.txt looks like this

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)

And using Visual Studio 2017 with these settings in the toolchain enter image description here

Leto answered 3/8, 2020 at 6:20 Comment(3)
Thank you so, so much. These settings and the slightly different CMakeLists.txt file have fixed the issue and now CUDA is working for me in CLion. Thanks again!Cnidoblast
Thx it works, the key issue here is the architecture must be amd64. Ref: youtrack.jetbrains.com/issue/CPP-22371Burlburlap
Also, be sure to ONLY put the /bin/ and /libnvvp/ folders to PATH! I have made the mistake of putting other folders in PATH (e.g. extras/CUPTI), and this caused an error for me. If you have to have extra folder (though I don't know that it would work), I recommend at least putting the /bin/ and /libnvvp/ folder FIRST (i.e. ahead of the others in PATH)Amandaamandi
T
0

just add toolchain of visual studio(the architecture select 'amd64), and delete origin toolchain of mingw, it will work.

Tjon answered 26/10, 2023 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.