I now have
thrust::device_vector<int> A[N];
and my kernel function
__global__ void kernel(...) {
auto a = A[threadIdx.x];
}
I know that via thrust::raw_pointer_cast I could pass a device_vector to kernel. But how could I pass an array of vector to it?
talonmies
The really short answer is that you basically can't, and the longer answer is that you really shouldn't even if you discover or are presented with a hacky way of doing this.
And in the spirit of that advice, what you can do is something like this:
thrust::device_vector<int> A(N);
thrust::device_vector<int> B(N);
thrust::device_vector<int> C(N);
thrust::device_vector<int> D(N);
// .....
thrust::device_vector<int*> E(4);
E.push_back(thrust::raw_pointer_cast(A.data());
E.push_back(thrust::raw_pointer_cast(B.data());
E.push_back(thrust::raw_pointer_cast(C.data());
E.push_back(thrust::raw_pointer_cast(D.data());
int* E_p = thrust::raw_pointer_cast(E.data());
// ....
kernel<<<...>>>(E_p);
The code above should work, but there is so much wrong with it that I wouldn't recommend ever using it for anything. You have been warned.
来源:https://stackoverflow.com/questions/49579847/how-to-pass-an-array-of-vectors-to-cuda-kernel