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::SortPairsmakes use of temporary memory on the device that needs to be allocated manually. A first call tohipcub::DeviceRadixSort::SortPairs(withd_temp_storageset to null) calculates the size in bytes needed for the temporary storage and stores it in the variabletemp_storage_bytes.temp_storage_bytesis used to allocate device memory ind_temp_storageusinghipMalloc.- Finally a second call to
hipcub::DeviceRadixSort::SortPairsis 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::DoubleBufferhipcub::DeviceRadixSort::SortPairs
hipGetErrorStringhipMallochipMemcpyhipFree