安装后CUDA编译错误

时间:2017-12-12 19:42:02

标签: c++ cuda

我想用C ++开始CUDA编程,并从官方的Nvidia网站安装了工具包v9.0。我在VS 2017上运行了deviceQuery.cpp,一切都运行良好:

 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

然后我尝试运行bandwidthTest.cu并且我有一些编译错误:

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 

我只是在安装工具包之后编译1_Utilities中的现有bandwidth.cu并且我正在使用VS 2017.我已经搜索了很长时间在互联网上寻找解决方案,但我似乎无法找到任何东西。任何帮助表示赞赏。

编辑:我已经安装了并排的MSVC工具集:https://blogs.msdn.microsoft.com/vcblog/2017/11/15/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/

现在我的大多数错误都消失了,但最后一个仍然存在(长期错误)。这似乎是一种不同的错误。

编辑2:命令行中的 -Bv 行似乎正在创建错误。我删除它,现在我的所有项目都成功编译。这似乎是新版VC ++的一个错误,很快就会修复。

2 个答案:

答案 0 :(得分:11)

总结一下我的所作所为: 在Visual Studio 2017安装程序中选择修改,然后在顶部单击单个组件,向下滚动到编译器,构建工具和运行时并选中< strong> VC ++ 2017版本15.4 v14.11工具集(即将检查 Visual C ++ 2017可再发行更新)然后进行修改。之后,您将前往特定位置。对我来说,就在这里:

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

并将带有 .props 的文件复制到您的解决方案中。在VS中,右键单击您的项目,选择卸载项目,然后再次右键单击以选择编辑 - 项目名称 - 。在这里,您可以找到

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

以及您添加的那一行

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

您保存文件并重新加载项目,您应该好好去。

答案 1 :(得分:1)

我已经设法在PowerShell中编写了一个脚本来实现Wido Seidel的解决方案。在启动脚本并配置路径之前备份文件夹。

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

让我知道它是否有效。