[英]C++ CUDA project not compiling in VS2012, error on “<<<”
i have a little problem with compiling a "Hello world" CUDA program in VisualStudio2012. 我在VisualStudio2012中编译“Hello world”CUDA程序时遇到了一些问题。 I have downloaded and example from Nvidia:
我从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;
}
I changed the build configuration to cuda 6.0, added include and library paths in project properties. 我将构建配置更改为cuda 6.0,在项目属性中添加了include和library路径。 Still, it gave me one error in this line:
不过,它在这一行中给了我一个错误:
hello<<<num_blocks,num_threads>>>();
It reacts to <<<, telling me that there is an expression expected. 它对<<<作出反应,告诉我有预期的表达。 Is there a way to fix this?
有没有办法解决这个问题? It's driving me mad for the last few hours.
在过去的几个小时里,它让我发疯了。
EDIT: 编辑:
I changed the Item type of the file to "CUDA C/C++" in properties>general. 我在属性>常规中将文件的Item类型更改为“CUDA C / C ++”。 Now it compiles, but with errors:
现在它编译,但有错误:
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 ==========
And if i comment the printf function, then i just get something like this: 如果我评论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 ==========
I've managed to run that example, however your GPU needs to have compute capability >=2.0. 我已成功运行该示例,但您的GPU需要具有> = 2.0的计算能力。
Right click on project and choose "Properties". 右键单击项目,然后选择“属性”。
Go to CUDA/C++ -> Device. 转到CUDA / C ++ - >设备。
On "Code Generation" replace what you have with "compute_20,sm_20" (quotes for clarity). 在“代码生成”中用“compute_20,sm_20”代替你所拥有的(为了清晰起见,引号)。
EDIT (regarding Ptx assembly aborted due to errors
): If you remove the __device__
qualifier from const char *STR
it should compile. 编辑(关于
Ptx assembly aborted due to errors
):如果从const char *STR
删除__device__
限定符,它应该编译。 (When you have commented out the printf
function) - That was the reason for the ptxas error. (当你注释掉
printf
函数时) - 这就是ptxas错误的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.