This simple program showcases the usage of the hipcub::DeviceRadixSort::SortPairs
function.
- Host side data is instantiated in
std::vector<float>
andstd::vector<int>
as key-value pairs. - Device side storage is allocated using
hipMalloc
. - Data is copied from host to device using
hipMemcpy
. hipCUB::DeviceRadixSort::SortPairs
makes use of temporary memory on the device that needs to be allocated manually. A first call tohipcub::DeviceRadixSort::SortPairs
(withd_temp_storage
set to null) calculates the size in bytes needed for the temporary storage and stores it in the variabletemp_storage_bytes
.temp_storage_bytes
is used to allocate device memory ind_temp_storage
usinghipMalloc
.- Finally a second call to
hipcub::DeviceRadixSort::SortPairs
is invoked that sorts the pairs on the basis of keys. - Result is transferred from device to host.
- Free all device side memory using
hipFree
- The device-level API provided by hipCUB is used in this example. It performs global device level operations (in this case pair sorting using
hipcub::DeviceRadixSort::SortPairs
) on the GPU.
hipcub::DoubleBuffer
hipcub::DeviceRadixSort::SortPairs
hipGetErrorString
hipMalloc
hipMemcpy
hipFree