【问题标题】:sort one array by another on the gpu在 gpu 上对一个数组进行排序
【发布时间】:2018-12-23 10:59:55
【问题描述】:

我有代码,看起来像:

...
const N=10000; 
std::array<std::pair <int,int>,N> nnt; 
bool compar(std::pair<int,int> i, std::pair <int,int> j) {return (int) 
(i.second) > (int)(j.second);}
...
int main(int argc, char **argv)
{
  #pragma acc data create(...,nnt)
    {
       #pragma acc parallel loop
         {...}
         //the nnt array is filled here
         //here i need to sort nnt allocated on gpu, using the 
         //comparator compar()
    }
}

所以我需要对一组对进行排序,通过 OpenAcc 的 CUDA 分配在 GPU 上。 据我了解,我不太可能在 GPU 上对 std::pair 的 std::array 进行排序。

实际上,我需要将分配在 gpu 上的一个数组与分配在 gpu 上的另一个数组排序,i。 e.如果有

int a[N];
int b[N];

通过 CUDA 或 OpenAcc 分配或复制到 GPU,我需要按数组 b 的值对数组 a 进行排序,并且我需要在 GPU 上完成这种排序。可能有一些 CUDA 函数会有所帮助,或者可以使用 CUDA 推力排序函数(如推力::stable_sort),我不知道。有没有办法做到这一点?

【问题讨论】:

    标签: sorting cuda gpgpu openacc


    【解决方案1】:

    有办法吗?

    是的,一种可能的方法是使用thrust::sort_by_key,它允许您使用设备指针对设备数据进行排序。

    blog 解释了推力和 OpenACC 之间的接口方法。包括在例程之间传递一个deviceptr

    这个example code 可能很有趣。具体来说,hash example 给出了从 OpenACC 调用 thrust::sort_by_key 的完整示例。

    【讨论】:

      猜你喜欢
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-07
      • 2020-09-27
      • 2013-11-10
      • 2017-08-28
      • 1970-01-01
      相关资源
      最近更新 更多