Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA compiling error after installing it

Tags:

c++

cuda

I wanted to start CUDA Programming with C++ and installed the toolkit v9.0 from the official Nvidia website. I ran deviceQuery.cpp on VS 2017 and everything worked perfectly:

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 960M"
  CUDA Driver Version / Runtime Version          9.0 / 9.0
  CUDA Capability Major/Minor version number:    5.0
  Total amount of global memory:                 2048 MBytes (2147483648 bytes)
  ( 5) Multiprocessors, (128) CUDA Cores/MP:     640 CUDA Cores
  GPU Max Clock rate:                            1176 MHz (1.18 GHz)
  Memory Clock rate:                             2505 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  CUDA Device Driver Mode (TCC or WDDM):         WDDM (Windows Display Driver Model)
  Device supports Unified Addressing (UVA):      Yes
  Supports Cooperative Kernel Launch:            No
  Supports MultiDevice Co-op Kernel Launch:      No
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

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

Then I tried running bandwidthTest.cu and I have some compile errors:

Severity    Code    Description File    Line    Category    Suppression State
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 504     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 505     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 506     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 538     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 1043        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 1558        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 2371        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits 2371        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility    543     
Error       class "std::enable_if<<error-constant>, int>" has no member "type"  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xtr1common  58      
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility    3135        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility    3662        
Error       class "std::enable_if<<error-constant>, void>" has no member "type" C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xtr1common  58      
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xmemory0    390     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xmemory0    1002        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xmemory0    1322        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xstring 1718        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xutility    298     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\vector  495     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\algorithm   278     
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\memory  1540        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\memory  1547        
Error       constant value is not known C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\memory  2482        
Error       expression must have a constant value   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\memory  2582        
Error       more than one instance of overloaded function "std::_Deallocate_plain" matches the argument list:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xstring 1780        
Error       more than one instance of overloaded function "std::_Deallocate_plain" matches the argument list:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xstring 1780        
Error       more than one instance of overloaded function "std::_Deallocate_plain" matches the argument list:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xstring 1780        
Error       more than one instance of overloaded function "std::_Deallocate_plain" matches the argument list:   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\xstring 1780        
Error   MSB3721 The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe" -gencode=arch=compute_30,code=\"sm_30,compute_30\" -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_70,code=\"sm_70,compute_70\" --use-local-env --cl-version 2017 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\HostX86\x64" -x cu  -I./ -I../../common/inc -I./ -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\/include" -I../../common/inc -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static -Xcompiler "/wd 4819" -g   -DWIN32 -DWIN32 -D_MBCS -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MTd " -o x64/Debug/bandwidthTest.cu.obj "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\1_Utilities\bandwidthTest\bandwidthTest.cu"" exited with code 1. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 9.0.targets 707 

I am just compiling the existing bandwidth.cu in 1_Utilities after installing the toolkit and I am using VS 2017. I have searched a long time for a solution on the Internet but I can't seem to find anything. Any help is appreciated.

EDIT: I have installed a side-by-side MSVC toolset: https://blogs.msdn.microsoft.com/vcblog/2017/11/15/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/

Now most of my errors are gone but the last one still remains (the long one). This seems to be an error of a different kind.

EDIT 2: It seems that the line -Bv in the command line was creating the error. I removed it and now all my projects compile successfully. This seems to be a bug with the new version of VC++ and will probably be fixed soon.

like image 268
Wido Seidel Avatar asked Dec 12 '17 19:12

Wido Seidel


2 Answers

To summarize what I did: In the Visual Studio 2017 installer select Modify then at the top click Individual Components, scroll down to Compilers, build tools, and runtimes and check VC++ 2017 version 15.4 v14.11 toolset (that is going to check Visual C++ 2017 Redistributable Update as well) and then you modify it. After that you go to a specific location. For me it was here:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\14.11

and copy the file with the .props -ending to your solution. In VS you right click your project, select Unload Project and right click again to select Edit -project name-. Here you look for the line that says

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

and above that line you add

<Import Project="$(SolutionDir)\Microsoft.VCToolsVersion.14.11.props" />

You save the file and reload the project and you should be good to go.

like image 71
Wido Seidel Avatar answered Nov 14 '22 07:11

Wido Seidel


I've managed to write a script in PowerShell that implements solution from Wido Seidel. Make a backup of the folder before you start the script and configure your paths.

#path where CUDA samples are located
$files = Get-ChildItem "c:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\" -Recurse -Include "*_vs2017.vcxproj"


#string to find
$stringToFind= '<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />'
#strings that will be added actually it's string with two lines
$stringToAdd = '  <Import Project="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\14.11\Microsoft.VCToolsVersion.14.11.props" />' + "`r`n" + 
                '  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />'


for($i=0;$i -le $files.count;$i++){
    Write-Host $files[$i].FullName
    #the path of file that is currently being worked on
    $filePath = $files[$i].FullName
    #content of the file
    $fileToChange = Get-Content $filePath
    for($j = 0;$j -le $fileToChange.Count;$j++){
        if($fileToChange[$j].Contains($stringToFind)){
            #find the string from above and break the for loop
            #since we only need to find 1st line and add one line above it
            $fileToChange[$j] = $stringToAdd
            break
        }
    }
    #writing changes to a file
    $fileToChange | Set-Content $filePath
}

Let me know if it works.

like image 1
knile Avatar answered Nov 14 '22 08:11

knile