How to pass an array of vectors to cuda kernel?

时光毁灭记忆、已成空白 提交于 2019-12-02 09:10:58
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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!