C ++ CUDA项目未在VS2012中编译,错误“<<<<<

时间:2014-05-14 14:04:19

标签: c++ cuda

编译一个" Hello world"我有一点问题。 VisualStudio2012中的CUDA程序。我从Nvidia下载了示例:

#include "stdafx.h"
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>

__device__ const char *STR = "HELLO WORLD!";
const char STR_LENGTH = 12;

__global__ void hello()
{
    printf("%c\n", STR[threadIdx.x % STR_LENGTH]);
}

int main(void)
{
    int num_threads = STR_LENGTH;
    int num_blocks = 1;
    hello<<<num_blocks,num_threads>>>();
    cudaDeviceSynchronize();

    return 0;
}

我将构建配置更改为cuda 6.0,在项目属性中添加了include和library路径。不过,它在这一行中给了我一个错误:

hello<<<num_blocks,num_threads>>>();

它对&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;有没有办法来解决这个问题?在过去的几个小时里,它让我发疯了。

编辑:

我将文件的Item类型更改为&#34; CUDA C / C ++&#34;在属性&gt;一般。现在它编译,但有错误:

1>------ Build started: Project: CUDATest, Configuration: Debug Win32 ------
1>  Compiling CUDA source file CUDATest.cu...
1>  
1>  C:\Users\Rafał\Documents\Visual Studio 2012\Projects\CUDATest\CUDATest>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\CUDATest.cu.obj "C:\Users\Rafał\Documents\Visual Studio 2012\Projects\CUDATest\CUDATest\CUDATest.cu" 
1>nvcc : warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
1>C:/Users/Rafa│/Documents/Visual Studio 2012/Projects/CUDATest/CUDATest/CUDATest.cu(15): error : calling a __host__ function("printf") from a __global__ function("hello") is not allowed
1>  CUDATest.cu
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 6.0.targets(597,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\CUDATest.cu.obj "C:\Users\Rafał\Documents\Visual Studio 2012\Projects\CUDATest\CUDATest\CUDATest.cu"" exited with code 2.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

如果我评论printf函数,那么我只是得到这样的东西:

1>------ Build started: Project: CUDATest, Configuration: Debug Win32 ------
1>  Compiling CUDA source file CUDATest.cu...
1>  
1>  C:\Users\Rafał\Documents\Visual Studio 2012\Projects\CUDATest\CUDATest>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\CUDATest.cu.obj "C:\Users\Rafał\Documents\Visual Studio 2012\Projects\CUDATest\CUDATest\CUDATest.cu" 
1>nvcc : warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
1>ptxas : fatal error : Ptx assembly aborted due to errors
1>  CUDATest.cu
1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 6.0.targets(597,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\CUDATest.cu.obj "C:\Users\Rafał\Documents\Visual Studio 2012\Projects\CUDATest\CUDATest\CUDATest.cu"" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

1 个答案:

答案 0 :(得分:2)

我已成功运行该示例,但您的GPU需要具有&gt; = 2.0的计算能力。

右键单击项目并选择“属性”。

转到CUDA / C ++ - &gt;设备

在“代码生成”中用“compute_20,sm_20”替换你所拥有的内容(为了清晰起见,引号)。

编辑(关于Ptx assembly aborted due to errors):如果从__device__删除const char *STR限定符,则应编译。 (当您注释掉printf函数时) - 这就是ptxas错误的原因。