how to cast thrust::device_vector to raw pointer

后端 未结 1 1981
花落未央
花落未央 2020-12-09 09:04

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<         


        
相关标签:
1条回答
  • 2020-12-09 09:33

    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

    0 讨论(0)
提交回复
热议问题