I am using THRUST to support STL in device code.
I declared device vectors and when I am using functions like push_back()
in device code it is showing an error.
CODE:
#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:
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
I am new to THRUST library. Please tell me how to use functions similar to push_back() in device code. I searched for examples but couldn't find one.