问题是:是否有一种方法可以在Cuda内核中使用类“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
是否有一种类似使用内核代码中支持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]);
}
}
}