how to cast thrust::device_vector<int> to raw pointer

℡╲_俬逩灬. 提交于 2019-11-27 02:41:17

问题


I have a thrust device_vector. I want to cast it to a raw pointer so that I can pass it to a kernel. How can I do so?

thrust::device_vector<int> dv(10);
//CAST TO RAW
kernel<<<bl,tpb>>>(pass raw)

回答1:


You can do this using thrust::raw_pointer_cast. The device vector class has a member function data which will return a thrust::device_ptr to the memory held by the vector, which can be cast, something like this:

thrust::device_vector<int> dv(10);

int * dv_ptr = thrust::raw_pointer_cast(dv.data());

kernel<<<bl,tpb>>>(dv_ptr)

(disclaimer: written in browser, never compiled, never tested). There is a full working example of this included with thrust: unwrap_pointer.cu



来源:https://stackoverflow.com/questions/11113485/how-to-cast-thrustdevice-vectorint-to-raw-pointer

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