使用Thrust CUDA对对象进行排序 [英] Sorting objects with Thrust CUDA

查看:631
本文介绍了使用Thrust CUDA对对象进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Thrust库对对象进行排序?
我有以下结构:

Is it possible to sort objects using the Thrust library? I have the following struct:

struct OB{
  int N;
  Cls *C; //CLS is another struct.
}

可以使用thrust来对OB数组进行排序N?你能提供一个简单的例子使用推力来排序对象?如果推力不能这样做,有没有任何其他CUDA库允许我这样做?

Is it possible to use thrust in order to sort an array of OB according to N? Can you provide a simple example on using thrust to sort objects? If thrust is not able to do so, is there any other CUDA libraries that allows me to do so?

推荐答案

thrust :: sort 显示它接受一个比较运算符。请参阅示例如何定义和使用这些示例。我没有测试这个,但基于这个例子,你所需要的是一个类似于这样的结构:

The docs for thrust::sort show it accepts a comparison operator. See in their example how those are defined and used. I haven't tested this, but based on the example, all you would need is a struct that looks something like this:

struct OBCmp {
  __host__ __device__
  bool operator()(const OB& o1, const OB& o2) {
      return o1.N < o2.N;
  }
};

然后调用 thrust :: sort(obs.begin obs.end(),OBCmp())

这篇关于使用Thrust CUDA对对象进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆