且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将向量数组传递给cuda内核?

更新时间:2021-09-19 23:21:49

真正的简短答案是您基本上不能这样做,并且更长的答案是,即使您发现了这种做法,也不知道该怎么做。

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.