使用CUDA Thrust的2D device_vector错误

时间:2014-06-01 15:50:10

标签: c++ visual-studio-2012 vector cuda thrust

我使用CUDA Thrust编写了一个简单的代码。我需要在GPU上分配2D矢量,但我得到error MSB3721

  

D:\ Cuda \ NVIDIA GPU Computing Toolkit \ CUDA \ v6.0 \ include \ thrust / device_vector.h(52):错误:不支持外部调用(找到非内联调用_ZN6thrust6detail11vector_baseIiNS_23device_malloc_allocatorIiEEED2Ev)    kernel.cu   C:\ Program Files(x86)\ MSBuild \ Microsoft.Cpp \ v4.0 \ V110 \ BuildCustomizations \ CUDA 6.0.targets(597,9):错误MSB3721:命令“”D:\ Cuda \ 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”D:\ Microsoft Visual Studio 11.0 \ VC \ bin \ x86_amd64“-I”D:\ Cuda \ NVIDIA GPU Computing Toolkit \ CUDA \ v6.0 \ include“-I”D:\ Cuda \ NVIDIA GPU Computing Toolkit \ CUDA \ v6.0 \ include“ -G --keep-dir x64 \ Debug -maxrregcount = 0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler“/ EHsc / W3 / nologo / Od / Zi / RTC1 / MDd“-o x64 \ Debug \ kernel.cu.obj”D:\ VS Codes \ Projects \ CUDASimpleImageProcessing \ CUDASimpleImageProcessing \ kernel.cu“”退出代码2。   ==========构建:0成功,1个失败,0个最新,0个跳过==========

代码是

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
using namespace thrust;
int main()
{
int height = 5, width = 5;
device_vector<device_vector<int>> d_ndata (height, device_vector<int> (width, 0));
//  d_ndata.resize(newheight, vector<uchar> (newwidth, 0));

return 0;
}

帮助请...

1 个答案:

答案 0 :(得分:1)

推力不能处理向量的向量。您应该将矩阵展平为单个向量,如下例所示:

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>

using namespace thrust;

int main()
{
    int height = 5, width = 5;
    device_vector<int> d_ndata(height*width);

    return 0;
}