问题推力:sort_by_key与zip_iterator性能
我使用sort_by_key
与使用zip_iterator
传递的价值观。这个sort_by_key
被称为很多次,经过一定的迭代后,它变得慢了10x ! 性能下降的原因是什么?
症状
我使用sort_by_key
排序3个矢量,它们中的一个作为密钥矢量:
struct Segment
{
int v[2];
};
thrust::device_vector<int> keyVec;
thrust::device_vector<int> valVec;
thrust::device_vector<Segment> segVec;
// ... code which fills these vectors ...
thrust::sort_by_key(keyVec.begin(), keyVec.end(),
make_zip_iterator(make_tuple(valVec.begin(), segVec.begin())));
载体的大小通常为约400万。在最初的2次调用中,sort_by_key
需要0.04s,在循环3中需要0.1s,然后在剩余的循环中进一步降低到0.3s。因此,我们发现性能下降了10倍。
thrust::device_vector<int> indexVec(keyVec.size());
thrust::sequence(indexVec.begin(), indexVec.end());
// Sort the keys and indexes
thrust::sort_by_key(keyVec.begin(), keyVec.end(), indexVec.begin());
thrust::device_vector<int> valVec2(keyVec.size());
thrust::device_vector<Segment> segVec2(keyVec.size());
// Use index array and move vectors to destination
moveKernel<<< x, y >>>(
toRawPtr(indexVec),
indexVec.size(),
toRawPtr(valVec),
toRawPtr(segVec),
toRawPtr(valVec2),
toRawPtr(segVec2));
// Swap back into original vectors
valVec.swap(valVec2);
segVec.swap(segVec2);
该手写排序需要0.03秒,这:
额外信息
要确保退化的唯一因素是sort_by_key
,我用手写的内核取代了以上人工分拣性能在所有迭代中都是一致的,与sort_by_key和zip_iterator的性能下降不同。
这仍然是一个问题与推力1.6? – harrism 2012-09-13 03:43:27