CUDA on Thrust:如何实现优先级队列

发布于 2024-10-03 18:28:45 字数 1080 浏览 0 评论 0原文

我的计划是使用皮尔逊相关性计算距离矩阵,并从距离矩阵中获取每个节点的 q- 最近邻 (q=ln(n)) 并将它们放入结果向量中。我在 C++ 中使用相关函数循环内的 STL 优先级队列来完成此操作。

但你认为,有什么办法可以在 GPU 中做到这一点吗?

  1. 任何人都可以帮助我,我怎样才能在GPU中做同样的事情(可能推力对我来说会更容易!)
  2. 如何在GPU中实现优先级队列

这是我的 CPU(C++ STL) 代码:

例如,

      distance matrix
-----------------------
 0 3 2 4
 3 0 4 5
 2 4 0 6
 .....

output in a object vector
=================

    source  target  weight
--------------------------------
0 2 2
0 1 3  ....    (sorted by Edge weight)

1 0 3
1 2 4

2 0 2
.....


calculatePearsonCorrelation(float  vector1[], float vector2[], int m) {
               // float distancePearson(vector vector1, vector vector2){

                            int i;
                            float a=0,b=0,c=0,d=0, e = 0, sumX=0, sumY=0;

                            //m = vector1.size();

                            for(i=0;iq){
                        MIN=pqx.top().get_corr();
                        if(corr::iterator it = qNNVector.begin(); it!=qNNVector.end(); ++it) {
            fout 

my plan is to calculate a distance matrix using Pearsons's correlation and get q- nearest neighbors for each nodes (q=ln(n)) from the distance matrix and put them in a result vector. I did it in C++ using STL priority queue inside the loop of correlation function.

But do you think, there is any way to do it in GPU?

  1. Can anyone help me, how can I do the same in GPU (probably Thrust will be easier for me!)
  2. How to implement priority queue in GPU?

Here is my CPU(C++ STL) code:

For example,

      distance matrix
-----------------------
 0 3 2 4
 3 0 4 5
 2 4 0 6
 .....

output in a object vector
=================

    source  target  weight
--------------------------------
0 2 2
0 1 3  ....    (sorted by Edge weight)

1 0 3
1 2 4

2 0 2
.....


calculatePearsonCorrelation(float  vector1[], float vector2[], int m) {
               // float distancePearson(vector vector1, vector vector2){

                            int i;
                            float a=0,b=0,c=0,d=0, e = 0, sumX=0, sumY=0;

                            //m = vector1.size();

                            for(i=0;iq){
                        MIN=pqx.top().get_corr();
                        if(corr::iterator it = qNNVector.begin(); it!=qNNVector.end(); ++it) {
            fout 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殊姿 2024-10-10 18:28:45

您是否尝试过使用 Thrust 排序?您只需读出前 q 个元素即可。如果有足够的元素,您可能会看到相当大的加速。

Have you tried using Thrust's sort? You can just read out the first q elements. If there are enough elements, you'll likely see a decent speedup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文