问题是:有没有办法在Cuda内核中使用类“vector”?当我尝试我得到以下错误:在CUDA设备代码中使用std :: vector
error : calling a host function("std::vector<int, std::allocator<int> > ::push_back") from a __device__/__global__ function not allowed
所以有办法在全球部分使用一个向量? 我最近尝试以下操作:
- 创建一个新的Cuda项目
- 进入项目的性质
- 开放CUDA C/C++
- 进入设备
- 变化“代码值代“设置为这个值: compute_20,sm_20
........之后,我能够使用我Cuda内核中的printf标准库函数。
有没有办法在内核代码中支持printf的方式使用标准库类vector
?这是在内核代码用printf的例子:
// this code only to count the 3s in an array using Cuda
//private_count is an array to hold every thread's result separately
__global__ void countKernel(int *a, int length, int* private_count)
{
printf("%d\n",threadIdx.x); //it's print the thread id and it's working
// vector<int> y;
//y.push_back(0); is there a possibility to do this?
unsigned int offset = threadIdx.x * length;
int i = offset;
for(; i < offset + length; i++)
{
if(a[i] == 3)
{
private_count[threadIdx.x]++;
printf("%d ",a[i]);
}
}
}
+1完全合法的问题(不知道为什么它被否决。很不幸,答案是目前还没有。 – harrism