简体   繁体   English

推力库-如何编写包装器?

[英]Thrust library - how to write a wrapper?

I have a VS2010 project written in C++ and want to use the thrust::sort functions. 我有一个用C ++编写的VS2010项目,想使用推力::: sort函数。 My data is currently in a POD (Plain Old Date) struct. 我的数据当前处于POD(普通旧日期)结构中。 The thrust::sort routines require a host and device vector container to work. push :: sort例程需要主机和设备向量容器才能工作。 What's the easiest way to interface my POD data for use by thrust::sort? 接口我的POD数据以供推力::: sort使用的最简单方法是什么?

Thanks, Dave 谢谢戴夫

The very first page of the Thrust user guide gives an example to do exactly that: Thrust用户指南的第一页提供了一个示例来完成此操作:

thrust::host_vector<int> hv = populate();        // make data on host

thrust::device_vector<int> dv(hv.begin(), hv.end()); // copy to device

thrust::sort(dv.begin(), dv.end());              // sort on device

thrust::copy(dv.begin(), dv.end(), hv.begin());  // copy back

Instead of int you can use your own POD structure, and you can pass a comparator to the sort algorithm. 您可以使用自己的POD结构来代替int ,并且可以将比较器传递给sort算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM