从 Thrust::device_vector 到原始指针并返回?
我了解如何从向量转换为原始指针,但我跳过了如何向后转换的节拍。
// our host vector
thrust::host_vector<dbl2> hVec;
// pretend we put data in it here
// get a device_vector
thrust::device_vector<dbl2> dVec = hVec;
// get the device ptr
thrust::device_ptr devPtr = &d_vec[0];
// now how do i get back to device_vector?
thrust::device_vector<dbl2> dVec2 = devPtr; // gives error
thrust::device_vector<dbl2> dVec2(devPtr); // gives error
有人可以解释/给我举个例子吗?
I understand how to go from a vector to a raw pointer but im skipping a beat on how to go backwards.
// our host vector
thrust::host_vector<dbl2> hVec;
// pretend we put data in it here
// get a device_vector
thrust::device_vector<dbl2> dVec = hVec;
// get the device ptr
thrust::device_ptr devPtr = &d_vec[0];
// now how do i get back to device_vector?
thrust::device_vector<dbl2> dVec2 = devPtr; // gives error
thrust::device_vector<dbl2> dVec2(devPtr); // gives error
Can someone explain/point me to an example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://code.google.com/p/thrust/source/browse/ example/cuda/wrap_pointer.cu
Thrust 为这个问题提供了一个很好的例子。
从推力容器获取原始指针已经由您自己回答了。
http://code.google.com/p/thrust/source/browse/examples/cuda/wrap_pointer.cu
Thrust provides a good example for this question.
And getting the raw pointer from thrust containers is as answered already by yourself..
您可以像标准容器一样初始化和填充推力向量,即通过迭代器:
在您的简单示例中,无需通过指针绕道,因为您可以直接复制其他容器。一般来说,如果您有一个指向数组开头的指针,并且提供了数组大小,则可以使用
v3
版本。You initialize and populate thrust vectors just like standard containers, i.e. via iterators:
In your simple example there's no need to go the detour via pointers, as you can just copy the other container directly. In general, if you have a pointer to the beginning of an array, you can use the version for
v3
if you supply the array size.没有。尽管您应该能够重用初始向量变量。
There is not. Although you should be able to reuse the initial vector variable.