推力:reduce_by_key 比预期慢
Thrust : reduce_by_key is slower than expected
我有以下代码:
thrust::device_vector<int> unique_idxs(N);
thrust::device_vector<int> sizes(N);
thrust::pair<thrust::device_vector<int>::iterator, thrust::device_vector<int>::iterator> new_end = reduce_by_key(idxs.begin(), idxs.end(),thrust::make_constant_iterator(1),unique_idxs.begin(),sizes.begin());
int unique_elems=new_end.first-unique_idxs.begin();
sizes.erase(new_end.second, sizes.end());
其中 idxs
是索引的排序设备向量,unique_idxs
是唯一索引,sizes
是每个索引的频率。
为我的程序计时 我发现与处理相同或更多数据量的其他操作相比,此操作需要很长时间...有什么方法可以加快它的速度吗?
事实上,当 idxs
的大小超过 500k 元素时,这部分也会导致 NVIDIA Kernel Mode Crash。
编辑
我找到了有关 Thrust 的演示文稿,我认为我正在做的正是它在第 38 页上描述的内容,即使是 10M 点,它也应该 运行 以毫秒为单位。如演示文稿所示,我正在 GTX 480 上测试我的代码。
http://thrust.googlecode.com/files/GTC%202010%20%28Part%202%29%20-%20Thrust%20By%20Example.pdf
我犯了一个可怕的错误!我没有正确计时我的代码,因此,我认为延迟是由于减少部分造成的,而我之前执行的转换是罪魁祸首。
我有以下代码:
thrust::device_vector<int> unique_idxs(N);
thrust::device_vector<int> sizes(N);
thrust::pair<thrust::device_vector<int>::iterator, thrust::device_vector<int>::iterator> new_end = reduce_by_key(idxs.begin(), idxs.end(),thrust::make_constant_iterator(1),unique_idxs.begin(),sizes.begin());
int unique_elems=new_end.first-unique_idxs.begin();
sizes.erase(new_end.second, sizes.end());
其中 idxs
是索引的排序设备向量,unique_idxs
是唯一索引,sizes
是每个索引的频率。
为我的程序计时 我发现与处理相同或更多数据量的其他操作相比,此操作需要很长时间...有什么方法可以加快它的速度吗?
事实上,当 idxs
的大小超过 500k 元素时,这部分也会导致 NVIDIA Kernel Mode Crash。
编辑
我找到了有关 Thrust 的演示文稿,我认为我正在做的正是它在第 38 页上描述的内容,即使是 10M 点,它也应该 运行 以毫秒为单位。如演示文稿所示,我正在 GTX 480 上测试我的代码。 http://thrust.googlecode.com/files/GTC%202010%20%28Part%202%29%20-%20Thrust%20By%20Example.pdf
我犯了一个可怕的错误!我没有正确计时我的代码,因此,我认为延迟是由于减少部分造成的,而我之前执行的转换是罪魁祸首。