CUDA on Thrust:如何实现优先级队列
我的计划是使用皮尔逊相关性计算距离矩阵,并从距离矩阵中获取每个节点的 q- 最近邻 (q=ln(n)) 并将它们放入结果向量中。我在 C++ 中使用相关函数循环内的 STL 优先级队列来完成此操作。
但你认为,有什么办法可以在 GPU 中做到这一点吗?
- 任何人都可以帮助我,我怎样才能在GPU中做同样的事情(可能推力对我来说会更容易!)
- 如何在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?
- Can anyone help me, how can I do the same in GPU (probably Thrust will be easier for me!)
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 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.