Reputation: 3517
Using device_vector:
thrust::device_vector< int > iVec;
int* iArray = thrust::raw_pointer_cast( &iVec[0] );
but how can I do it if I have an array of device_vectors?
thrust::device_vector<int> iVec[10];
Ideally I would like to pass my array of device_vector to a 1D array to be handled on a CUDA kernel. Is it possible?
Upvotes: 1
Views: 1602
Reputation: 72372
If I have understood your question correctly, what you are really try to do is create an array of raw pointers from an array of thrust::device_vectors
. You should be able to do this like so:
const int N = 10;
thrust::device_vector<int> iVec[N];
int * iRaw[N];
for(int i=0; i<N; i++)
iRaw[i] = thrust::raw_pointer_cast(iVec[i].data());
int ** _iRaw;
size_t sz = sizeof(int *) * N;
cudaMalloc((void ***)&_iRaw, sz);
cudaMemcpy(_iRaw, iRaw, sz, cudaMemcpyHostToDevice);
[disclaimer: written in browser, never compiled, never tested, use at own risk]
In the above code snippet, _iRaw
holds the raw pointers of each of the device vectors in iVec
. You could pass that to a kernel if you really wanted to.
Upvotes: 1