1

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?

4
  • You understand that a device_vector is a C++ class in host memory? An array of device_vector is an array of C++ class instances, also in host memory. There is no raw device pointer because there is no device memory involved. Commented Oct 17, 2012 at 11:24
  • @talonmies: So,there is no way I can covert the array of device_vector to 1D host array? Commented Oct 17, 2012 at 11:36
  • An array of device vectors is already 1D host array. What is it that you are really trying to do? Commented Oct 17, 2012 at 11:47
  • I want to pass the array to a kernel so I can deal with it with all the elements in order, thinking that every array might have different length of the vector. Commented Oct 17, 2012 at 11:53

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.