OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
cub::DeviceRadixSort Struct Reference

DeviceRadixSort provides device-wide, parallel operations for computing a radix sort across a sequence of data items residing within device-accessible memory. More...

Detailed Description

DeviceRadixSort provides device-wide, parallel operations for computing a radix sort across a sequence of data items residing within device-accessible memory.

Overview
The radix sorting method arranges items into ascending (or descending) order. The algorithm relies upon a positional representation for keys, i.e., each key is comprised of an ordered sequence of symbols (e.g., digits, characters, etc.) specified from least-significant to most-significant. For a given input sequence of keys and a set of rules specifying a total ordering of the symbolic alphabet, the radix sorting method produces a lexicographic ordering of those keys.
DeviceRadixSort can sort all of the built-in C++ numeric primitive types (unsigned char, int, double, etc.) as well as CUDA's __half half-precision floating-point type. Although the direct radix sorting method can only be applied to unsigned integral types, DeviceRadixSort is able to sort signed and floating-point types via simple bit-wise transformations that ensure lexicographic key ordering.
Usage Considerations
\cdp_class{DeviceRadixSort}
Performance
\linear_performance{radix sort} The following chart illustrates DeviceRadixSort::SortKeys performance across different CUDA architectures for uniform-random uint32 keys. \plots_below

Definition at line 83 of file device_radix_sort.cuh.

Static Public Member Functions

KeyT-value pairs
template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t SortPairs (void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, const ValueT *d_values_in, ValueT *d_values_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts key-value pairs into ascending order. (~2N auxiliary storage required)
 
template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t SortPairs (void *d_temp_storage, size_t &temp_storage_bytes, DoubleBuffer< KeyT > &d_keys, DoubleBuffer< ValueT > &d_values, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts key-value pairs into ascending order. (~N auxiliary storage required)
 
template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t SortPairsDescending (void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, const ValueT *d_values_in, ValueT *d_values_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts key-value pairs into descending order. (~2N auxiliary storage required).
 
template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t SortPairsDescending (void *d_temp_storage, size_t &temp_storage_bytes, DoubleBuffer< KeyT > &d_keys, DoubleBuffer< ValueT > &d_values, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts key-value pairs into descending order. (~N auxiliary storage required).
 
Keys-only
template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t SortKeys (void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts keys into ascending order. (~2N auxiliary storage required)
 
template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t SortKeys (void *d_temp_storage, size_t &temp_storage_bytes, DoubleBuffer< KeyT > &d_keys, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts keys into ascending order. (~N auxiliary storage required).
 
template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t SortKeysDescending (void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts keys into descending order. (~2N auxiliary storage required).
 
template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t SortKeysDescending (void *d_temp_storage, size_t &temp_storage_bytes, DoubleBuffer< KeyT > &d_keys, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts keys into descending order. (~N auxiliary storage required).
 

Member Function Documentation

◆ SortKeys() [1/2]

template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortKeys ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
const KeyT *  d_keys_in,
KeyT *  d_keys_out,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts keys into ascending order. (~2N auxiliary storage required)

  • The contents of the input data are not altered by the sorting operation
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageNP For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • \devicestorage
Performance
The following charts illustrate saturated sorting performance across different CUDA architectures for uniform-random uint32 and uint64 keys, respectively.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_keys_out; // e.g., [ ... ]
...
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items);
// d_keys_out <-- [0, 3, 5, 6, 7, 8, 9]
KeyT const ValueT ValueT OffsetT OffsetT num_items
[in] Total number of input data items
KeyT * d_keys_out
< [in] Input keys buffer
static CUB_RUNTIME_FUNCTION cudaError_t SortKeys(void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
Sorts keys into ascending order. (~2N auxiliary storage required)
Template Parameters
KeyT[inferred] KeyT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in]d_keys_inPointer to the input data of key data to sort
[out]d_keys_outPointer to the sorted output sequence of key data
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 507 of file device_radix_sort.cuh.

◆ SortKeys() [2/2]

template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortKeys ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts keys into ascending order. (~N auxiliary storage required).

  • The sorting operation is given a pair of key buffers managed by a DoubleBuffer structure that indicates which of the two buffers is "current" (and thus contains the input data to be sorted).
  • The contents of both buffers may be altered by the sorting operation.
  • Upon completion, the sorting operation will update the "current" indicator within the DoubleBuffer wrapper to reference which of the two buffers now contains the sorted output sequence (a function of the number of key bits specified and the targeted device architecture).
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageP
  • \devicestorage
Performance
The following charts illustrate saturated sorting performance across different CUDA architectures for uniform-random uint32 and uint64 keys, respectively.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_key_alt_buf; // e.g., [ ... ]
...
// Create a DoubleBuffer to wrap the pair of device pointers
cub::DoubleBuffer<int> d_keys(d_key_buf, d_key_alt_buf);
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys, num_items);
// d_keys.Current() <-- [0, 3, 5, 6, 7, 8, 9]
Template Parameters
KeyT[inferred] KeyT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in,out]d_keysReference to the double-buffer of keys whose "current" device-accessible buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 596 of file device_radix_sort.cuh.

◆ SortKeysDescending() [1/2]

template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortKeysDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
const KeyT *  d_keys_in,
KeyT *  d_keys_out,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts keys into descending order. (~2N auxiliary storage required).

  • The contents of the input data are not altered by the sorting operation
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageNP For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • \devicestorage
Performance
Performance is similar to DeviceRadixSort::SortKeys.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_keys_out; // e.g., [ ... ]
...
// Create a DoubleBuffer to wrap the pair of device pointers
cub::DoubleBuffer<int> d_keys(d_key_buf, d_key_alt_buf);
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out, num_items);
// d_keys_out <-- [9, 8, 7, 6, 5, 3, 0]s
static CUB_RUNTIME_FUNCTION cudaError_t SortKeysDescending(void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
Sorts keys into descending order. (~2N auxiliary storage required).
Template Parameters
KeyT[inferred] KeyT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in]d_keys_inPointer to the input data of key data to sort
[out]d_keys_outPointer to the sorted output sequence of key data
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 671 of file device_radix_sort.cuh.

◆ SortKeysDescending() [2/2]

template<typename KeyT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortKeysDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts keys into descending order. (~N auxiliary storage required).

  • The sorting operation is given a pair of key buffers managed by a DoubleBuffer structure that indicates which of the two buffers is "current" (and thus contains the input data to be sorted).
  • The contents of both buffers may be altered by the sorting operation.
  • Upon completion, the sorting operation will update the "current" indicator within the DoubleBuffer wrapper to reference which of the two buffers now contains the sorted output sequence (a function of the number of key bits specified and the targeted device architecture).
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageP
  • \devicestorage
Performance
Performance is similar to DeviceRadixSort::SortKeys.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_key_alt_buf; // e.g., [ ... ]
...
// Create a DoubleBuffer to wrap the pair of device pointers
cub::DoubleBuffer<int> d_keys(d_key_buf, d_key_alt_buf);
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys, num_items);
// d_keys.Current() <-- [9, 8, 7, 6, 5, 3, 0]
Template Parameters
KeyT[inferred] KeyT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in,out]d_keysReference to the double-buffer of keys whose "current" device-accessible buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 755 of file device_radix_sort.cuh.

◆ SortPairs() [1/2]

template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortPairs ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
const KeyT *  d_keys_in,
KeyT *  d_keys_out,
const ValueT *  d_values_in,
ValueT *  d_values_out,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts key-value pairs into ascending order. (~2N auxiliary storage required)

  • The contents of the input data are not altered by the sorting operation
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageNP For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • \devicestorage
Performance
The following charts illustrate saturated sorting performance across different CUDA architectures for uniform-random uint32,uint32 and uint64,uint64 pairs, respectively.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_keys_out; // e.g., [ ... ]
int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6]
int *d_values_out; // e.g., [ ... ]
...
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
// d_keys_out <-- [0, 3, 5, 6, 7, 8, 9]
// d_values_out <-- [5, 4, 3, 1, 2, 0, 6]
KeyT const ValueT ValueT * d_values_out
[in] Output values buffer
KeyT const ValueT * d_values_in
[in] Input values buffer
static CUB_RUNTIME_FUNCTION cudaError_t SortPairs(void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, const ValueT *d_values_in, ValueT *d_values_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
Sorts key-value pairs into ascending order. (~2N auxiliary storage required)
Template Parameters
KeyT[inferred] KeyT type
ValueT[inferred] ValueT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in]d_keys_inPointer to the input data of key data to sort
[out]d_keys_outPointer to the sorted output sequence of key data
[in]d_values_inPointer to the corresponding input sequence of associated value items
[out]d_values_outPointer to the correspondingly-reordered output sequence of associated value items
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 148 of file device_radix_sort.cuh.

◆ SortPairs() [2/2]

template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortPairs ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
DoubleBuffer< ValueT > &  d_values,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts key-value pairs into ascending order. (~N auxiliary storage required)

  • The sorting operation is given a pair of key buffers and a corresponding pair of associated value buffers. Each pair is managed by a DoubleBuffer structure that indicates which of the two buffers is "current" (and thus contains the input data to be sorted).
  • The contents of both buffers within each pair may be altered by the sorting operation.
  • Upon completion, the sorting operation will update the "current" indicator within each DoubleBuffer wrapper to reference which of the two buffers now contains the sorted output sequence (a function of the number of key bits specified and the targeted device architecture).
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageP
  • \devicestorage
Performance
The following charts illustrate saturated sorting performance across different CUDA architectures for uniform-random uint32,uint32 and uint64,uint64 pairs, respectively.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_key_alt_buf; // e.g., [ ... ]
int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6]
int *d_value_alt_buf; // e.g., [ ... ]
...
// Create a set of DoubleBuffers to wrap pairs of device pointers
cub::DoubleBuffer<int> d_keys(d_key_buf, d_key_alt_buf);
cub::DoubleBuffer<int> d_values(d_value_buf, d_value_alt_buf);
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortPairs(d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items);
// d_keys.Current() <-- [0, 3, 5, 6, 7, 8, 9]
// d_values.Current() <-- [5, 4, 3, 1, 2, 0, 6]
Double-buffer storage wrapper for multi-pass stream transformations that require more than one storag...
Template Parameters
KeyT[inferred] KeyT type
ValueT[inferred] ValueT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in,out]d_keysReference to the double-buffer of keys whose "current" device-accessible buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys
[in,out]d_valuesDouble-buffer of values whose "current" device-accessible buffer contains the unsorted input values and, upon return, is updated to point to the sorted output values
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 249 of file device_radix_sort.cuh.

◆ SortPairsDescending() [1/2]

template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortPairsDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
const KeyT *  d_keys_in,
KeyT *  d_keys_out,
const ValueT *  d_values_in,
ValueT *  d_values_out,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts key-value pairs into descending order. (~2N auxiliary storage required).

  • The contents of the input data are not altered by the sorting operation
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageNP For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • \devicestorage
Performance
Performance is similar to DeviceRadixSort::SortPairs.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_keys_in; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_keys_out; // e.g., [ ... ]
int *d_values_in; // e.g., [0, 1, 2, 3, 4, 5, 6]
int *d_values_out; // e.g., [ ... ]
...
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes,
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes,
// d_keys_out <-- [9, 8, 7, 6, 5, 3, 0]
// d_values_out <-- [6, 0, 2, 1, 3, 4, 5]
static CUB_RUNTIME_FUNCTION cudaError_t SortPairsDescending(void *d_temp_storage, size_t &temp_storage_bytes, const KeyT *d_keys_in, KeyT *d_keys_out, const ValueT *d_values_in, ValueT *d_values_out, int num_items, int begin_bit=0, int end_bit=sizeof(KeyT) *8, cudaStream_t stream=0, bool debug_synchronous=false)
Sorts key-value pairs into descending order. (~2N auxiliary storage required).
Template Parameters
KeyT[inferred] KeyT type
ValueT[inferred] ValueT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in]d_keys_inPointer to the input data of key data to sort
[out]d_keys_outPointer to the sorted output sequence of key data
[in]d_values_inPointer to the corresponding input sequence of associated value items
[out]d_values_outPointer to the correspondingly-reordered output sequence of associated value items
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 329 of file device_radix_sort.cuh.

◆ SortPairsDescending() [2/2]

template<typename KeyT , typename ValueT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceRadixSort::SortPairsDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
DoubleBuffer< ValueT > &  d_values,
int  num_items,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts key-value pairs into descending order. (~N auxiliary storage required).

  • The sorting operation is given a pair of key buffers and a corresponding pair of associated value buffers. Each pair is managed by a DoubleBuffer structure that indicates which of the two buffers is "current" (and thus contains the input data to be sorted).
  • The contents of both buffers within each pair may be altered by the sorting operation.
  • Upon completion, the sorting operation will update the "current" indicator within each DoubleBuffer wrapper to reference which of the two buffers now contains the sorted output sequence (a function of the number of key bits specified and the targeted device architecture).
  • An optional bit subrange [begin_bit, end_bit) of differentiating key bits can be specified. This can reduce overall sorting overhead and yield a corresponding performance improvement.
  • \devicestorageP
  • \devicestorage
Performance
Performance is similar to DeviceRadixSort::SortPairs.
Snippet
The code snippet below illustrates the sorting of a device vector of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int *d_key_buf; // e.g., [8, 6, 7, 5, 3, 0, 9]
int *d_key_alt_buf; // e.g., [ ... ]
int *d_value_buf; // e.g., [0, 1, 2, 3, 4, 5, 6]
int *d_value_alt_buf; // e.g., [ ... ]
...
// Create a set of DoubleBuffers to wrap pairs of device pointers
cub::DoubleBuffer<int> d_keys(d_key_buf, d_key_alt_buf);
cub::DoubleBuffer<int> d_values(d_value_buf, d_value_alt_buf);
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes, d_keys, d_values, num_items);
// d_keys.Current() <-- [9, 8, 7, 6, 5, 3, 0]
// d_values.Current() <-- [6, 0, 2, 1, 3, 4, 5]
Template Parameters
KeyT[inferred] KeyT type
ValueT[inferred] ValueT type
Parameters
[in]d_temp_storageDevice-accessible allocation of temporary storage. When NULL, the required allocation size is written to temp_storage_bytes and no work is done.
[in,out]temp_storage_bytesReference to size in bytes of d_temp_storage allocation
[in,out]d_keysReference to the double-buffer of keys whose "current" device-accessible buffer contains the unsorted input keys and, upon return, is updated to point to the sorted output keys
[in,out]d_valuesDouble-buffer of values whose "current" device-accessible buffer contains the unsorted input values and, upon return, is updated to point to the sorted output values
[in]num_itemsNumber of items to sort
[in]begin_bit[optional] The least-significant bit index (inclusive) needed for key comparison
[in]end_bit[optional] The most-significant bit index (exclusive) needed for key comparison (e.g., sizeof(unsigned int) * 8)
[in]stream[optional] CUDA stream to launch kernels within. Default is stream0.
[in]debug_synchronous[optional] Whether or not to synchronize the stream after every kernel launch to check for errors. Also causes launch configurations to be printed to the console. Default is false.

Definition at line 425 of file device_radix_sort.cuh.


The documentation for this struct was generated from the following file: