利用CUDA 5.0最新推出的 Dynamic Parallelism,以往很难使用的分治法现在可以轻易的在GK110上利用这一新特性实现,非常方便:
算法思想:
随机选取一个枢纽元(pivot),对排序数组进行划分,左边一组都比枢纽元小,右边一组都等于或大于枢纽元,然后对每一个分组递归使用快排算法直至每一个分组仅有一个元素,则排序完成。
示例图:
CUDA version with dynamic parallelism:
有了dynamic parallelism后,代码简洁清晰,nice!
Dynamic Parallelism的优势:
- Programming the GPU will be easier than ever;
- Algorithms previously considered difficult will now accelerate easily on GPUs;
- The GPU depends significantly less on the CPU, enabling both to operate more efficiently.
参考:
1. http://blogs.nvidia.com/blog/2012/09/12/how-tesla-k20-speeds-up-quicksort-a-familiar-comp-sci-code/
2. cuda 5.5 sdk samples: cdpSimpleQuicksort