Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

CUDPP: Sorting a Structure Array

📅 2011-Mar-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cuda, cudpp, sorting ⬩ 📚 Archive

Problem

The cudppSort function from the CUDPP library can be used to sort an array of keys and an array of values along with it. However, the value types that are supported are only 32-bit. Thus, an array of structures cannot directly be sorted by using cudppSort.

Solution

One way to sort such a structure array is as follows:

  1. Create an index array. Fill it with indices of the array using a simple kernel.

  2. Use this index array as the value array and sort the key and value arrays using cudppSort.

  3. Pass the sorted index array to a simple kernel and use it write the structures of the array to their sorted destinations.

This solution assumes that the structure array has an additional array of keys. More details and code on this method can be seen in my post on Compacting a Structure Array.

Tried with: CUDPP 1.1.1 and CUDA 3.2


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧