我正在使用THRUST来支持设备代码中的STL。
我声明了设备向量,当我在设备代码中使用push_back()
等函数时,它显示错误。
代码:
#include <thrust/device_vector.h>
using namespace thrust;
__global__ void kernel_fillholes_g(uchar *M, bool * visited, int x, int y)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
int j = blockIdx.y * blockDim.y + threadIdx.y;
if (M[i*x + j] && !visited[i*x + j] && (i==0 || j==0 || i==x-1 || j==y-1))
{
M[i*x + j] = 0;
s1.push_back(i);
s2.push_back(j);
//BFS_g(M, visited, s1, s2, x, y);
}
}
void func(uchar *M, bool * visited,)
{
//
copy M and bool to device memory
//
dim3 block1(BLOCK_SIZE_X, BLOCK_SIZE_Y);
dim3 grid1(size_x/BLOCK_SIZE_X, size_y/BLOCK_SIZE_Y);
device_vector <int> s1;
device_vector <int> s2;
kernel_fillholes_g<<<grid1, block1>>>(M, visited, s1, s2);
}
错误:
error : calling a __host__ function("thrust::detail::vector_base<int,thrust::device_malloc_allocator<int> > ::push_back")
from a __global__ function("kernel_fillholes_g") is not allowed
我是THRUST图书馆的新手。请告诉我如何在设备代码中使用类似于push_back()的函数。我搜索了一些例子,却找不到一个。