CUB  
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members
cub::DeviceSegmentedRadixSort Struct Reference

Detailed description

DeviceSegmentedRadixSort provides device-wide, parallel operations for computing a batched radix sort across multiple, non-overlapping sequences of data items residing within device-accessible memory.

segmented_sorting_logo.png
.
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.
See Also
DeviceSegmentedRadixSort shares its implementation with DeviceRadixSort. See that algorithm's documentation for more information.
Usage Considerations
  • Dynamic parallelism. DeviceSegmentedRadixSort methods can be called within kernel code on devices in which CUDA dynamic parallelism is supported.

Static Public Methods

Key-value pairs
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
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 num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of key-value pairs into ascending order. (~2N auxiliary storage required) More...
 
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
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 num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of key-value pairs into ascending order. (~N auxiliary storage required) More...
 
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
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 num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of key-value pairs into descending order. (~2N auxiliary storage required). More...
 
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
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 num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of key-value pairs into descending order. (~N auxiliary storage required). More...
 
Keys-only
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
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 num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of keys into ascending order. (~2N auxiliary storage required) More...
 
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION
cudaError_t 
SortKeys (void *d_temp_storage, size_t &temp_storage_bytes, DoubleBuffer< KeyT > &d_keys, int num_items, int num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of keys into ascending order. (~N auxiliary storage required). More...
 
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
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 num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of keys into descending order. (~2N auxiliary storage required). More...
 
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION
cudaError_t 
SortKeysDescending (void *d_temp_storage, size_t &temp_storage_bytes, DoubleBuffer< KeyT > &d_keys, int num_items, int num_segments, BeginOffsetIteratorT d_begin_offsets, EndOffsetIteratorT d_end_offsets, int begin_bit=0, int end_bit=sizeof(KeyT)*8, cudaStream_t stream=0, bool debug_synchronous=false)
 Sorts segments of keys into descending order. (~N auxiliary storage required). More...
 

Member Function Documentation

template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::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  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

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

  • The contents of the input data are not altered by the sorting operation
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires an allocation of temporary device storage that is O(N+P), where N is the length of the input and P is the number of streaming multiprocessors on the device. For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortPairs(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys_out <-- [6, 7, 8, 0, 3, 5, 9]
// d_values_out <-- [1, 2, 0, 5, 4, 3, 6]
Template Parameters
KeyT[inferred] Key type
ValueT[inferred] Value type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_inDevice-accessible pointer to the input data of key data to sort
[out]d_keys_outDevice-accessible pointer to the sorted output sequence of key data
[in]d_values_inDevice-accessible pointer to the corresponding input sequence of associated value items
[out]d_values_outDevice-accessible pointer to the correspondingly-reordered output sequence of associated value items
[in]num_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::SortPairs ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
DoubleBuffer< ValueT > &  d_values,
int  num_items,
int  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts segments of 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).
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires a relatively small allocation of temporary device storage that is O(P), where P is the number of streaming multiprocessors on the device (and is typically a small constant relative to the input size N).
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortPairs(d_temp_storage, temp_storage_bytes, d_keys, d_values,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortPairs(d_temp_storage, temp_storage_bytes, d_keys, d_values,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9]
// d_values.Current() <-- [5, 4, 3, 1, 2, 0, 6]
Template Parameters
KeyT[inferred] Key type
ValueT[inferred] Value type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::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  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

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

  • The contents of the input data are not altered by the sorting operation
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires an allocation of temporary device storage that is O(N+P), where N is the length of the input and P is the number of streaming multiprocessors on the device. For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes,
d_keys_in, d_keys_out, d_values_in, d_values_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys_out <-- [8, 7, 6, 9, 5, 3, 0]
// d_values_out <-- [0, 2, 1, 6, 3, 4, 5]
Template Parameters
KeyT[inferred] Key type
ValueT[inferred] Value type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_inDevice-accessible pointer to the input data of key data to sort
[out]d_keys_outDevice-accessible pointer to the sorted output sequence of key data
[in]d_values_inDevice-accessible pointer to the corresponding input sequence of associated value items
[out]d_values_outDevice-accessible pointer to the correspondingly-reordered output sequence of associated value items
[in]num_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename ValueT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::SortPairsDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
DoubleBuffer< ValueT > &  d_values,
int  num_items,
int  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts segments of 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).
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires a relatively small allocation of temporary device storage that is O(P), where P is the number of streaming multiprocessors on the device (and is typically a small constant relative to the input size N).
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys with associated vector of int values.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes, d_keys, d_values,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortPairsDescending(d_temp_storage, temp_storage_bytes, d_keys, d_values,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0]
// d_values.Current() <-- [0, 2, 1, 6, 3, 4, 5]
Template Parameters
KeyT[inferred] Key type
ValueT[inferred] Value type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::SortKeys ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
const KeyT *  d_keys_in,
KeyT *  d_keys_out,
int  num_items,
int  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts segments of 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.
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • This operation requires an allocation of temporary device storage that is O(N+P), where N is the length of the input and P is the number of streaming multiprocessors on the device. For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys_out <-- [6, 7, 8, 0, 3, 5, 9]
Template Parameters
KeyT[inferred] Key type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_inDevice-accessible pointer to the input data of key data to sort
[out]d_keys_outDevice-accessible pointer to the sorted output sequence of key data
[in]num_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::SortKeys ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
int  num_items,
int  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts segments of 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).
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires a relatively small allocation of temporary device storage that is O(P), where P is the number of streaming multiprocessors on the device (and is typically a small constant relative to the input size N).
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortKeys(d_temp_storage, temp_storage_bytes, d_keys,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys.Current() <-- [6, 7, 8, 0, 3, 5, 9]
Template Parameters
KeyT[inferred] Key type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::SortKeysDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
const KeyT *  d_keys_in,
KeyT *  d_keys_out,
int  num_items,
int  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

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

  • The contents of the input data are not altered by the sorting operation
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires an allocation of temporary device storage that is O(N+P), where N is the length of the input and P is the number of streaming multiprocessors on the device. For sorting using only O(P) temporary storage, see the sorting interface using DoubleBuffer wrappers below.
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys_in, d_keys_out,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys_out <-- [8, 7, 6, 9, 5, 3, 0]
Template Parameters
KeyT[inferred] Key type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_inDevice-accessible pointer to the input data of key data to sort
[out]d_keys_outDevice-accessible pointer to the sorted output sequence of key data
[in]num_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.
template<typename KeyT , typename BeginOffsetIteratorT , typename EndOffsetIteratorT >
static CUB_RUNTIME_FUNCTION cudaError_t cub::DeviceSegmentedRadixSort::SortKeysDescending ( void *  d_temp_storage,
size_t &  temp_storage_bytes,
DoubleBuffer< KeyT > &  d_keys,
int  num_items,
int  num_segments,
BeginOffsetIteratorT  d_begin_offsets,
EndOffsetIteratorT  d_end_offsets,
int  begin_bit = 0,
int  end_bit = sizeof(KeyT) * 8,
cudaStream_t  stream = 0,
bool  debug_synchronous = false 
)
inlinestatic

Sorts segments of 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).
  • When input a contiguous sequence of segments, a single sequence segment_offsets (of length num_segments+1) can be aliased for both the d_begin_offsets and d_end_offsets parameters (where the latter is specified as segment_offsets+1).
  • 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.
  • This operation requires a relatively small allocation of temporary device storage that is O(P), where P is the number of streaming multiprocessors on the device (and is typically a small constant relative to the input size N).
  • When d_temp_storage is NULL, no work is done and the required allocation size is returned in temp_storage_bytes.
Snippet
The code snippet below illustrates the batched sorting of three segments (with one zero-length segment) of int keys.
#include <cub/cub.cuh> // or equivalently <cub/device/device_segmented_radix_sort.cuh>
// Declare, allocate, and initialize device-accessible pointers for sorting data
int num_items; // e.g., 7
int num_segments; // e.g., 3
int *d_offsets; // e.g., [0, 3, 3, 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::DeviceSegmentedRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys,
num_items, num_segments, d_offsets, d_offsets + 1);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run sorting operation
cub::DeviceSegmentedRadixSort::SortKeysDescending(d_temp_storage, temp_storage_bytes, d_keys,
num_items, num_segments, d_offsets, d_offsets + 1);
// d_keys.Current() <-- [8, 7, 6, 9, 5, 3, 0]
Template Parameters
KeyT[inferred] Key type
BeginOffsetIteratorT[inferred] Random-access input iterator type for reading segment beginning offsets (may be a simple pointer type)
EndOffsetIteratorT[inferred] Random-access input iterator type for reading segment ending offsets (may be a simple pointer 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_itemsThe total number of items to sort (across all segments)
[in]num_segmentsThe number of segments that comprise the sorting data
[in]d_begin_offsetsRandom-access input iterator to the sequence of beginning offsets of length num_segments, such that d_begin_offsets[i] is the first element of the ith data segment in d_keys_* and d_values_*
[in]d_end_offsetsRandom-access input iterator to the sequence of ending offsets of length num_segments, such that d_end_offsets[i]-1 is the last element of the ith data segment in d_keys_* and d_values_*. If d_end_offsets[i]-1 <= d_begin_offsets[i], the ith is considered empty.
[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.

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