sorting array

25 views
Skip to first unread message

rhaney

unread,
Apr 25, 2019, 11:58:29 AM4/25/19
to cub-users
Hello all,

I have gotten a great deal of help from this forum so far - thanks to all who have assisted me. However, I have another question that is likely simple, but I am relatively new, regarding sorting.

Is there a call available in CUB that does simple array sorting? For example, I have an array of floating-point values (e.g. float arr*) that I wish to sort in ascending order, no keys just the actual values themselves, and I would like it to be device-wide if possible.

Thank you for any help/hints.

Robert Crovella

unread,
Apr 25, 2019, 12:05:06 PM4/25/19
to cub-users, rhaney
Yes


that is the entry page for the cub documentation

click on "Device-wide primitives" to get started

--
http://nvlabs.github.com/cub
---
You received this message because you are subscribed to the Google Groups "cub-users" group.
To post to this group, send email to cub-...@googlegroups.com.
Visit this group at https://groups.google.com/group/cub-users.

rhaney

unread,
Apr 25, 2019, 12:11:45 PM4/25/19
to cub-users
Thank you for the link and information.

rhaney

unread,
Apr 25, 2019, 1:00:57 PM4/25/19
to cub-users
I was successful in completing a simple sort of floating-point array using CUB. Can you tell me if my function below (where the argument array is allocated on Device) is correct - i.e., will it have performance issues down the road if passed arrays of varying length(s)?

void cubSortArray(float *d_array, unsigned int num_items){
   
void *d_temp_storage = NULL;
    size_t temp_storage_bytes
= 0;
    cub
::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
                                    d_array
, d_array, d_array, d_array, num_items);


    cudaMalloc
(&d_temp_storage, temp_storage_bytes);
   
   
// run sorting operation
    cub
::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
                                    d_array
, d_array, d_array, d_array, num_items);
   
   
// free DEVICE memory
    cudaFree
(d_temp_storage);
}


Thanks again for all the help.

On Thursday, April 25, 2019 at 12:05:06 PM UTC-4, txbob wrote:

Robert Crovella

unread,
Apr 25, 2019, 4:23:15 PM4/25/19
to cub-users, rhaney
There is no reason to be using ::SortPairs if you are not doing key-value sorting.  ::SortKeys may be what you want.

Reply all
Reply to author
Forward
0 new messages