CUB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
Classes | List of all members
cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH > Class Template Reference

Detailed description

template< typename T, int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
class cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >

The WarpScan class provides collective methods for computing a parallel prefix scan of items partitioned across a CUDA thread warp.

warp_scan_logo.png
.
Template Parameters
TThe scan input/output element type
LOGICAL_WARP_THREADS[optional] The number of threads per "logical" warp (may be less than the number of hardware warp threads). Default is the warp size associated with the CUDA Compute Capability targeted by the compiler (e.g., 32 threads for SM20).
PTX_ARCH[optional] The PTX compute capability for which to to specialize this collective, formatted as per the CUDA_ARCH macro (e.g., 350 for sm_35). Useful for determining the collective's storage requirements for a given device from the host. (Default: the value of CUDA_ARCH during the current compiler pass)
Overview
  • Given a list of input elements and a binary reduction operator, a prefix scan produces an output list where each element is computed to be the reduction of the elements occurring earlier in the input list. Prefix sum connotes a prefix scan with the addition operator. The term inclusive indicates that the ith output reduction incorporates the ith input. The term exclusive indicates the ith input is not incorporated into the ith output reduction.
  • Supports "logical" warps smaller than the physical warp size (e.g., a logical warp of 8 threads)
  • The number of entrant threads must be an multiple of LOGICAL_WARP_THREADS
Performance Considerations
  • Uses special instructions when applicable (e.g., warp SHFL)
  • Uses synchronization-free communication between warp lanes when applicable
  • Incurs zero bank conflicts for most types
  • Computation is slightly more efficient (i.e., having lower instruction overhead) for:
    • Summation (vs. generic scan)
    • The architecture's warp size is a whole multiple of LOGICAL_WARP_THREADS
Simple Examples
Every thread in the warp uses the WarpScan class by first specializing the WarpScan type, then instantiating an instance with parameters for communication, and finally invoking or more collective member functions.
The code snippet below illustrates four concurrent warp prefix sums within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute warp-wide prefix sums
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveSum(thread_data, thread_data);
Suppose the set of input thread_data across the block of threads is {1, 1, 1, 1, ...}. The corresponding output thread_data in each of the four warps of threads will be 0, 1, 2, 3, ..., 31}.
The code snippet below illustrates a single warp prefix sum within a block of 128 threads.
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for one warp
__shared__ typename WarpScan::TempStorage temp_storage;
...
// Only the first warp performs a prefix sum
if (threadIdx.x < 32)
{
// Obtain one input item per thread
int thread_data = ...
// Compute warp-wide prefix sums
WarpScan(temp_storage).ExclusiveSum(thread_data, thread_data);
Suppose the set of input thread_data across the warp of threads is {1, 1, 1, 1, ...}. The corresponding output thread_data will be {0, 1, 2, 3, ..., 31}.

Definition at line 145 of file warp_scan.cuh.

Classes

struct  TempStorage
 The operations exposed by WarpScan require a temporary memory allocation of this nested type for thread communication. This opaque storage can be allocated directly using the __shared__ keyword. Alternatively, it can be aliased to externally allocated memory (shared or global) or union'd with other storage allocation types to facilitate memory reuse. More...
 

Public Methods

Collective constructors
__device__ __forceinline__ WarpScan (TempStorage &temp_storage)
 Collective constructor using the specified memory allocation as temporary storage. Logical warp and lane identifiers are constructed from threadIdx.x. More...
 
Inclusive prefix sums
__device__ __forceinline__ void InclusiveSum (T input, T &output)
 Computes an inclusive prefix sum across the calling warp. More...
 
__device__ __forceinline__ void InclusiveSum (T input, T &output, T &warp_aggregate)
 Computes an inclusive prefix sum across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
template<typename WarpPrefixCallbackOp >
__device__ __forceinline__ void InclusiveSum (T input, T &output, T &warp_aggregate, WarpPrefixCallbackOp &warp_prefix_op)
 Computes an inclusive prefix sum across the calling warp. Instead of using 0 as the warp-wide prefix, the call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
Exclusive prefix sums
__device__ __forceinline__ void ExclusiveSum (T input, T &output)
 Computes an exclusive prefix sum across the calling warp. More...
 
__device__ __forceinline__ void ExclusiveSum (T input, T &output, T &warp_aggregate)
 Computes an exclusive prefix sum across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
template<typename WarpPrefixCallbackOp >
__device__ __forceinline__ void ExclusiveSum (T input, T &output, T &warp_aggregate, WarpPrefixCallbackOp &warp_prefix_op)
 Computes an exclusive prefix sum across the calling warp. Instead of using 0 as the warp-wide prefix, the call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
Inclusive prefix scans
template<typename ScanOp >
__device__ __forceinline__ void InclusiveScan (T input, T &output, ScanOp scan_op)
 Computes an inclusive prefix scan using the specified binary scan functor across the calling warp. More...
 
template<typename ScanOp >
__device__ __forceinline__ void InclusiveScan (T input, T &output, ScanOp scan_op, T &warp_aggregate)
 Computes an inclusive prefix scan using the specified binary scan functor across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
template<typename ScanOp , typename WarpPrefixCallbackOp >
__device__ __forceinline__ void InclusiveScan (T input, T &output, ScanOp scan_op, T &warp_aggregate, WarpPrefixCallbackOp &warp_prefix_op)
 Computes an inclusive prefix scan using the specified binary scan functor across the calling warp. The call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
Exclusive prefix scans
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &output, T identity, ScanOp scan_op)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. More...
 
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &output, T identity, ScanOp scan_op, T &warp_aggregate)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
template<typename ScanOp , typename WarpPrefixCallbackOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &output, T identity, ScanOp scan_op, T &warp_aggregate, WarpPrefixCallbackOp &warp_prefix_op)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. The call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
Identityless exclusive prefix scans
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &output, ScanOp scan_op)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Because no identity value is supplied, the output computed for warp-lane0 is undefined. More...
 
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &output, ScanOp scan_op, T &warp_aggregate)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Because no identity value is supplied, the output computed for warp-lane0 is undefined. Also provides every thread with the warp-wide warp_aggregate of all inputs. More...
 
template<typename ScanOp , typename WarpPrefixCallbackOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &output, ScanOp scan_op, T &warp_aggregate, WarpPrefixCallbackOp &warp_prefix_op)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. The warp_prefix_op value from warp-lane0 is applied to all scan outputs. Also computes the warp-wide warp_aggregate of all inputs for warp-lane0. More...
 
Combination (inclusive & exclusive) prefix scans
__device__ __forceinline__ void Sum (T input, T &inclusive_output, T &exclusive_output)
 Computes both inclusive and exclusive prefix sums across the calling warp. More...
 
template<typename ScanOp >
__device__ __forceinline__ void Scan (T input, T &inclusive_output, T &exclusive_output, T identity, ScanOp scan_op)
 Computes both inclusive and exclusive prefix scans using the specified binary scan functor across the calling warp. More...
 
template<typename ScanOp >
__device__ __forceinline__ void Scan (T input, T &inclusive_output, T &exclusive_output, ScanOp scan_op)
 Computes both inclusive and exclusive prefix scans using the specified binary scan functor across the calling warp. Because no identity value is supplied, the exclusive_output computed for warp-lane0 is undefined. More...
 

Constructor & Destructor Documentation

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::WarpScan ( TempStorage temp_storage)
inline

Collective constructor using the specified memory allocation as temporary storage. Logical warp and lane identifiers are constructed from threadIdx.x.

Parameters
[in]temp_storageReference to memory allocation having layout type TempStorage

Definition at line 201 of file warp_scan.cuh.

Member Function Documentation

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InclusiveSum ( input,
T &  output 
)
inline

Computes an inclusive prefix sum across the calling warp.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide inclusive prefix sums within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute inclusive warp-wide prefix sums
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).InclusiveSum(thread_data, thread_data);
Suppose the set of input thread_data across the block of threads is {1, 1, 1, 1, ...}. The corresponding output thread_data in each of the four warps of threads will be 1, 2, 3, ..., 32}.
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.

Definition at line 251 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InclusiveSum ( input,
T &  output,
T &  warp_aggregate 
)
inline

Computes an inclusive prefix sum across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs.

The warp_aggregate is undefined in threads other than warp-lane0.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide inclusive prefix sums within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute inclusive warp-wide prefix sums
int warp_aggregate;
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).InclusiveSum(thread_data, thread_data, warp_aggregate);
Suppose the set of input thread_data across the block of threads is {1, 1, 1, 1, ...}. The corresponding output thread_data in each of the four warps of threads will be 1, 2, 3, ..., 32}. Furthermore, warp_aggregate for all threads in all warps will be 32.
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 295 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename WarpPrefixCallbackOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InclusiveSum ( input,
T &  output,
T &  warp_aggregate,
WarpPrefixCallbackOp &  warp_prefix_op 
)
inline

Computes an inclusive prefix sum across the calling warp. Instead of using 0 as the warp-wide prefix, the call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs.

The warp_aggregate is undefined in threads other than warp-lane0.

The warp_prefix_op functor must implement a member function T operator()(T warp_aggregate). The functor's input parameter warp_aggregate is the same value also returned by the scan operation. The functor will be invoked by the entire warp of threads, however only the return value from lane0 is applied as the threadblock-wide prefix. Can be stateful.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates a single thread block of 32 threads (one warp) that progressively computes an inclusive prefix sum over multiple "tiles" of input using a prefix functor to maintain a running total between block-wide scans. Each tile consists of 32 integer items that are partitioned across the warp.
#include <cub/cub.cuh>
// A stateful callback functor that maintains a running prefix to be applied
// during consecutive scan operations.
struct WarpPrefixCallbackOp
{
// Running prefix
int running_total;
// Constructor
__device__ WarpPrefixCallbackOp(int running_total) : running_total(running_total) {}
// Callback operator to be entered by the entire warp. Lane-0 is responsible
// for returning a value for seeding the warp-wide scan.
__device__ int operator()(int warp_aggregate)
{
int old_prefix = running_total;
running_total += warp_aggregate;
return old_prefix;
}
};
__global__ void ExampleKernel(int *d_data, int num_items, ...)
{
// Specialize WarpScan for int
// Allocate WarpScan shared memory for one warp
__shared__ typename WarpScan::TempStorage temp_storage;
// Initialize running total
WarpPrefixCallbackOp prefix_op(0);
// Have the warp iterate over segments of items
for (int block_offset = 0; block_offset < num_items; block_offset += 32)
{
// Load a segment of consecutive items
int thread_data = d_data[block_offset];
// Collectively compute the warp-wide inclusive prefix sum
int warp_aggregate;
WarpScan(temp_storage).InclusiveSum(
thread_data, thread_data, warp_aggregate, prefix_op);
// Store scanned items to output segment
d_data[block_offset] = thread_data;
}
Suppose the input d_data is {1, 1, 1, 1, 1, 1, 1, 1, ...}. The corresponding output for the first segment will be {1, 2, 3, ..., 32}. The output for the second segment will be {33, 34, 35, ..., 64}. Furthermore, the value 32 will be stored in warp_aggregate for all threads after each scan.
Template Parameters
WarpPrefixCallbackOp[inferred] Call-back functor type having member T operator()(T warp_aggregate)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[out]warp_aggregate[warp-lane0 only] Warp-wide aggregate reduction of input items, exclusive of the warp_prefix_op value
[in,out]warp_prefix_op[warp-lane0 only] Call-back functor for specifying a warp-wide prefix to be applied to all inputs.

Definition at line 380 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveSum ( input,
T &  output 
)
inline

Computes an exclusive prefix sum across the calling warp.

This operation assumes the value of obtained by the T's default constructor (or by zero-initialization if no user-defined default constructor exists) is suitable as the identity value "zero" for addition.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix sums within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix sums
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveSum(thread_data, thread_data);
Suppose the set of input thread_data across the block of threads is {1, 1, 1, 1, ...}. The corresponding output thread_data in each of the four warps of threads will be 0, 1, 2, ..., 31}.
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.

Definition at line 519 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveSum ( input,
T &  output,
T &  warp_aggregate 
)
inline

Computes an exclusive prefix sum across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs.

This operation assumes the value of obtained by the T's default constructor (or by zero-initialization if no user-defined default constructor exists) is suitable as the identity value "zero" for addition.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix sums within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix sums
int warp_aggregate;
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveSum(thread_data, thread_data, warp_aggregate);
Suppose the set of input thread_data across the block of threads is {1, 1, 1, 1, ...}. The corresponding output thread_data in each of the four warps of threads will be 0, 1, 2, ..., 31}. Furthermore, warp_aggregate for all threads in all warps will be 32.
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 566 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename WarpPrefixCallbackOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveSum ( input,
T &  output,
T &  warp_aggregate,
WarpPrefixCallbackOp &  warp_prefix_op 
)
inline

Computes an exclusive prefix sum across the calling warp. Instead of using 0 as the warp-wide prefix, the call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs.

This operation assumes the value of obtained by the T's default constructor (or by zero-initialization if no user-defined default constructor exists) is suitable as the identity value "zero" for addition.

The warp_prefix_op functor must implement a member function T operator()(T warp_aggregate). The functor's input parameter warp_aggregate is the same value also returned by the scan operation. The functor will be invoked by the entire warp of threads, however only the return value from lane0 is applied as the threadblock-wide prefix. Can be stateful.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates a single thread block of 32 threads (one warp) that progressively computes an exclusive prefix sum over multiple "tiles" of input using a prefix functor to maintain a running total between block-wide scans. Each tile consists of 32 integer items that are partitioned across the warp.
#include <cub/cub.cuh>
// A stateful callback functor that maintains a running prefix to be applied
// during consecutive scan operations.
struct WarpPrefixCallbackOp
{
// Running prefix
int running_total;
// Constructor
__device__ WarpPrefixCallbackOp(int running_total) : running_total(running_total) {}
// Callback operator to be entered by the entire warp. Lane-0 is responsible
// for returning a value for seeding the warp-wide scan.
__device__ int operator()(int warp_aggregate)
{
int old_prefix = running_total;
running_total += warp_aggregate;
return old_prefix;
}
};
__global__ void ExampleKernel(int *d_data, int num_items, ...)
{
// Specialize WarpScan for int
// Allocate WarpScan shared memory for one warp
__shared__ typename WarpScan::TempStorage temp_storage;
// Initialize running total
WarpPrefixCallbackOp prefix_op(0);
// Have the warp iterate over segments of items
for (int block_offset = 0; block_offset < num_items; block_offset += 32)
{
// Load a segment of consecutive items
int thread_data = d_data[block_offset];
// Collectively compute the warp-wide exclusive prefix sum
int warp_aggregate;
WarpScan(temp_storage).ExclusiveSum(
thread_data, thread_data, warp_aggregate, prefix_op);
// Store scanned items to output segment
d_data[block_offset] = thread_data;
}
Suppose the input d_data is {1, 1, 1, 1, 1, 1, 1, 1, ...}. The corresponding output for the first segment will be {0, 1, 2, ..., 31}. The output for the second segment will be {32, 33, 34, ..., 63}. Furthermore, the value 32 will be stored in warp_aggregate for all threads after each scan.
Template Parameters
WarpPrefixCallbackOp[inferred] Call-back functor type having member T operator()(T warp_aggregate)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[out]warp_aggregate[warp-lane0 only] Warp-wide aggregate reduction of input items (exclusive of the warp_prefix_op value).
[in,out]warp_prefix_op[warp-lane0 only] Call-back functor for specifying a warp-wide prefix to be applied to all inputs.

Definition at line 654 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InclusiveScan ( input,
T &  output,
ScanOp  scan_op 
)
inline

Computes an inclusive prefix scan using the specified binary scan functor across the calling warp.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide inclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute inclusive warp-wide prefix max scans
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).InclusiveScan(thread_data, thread_data, cub::Max());
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output thread_data in the first warp would be 0, 0, 2, 2, ..., 30, 30, the output for the second warp would be 32, 32, 34, 34, ..., 62, 62, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator

Definition at line 708 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InclusiveScan ( input,
T &  output,
ScanOp  scan_op,
T &  warp_aggregate 
)
inline

Computes an inclusive prefix scan using the specified binary scan functor across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide inclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute inclusive warp-wide prefix max scans
int warp_aggregate;
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).InclusiveScan(
thread_data, thread_data, cub::Max(), warp_aggregate);
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output thread_data in the first warp would be 0, 0, 2, 2, ..., 30, 30, the output for the second warp would be 32, 32, 34, 34, ..., 62, 62, etc. Furthermore, warp_aggregate would be assigned 30 for threads in the first warp, 62 for threads in the second warp, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 759 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp , typename WarpPrefixCallbackOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InclusiveScan ( input,
T &  output,
ScanOp  scan_op,
T &  warp_aggregate,
WarpPrefixCallbackOp &  warp_prefix_op 
)
inline

Computes an inclusive prefix scan using the specified binary scan functor across the calling warp. The call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs.

The warp_prefix_op functor must implement a member function T operator()(T warp_aggregate). The functor's input parameter warp_aggregate is the same value also returned by the scan operation. The functor will be invoked by the entire warp of threads, however only the return value from lane0 is applied as the threadblock-wide prefix. Can be stateful.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates a single thread block of 32 threads (one warp) that progressively computes an inclusive prefix max scan over multiple "tiles" of input using a prefix functor to maintain a running total between block-wide scans. Each tile consists of 32 integer items that are partitioned across the warp.
#include <cub/cub.cuh>
// A stateful callback functor that maintains a running prefix to be applied
// during consecutive scan operations.
struct WarpPrefixCallbackOp
{
// Running prefix
int running_total;
// Constructor
__device__ WarpPrefixCallbackOp(int running_total) : running_total(running_total) {}
// Callback operator to be entered by the entire warp. Lane-0 is responsible
// for returning a value for seeding the warp-wide scan.
__device__ int operator()(int warp_aggregate)
{
int old_prefix = running_total;
running_total = (warp_aggregate > old_prefix) ? warp_aggregate : old_prefix;
return old_prefix;
}
};
__global__ void ExampleKernel(int *d_data, int num_items, ...)
{
// Specialize WarpScan for int
// Allocate WarpScan shared memory for one warp
__shared__ typename WarpScan::TempStorage temp_storage;
// Initialize running total
WarpPrefixCallbackOp prefix_op(0);
// Have the warp iterate over segments of items
for (int block_offset = 0; block_offset < num_items; block_offset += 32)
{
// Load a segment of consecutive items
int thread_data = d_data[block_offset];
// Collectively compute the warp-wide inclusive prefix max scan
int warp_aggregate;
WarpScan(temp_storage).InclusiveScan(
thread_data, thread_data, cub::Max(), warp_aggregate, prefix_op);
// Store scanned items to output segment
d_data[block_offset] = thread_data;
}
Suppose the input d_data is {0, -1, 2, -3, 4, -5, ...}. The corresponding output for the first segment will be {0, 0, 2, 2, ..., 30, 30}. The output for the second segment will be {32, 32, 34, 34, ..., 62, 62}. Furthermore, block_aggregate will be assigned 30 in all threads after the first scan, assigned 62 after the second scan, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
WarpPrefixCallbackOp[inferred] Call-back functor type having member T operator()(T warp_aggregate)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator
[out]warp_aggregate[warp-lane0 only] Warp-wide aggregate reduction of input items (exclusive of the warp_prefix_op value).
[in,out]warp_prefix_op[warp-lane0 only] Call-back functor for specifying a warp-wide prefix to be applied to all inputs.

Definition at line 849 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveScan ( input,
T &  output,
identity,
ScanOp  scan_op 
)
inline

Computes an exclusive prefix scan using the specified binary scan functor across the calling warp.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix max scans
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, thread_data, INT_MIN, cub::Max());
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output thread_data in the first warp would be INT_MIN, 0, 0, 2, ..., 28, 30, the output for the second warp would be 30, 32, 32, 34, ..., 60, 62, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]identityIdentity value
[in]scan_opBinary scan operator

Definition at line 913 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveScan ( input,
T &  output,
identity,
ScanOp  scan_op,
T &  warp_aggregate 
)
inline

Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Also provides every thread with the warp-wide warp_aggregate of all inputs.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix max scans
int warp_aggregate;
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, thread_data, INT_MIN, cub::Max(), warp_aggregate);
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output thread_data in the first warp would be INT_MIN, 0, 0, 2, ..., 28, 30, the output for the second warp would be 30, 32, 32, 34, ..., 60, 62, etc. Furthermore, warp_aggregate would be assigned 30 for threads in the first warp, 62 for threads in the second warp, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]identityIdentity value
[in]scan_opBinary scan operator
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 965 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp , typename WarpPrefixCallbackOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveScan ( input,
T &  output,
identity,
ScanOp  scan_op,
T &  warp_aggregate,
WarpPrefixCallbackOp &  warp_prefix_op 
)
inline

Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. The call-back functor warp_prefix_op is invoked to provide the "seed" value that logically prefixes the warp's scan inputs. Also provides every thread with the warp-wide warp_aggregate of all inputs.

The warp_prefix_op functor must implement a member function T operator()(T warp_aggregate). The functor's input parameter warp_aggregate is the same value also returned by the scan operation. The functor will be invoked by the entire warp of threads, however only the return value from lane0 is applied as the threadblock-wide prefix. Can be stateful.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates a single thread block of 32 threads (one warp) that progressively computes an exclusive prefix max scan over multiple "tiles" of input using a prefix functor to maintain a running total between block-wide scans. Each tile consists of 32 integer items that are partitioned across the warp.
#include <cub/cub.cuh>
// A stateful callback functor that maintains a running prefix to be applied
// during consecutive scan operations.
struct WarpPrefixCallbackOp
{
// Running prefix
int running_total;
// Constructor
__device__ WarpPrefixCallbackOp(int running_total) : running_total(running_total) {}
// Callback operator to be entered by the entire warp. Lane-0 is responsible
// for returning a value for seeding the warp-wide scan.
__device__ int operator()(int warp_aggregate)
{
int old_prefix = running_total;
running_total = (warp_aggregate > old_prefix) ? warp_aggregate : old_prefix;
return old_prefix;
}
};
__global__ void ExampleKernel(int *d_data, int num_items, ...)
{
// Specialize WarpScan for int
// Allocate WarpScan shared memory for one warp
__shared__ typename WarpScan::TempStorage temp_storage;
// Initialize running total
WarpPrefixCallbackOp prefix_op(INT_MIN);
// Have the warp iterate over segments of items
for (int block_offset = 0; block_offset < num_items; block_offset += 32)
{
// Load a segment of consecutive items
int thread_data = d_data[block_offset];
// Collectively compute the warp-wide exclusive prefix max scan
int warp_aggregate;
WarpScan(temp_storage).ExclusiveScan(
thread_data, thread_data, INT_MIN, cub::Max(), warp_aggregate, prefix_op);
// Store scanned items to output segment
d_data[block_offset] = thread_data;
}
Suppose the input d_data is {0, -1, 2, -3, 4, -5, ...}. The corresponding output for the first segment will be {INT_MIN, 0, 0, 2, ..., 28, 30}. The output for the second segment will be {30, 32, 32, 34, ..., 60, 62}. Furthermore, block_aggregate will be assigned 30 in all threads after the first scan, assigned 62 after the second scan, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
WarpPrefixCallbackOp[inferred] Call-back functor type having member T operator()(T warp_aggregate)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]identityIdentity value
[in]scan_opBinary scan operator
[out]warp_aggregate[warp-lane0 only] Warp-wide aggregate reduction of input items (exclusive of the warp_prefix_op value).
[in,out]warp_prefix_op[warp-lane0 only] Call-back functor for specifying a warp-wide prefix to be applied to all inputs.

Definition at line 1056 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveScan ( input,
T &  output,
ScanOp  scan_op 
)
inline

Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Because no identity value is supplied, the output computed for warp-lane0 is undefined.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix max scans
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, thread_data, cub::Max());
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output thread_data in the first warp would be ?, 0, 0, 2, ..., 28, 30, the output for the second warp would be ?, 32, 32, 34, ..., 60, 62, etc. (The output thread_data in warp lane0 is undefined.)
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator

Definition at line 1124 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveScan ( input,
T &  output,
ScanOp  scan_op,
T &  warp_aggregate 
)
inline

Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Because no identity value is supplied, the output computed for warp-lane0 is undefined. Also provides every thread with the warp-wide warp_aggregate of all inputs.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix max scans
int warp_aggregate;
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).ExclusiveScan(thread_data, thread_data, cub::Max(), warp_aggregate);
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output thread_data in the first warp would be ?, 0, 0, 2, ..., 28, 30, the output for the second warp would be ?, 32, 32, 34, ..., 60, 62, etc. (The output thread_data in warp lane0 is undefined.) Furthermore, warp_aggregate would be assigned 30 for threads in the first warp, 62 for threads in the second warp, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 1175 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp , typename WarpPrefixCallbackOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::ExclusiveScan ( input,
T &  output,
ScanOp  scan_op,
T &  warp_aggregate,
WarpPrefixCallbackOp &  warp_prefix_op 
)
inline

Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. The warp_prefix_op value from warp-lane0 is applied to all scan outputs. Also computes the warp-wide warp_aggregate of all inputs for warp-lane0.

The warp_prefix_op functor must implement a member function T operator()(T warp_aggregate)}. The functor's input parameter warp_aggregate is the same value also returned by the scan operation. The functor will be invoked by the entire warp of threads, however only the return value from lane0 is applied as the threadblock-wide prefix. Can be stateful.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates a single thread block of 32 threads (one warp) that progressively computes an exclusive prefix max scan over multiple "tiles" of input using a prefix functor to maintain a running total between block-wide scans. Each tile consists of 32 integer items that are partitioned across the warp.
#include <cub/cub.cuh>
// A stateful callback functor that maintains a running prefix to be applied
// during consecutive scan operations.
struct WarpPrefixCallbackOp
{
// Running prefix
int running_total;
// Constructor
__device__ WarpPrefixCallbackOp(int running_total) : running_total(running_total) {}
// Callback operator to be entered by the entire warp. Lane-0 is responsible
// for returning a value for seeding the warp-wide scan.
__device__ int operator()(int warp_aggregate)
{
int old_prefix = running_total;
running_total = (warp_aggregate > old_prefix) ? warp_aggregate : old_prefix;
return old_prefix;
}
};
__global__ void ExampleKernel(int *d_data, int num_items, ...)
{
// Specialize WarpScan for int
// Allocate WarpScan shared memory for one warp
__shared__ typename WarpScan::TempStorage temp_storage;
// Initialize running total
WarpPrefixCallbackOp prefix_op(INT_MIN);
// Have the warp iterate over segments of items
for (int block_offset = 0; block_offset < num_items; block_offset += 32)
{
// Load a segment of consecutive items
int thread_data = d_data[block_offset];
// Collectively compute the warp-wide exclusive prefix max scan
int warp_aggregate;
WarpScan(temp_storage).ExclusiveScan(
thread_data, thread_data, INT_MIN, cub::Max(), warp_aggregate, prefix_op);
// Store scanned items to output segment
d_data[block_offset] = thread_data;
}
Suppose the input d_data is {0, -1, 2, -3, 4, -5, ...}. The corresponding output for the first segment will be {INT_MIN, 0, 0, 2, ..., 28, 30}. The output for the second segment will be {30, 32, 32, 34, ..., 60, 62}. Furthermore, block_aggregate will be assigned 30 in all threads after the first scan, assigned 62 after the second scan, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
WarpPrefixCallbackOp[inferred] Call-back functor type having member T operator()(T warp_aggregate)
Parameters
[in]inputCalling thread's input item.
[out]outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator
[out]warp_aggregate[warp-lane0 only] Warp-wide aggregate reduction of input items (exclusive of the warp_prefix_op value).
[in,out]warp_prefix_op[warp-lane0 only] Call-back functor for specifying a warp-wide prefix to be applied to all inputs.

Definition at line 1265 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::Sum ( input,
T &  inclusive_output,
T &  exclusive_output 
)
inline

Computes both inclusive and exclusive prefix sums across the calling warp.

This operation assumes the value of obtained by the T's default constructor (or by zero-initialization if no user-defined default constructor exists) is suitable as the identity value "zero" for addition.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide prefix sums within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute in|exclusive warp-wide prefix sums
int inclusive_partial, exclusive_partial;
int warp_id = threadIdx.x / 32;
WarpScan(temp_storage[warp_id]).Sum(thread_data, inclusive_partial, exclusive_partial);
Suppose the set of input thread_data across the block of threads is {1, 1, 1, 1, ...}. The corresponding output inclusive_partial in each of the four warps of threads will be 1, 2, 3, ..., 32}. The corresponding output exclusive_partial in each of the four warps of threads will be 0, 1, 2, ..., 31}.
Parameters
[in]inputCalling thread's input item.
[out]inclusive_outputCalling thread's inclusive-scan output item.
[out]exclusive_outputCalling thread's exclusive-scan output item.

Definition at line 1333 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::Scan ( input,
T &  inclusive_output,
T &  exclusive_output,
identity,
ScanOp  scan_op 
)
inline

Computes both inclusive and exclusive prefix scans using the specified binary scan functor across the calling warp.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute inclusive warp-wide prefix max scans
int warp_id = threadIdx.x / 32;
int inclusive_partial, exclusive_partial;
WarpScan(temp_storage[warp_id]).Scan(thread_data, inclusive_partial, exclusive_partial, INT_MIN, cub::Max());
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output inclusive_partial in the first warp would be 0, 0, 2, 2, ..., 30, 30, the output for the second warp would be 32, 32, 34, 34, ..., 62, 62, etc. The corresponding output exclusive_partial in the first warp would be INT_MIN, 0, 0, 2, ..., 28, 30, the output for the second warp would be 30, 32, 32, 34, ..., 60, 62, etc.
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]inclusive_outputCalling thread's inclusive-scan output item.
[out]exclusive_outputCalling thread's exclusive-scan output item.
[in]identityIdentity value
[in]scan_opBinary scan operator

Definition at line 1383 of file warp_scan.cuh.

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
template<typename ScanOp >
__device__ __forceinline__ void cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::Scan ( input,
T &  inclusive_output,
T &  exclusive_output,
ScanOp  scan_op 
)
inline

Computes both inclusive and exclusive prefix scans using the specified binary scan functor across the calling warp. Because no identity value is supplied, the exclusive_output computed for warp-lane0 is undefined.

Supports non-commutative scan operators.

A subsequent __syncthreads() threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., temp_storage) is to be reused or repurposed.

Snippet
The code snippet below illustrates four concurrent warp-wide exclusive prefix max scans within a block of 128 threads (one per each of the 32-thread warps).
#include <cub/cub.cuh>
__global__ void ExampleKernel(...)
{
// Specialize WarpScan for type int
// Allocate WarpScan shared memory for 4 warps
__shared__ typename WarpScan::TempStorage temp_storage[4];
// Obtain one input item per thread
int thread_data = ...
// Compute exclusive warp-wide prefix max scans
int inclusive_partial, exclusive_partial;
WarpScan(temp_storage[warp_id]).Scan(thread_data, inclusive_partial, exclusive_partial, cub::Max());
Suppose the set of input thread_data across the block of threads is {0, -1, 2, -3, ..., 126, -127}. The corresponding output inclusive_partial in the first warp would be 0, 0, 2, 2, ..., 30, 30, the output for the second warp would be 32, 32, 34, 34, ..., 62, 62, etc. The corresponding output exclusive_partial in the first warp would be ?, 0, 0, 2, ..., 28, 30, the output for the second warp would be ?, 32, 32, 34, ..., 60, 62, etc. (The output thread_data in warp lane0 is undefined.)
Template Parameters
ScanOp[inferred] Binary scan operator type having member T operator()(const T &a, const T &b)
Parameters
[in]inputCalling thread's input item.
[out]inclusive_outputCalling thread's inclusive-scan output item.
[out]exclusive_outputCalling thread's exclusive-scan output item.
[in]scan_opBinary scan operator

Definition at line 1435 of file warp_scan.cuh.


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