如何投射thrust :: device_vector< int>到原始指针 [英] how to cast thrust::device_vector<int> to raw pointer
本文介绍了如何投射thrust :: device_vector< int>到原始指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个推力 device_vector
。我想把它转换为一个原始指针,以便我可以将它传递给内核。我该怎么办?
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)
推荐答案
你可以使用 thrust :: raw_pointer_cast
。设备向量类具有成员函数 data
,它将向量返回一个 thrust :: device_ptr
,它可以被转换,像这样:
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)
$ b b
(免责声明:用浏览器编写,从不编译,从未测试过)。有一个完整的工作示例,包括推力: unwrap_pointer。 cu
这篇关于如何投射thrust :: device_vector< int>到原始指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文