Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

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

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...