gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 02:48:17 26 4
gpt4 key购买 nike

我在 VisualStudio2012 中编译“Hello world”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,在项目属性中添加了包含和库路径。仍然,它在这一行中给了我一个错误:

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

它对 <<< 作出 react ,告诉我需要一个表达式。有没有办法来解决这个问题?在过去的几个小时里,这让我发疯。

编辑:

我在属性>常规中将文件的项目类型更改为“CUDA C/C++”。现在它编译了,但是有错误:

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

最佳答案

我已经设法运行了该示例,但是您的 GPU 需要具有 >=2.0 的计算能力。

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

转到 CUDA/C++ -> 设备。

在“代码生成”中用“compute_20,sm_20”替换您拥有的内容(为清楚起见引用)。

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

关于C++ CUDA 项目未在 VS2012 中编译, "<<<"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23656969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com