OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH > Class Template Reference

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

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.

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] \ptxversion
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 non-commutative scan operators
  • 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
\warpcollective{WarpScan}
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);
The WarpScan class provides collective methods for computing a parallel prefix scan of items partitio...
__device__ __forceinline__ void ExclusiveSum(T input, T &exclusive_output)
Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the initial va...
_TempStorage & temp_storage
Shared storage reference.
\smemstorage{WarpScan}
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 146 of file warp_scan.cuh.

Data Structures

struct  TempStorage
 \smemstorage{WarpScan} More...
 

Public Member Functions

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.
 
Inclusive prefix sums
__device__ __forceinline__ void InclusiveSum (T input, T &inclusive_output)
 Computes an inclusive prefix sum across the calling warp.
 
__device__ __forceinline__ void InclusiveSum (T input, T &inclusive_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.
 
Exclusive prefix sums
__device__ __forceinline__ void ExclusiveSum (T input, T &exclusive_output)
 Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the initial value, and is assigned to exclusive_output in thread0.
 
__device__ __forceinline__ void ExclusiveSum (T input, T &exclusive_output, T &warp_aggregate)
 Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the initial value, and is assigned to exclusive_output in thread0. Also provides every thread with the warp-wide warp_aggregate of all inputs.
 
Inclusive prefix scans
template<typename ScanOp >
__device__ __forceinline__ void InclusiveScan (T input, T &inclusive_output, ScanOp scan_op)
 Computes an inclusive prefix scan using the specified binary scan functor across the calling warp.
 
template<typename ScanOp >
__device__ __forceinline__ void InclusiveScan (T input, T &inclusive_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.
 
Exclusive prefix scans
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &exclusive_output, ScanOp scan_op)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Because no initial value is supplied, the output computed for warp-lane0 is undefined.
 
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &exclusive_output, T initial_value, ScanOp scan_op)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp.
 
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &exclusive_output, ScanOp scan_op, T &warp_aggregate)
 Computes an exclusive prefix scan using the specified binary scan functor across the calling warp. Because no initial value is supplied, the output computed for warp-lane0 is undefined. Also provides every thread with the warp-wide warp_aggregate of all inputs.
 
template<typename ScanOp >
__device__ __forceinline__ void ExclusiveScan (T input, T &exclusive_output, T initial_value, 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.
 
Combination (inclusive & exclusive) prefix scans
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 initial value is supplied, the exclusive_output computed for warp-lane0 is undefined.
 
template<typename ScanOp >
__device__ __forceinline__ void Scan (T input, T &inclusive_output, T &exclusive_output, T initial_value, ScanOp scan_op)
 Computes both inclusive and exclusive prefix scans using the specified binary scan functor across the calling warp.
 
Data exchange
__device__ __forceinline__ T Broadcast (T input, unsigned int src_lane)
 Broadcast the value input from warp-lanesrc_lane to all lanes in the warp.
 

Private Types

enum  { IS_ARCH_WARP = (LOGICAL_WARP_THREADS == CUB_WARP_THREADS(PTX_ARCH)) , IS_POW_OF_TWO = ((LOGICAL_WARP_THREADS & (LOGICAL_WARP_THREADS - 1)) == 0) , IS_INTEGER = ((Traits<T>::CATEGORY == SIGNED_INTEGER) || (Traits<T>::CATEGORY == UNSIGNED_INTEGER)) }
 
typedef If<(PTX_ARCH >=300)&&(IS_POW_OF_TWO), WarpScanShfl< T, LOGICAL_WARP_THREADS, PTX_ARCH >, WarpScanSmem< T, LOGICAL_WARP_THREADS, PTX_ARCH > >::Type InternalWarpScan
 Internal specialization. Use SHFL-based scan if (architecture is >= SM30) and (LOGICAL_WARP_THREADS is a power-of-two)
 
typedef InternalWarpScan::TempStorage _TempStorage
 Shared memory storage layout type for WarpScan.
 

Private Attributes

_TempStoragetemp_storage
 Shared storage reference.
 
unsigned int lane_id
 

Member Typedef Documentation

◆ _TempStorage

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
typedef InternalWarpScan::TempStorage cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::_TempStorage
private

Shared memory storage layout type for WarpScan.

Definition at line 172 of file warp_scan.cuh.

◆ InternalWarpScan

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
typedef If<(PTX_ARCH>=300)&&(IS_POW_OF_TWO),WarpScanShfl<T,LOGICAL_WARP_THREADS,PTX_ARCH>,WarpScanSmem<T,LOGICAL_WARP_THREADS,PTX_ARCH>>::Type cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::InternalWarpScan
private

Internal specialization. Use SHFL-based scan if (architecture is >= SM30) and (LOGICAL_WARP_THREADS is a power-of-two)

Definition at line 169 of file warp_scan.cuh.

Member Enumeration Documentation

◆ anonymous enum

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
anonymous enum
private
Enumerator
IS_ARCH_WARP 

Whether the logical warp size and the PTX warp size coincide.

IS_POW_OF_TWO 

Whether the logical warp size is a power-of-two.

IS_INTEGER 

Whether the data type is an integer (which has fully-associative addition)

Definition at line 154 of file warp_scan.cuh.

Constructor & Destructor Documentation

◆ WarpScan()

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 203 of file warp_scan.cuh.

Member Function Documentation

◆ Broadcast()

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
__device__ __forceinline__ T cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::Broadcast ( input,
unsigned int  src_lane 
)
inline

Broadcast the value input from warp-lanesrc_lane to all lanes in the warp.

  • \smemreuse
Snippet
The code snippet below illustrates the warp-wide broadcasts of values from lanes0 in each of four warps to all other threads in those 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 = ...
// Broadcast from lane0 in each warp to all other threads in the warp
int warp_id = threadIdx.x / 32;
thread_data = WarpScan(temp_storage[warp_id]).Broadcast(thread_data, 0);
__device__ __forceinline__ T Broadcast(T input, unsigned int src_lane)
Broadcast the value input from warp-lanesrc_lane to all lanes in the warp.
Suppose the set of input thread_data across the block of threads is {0, 1, 2, 3, ..., 127}. The corresponding output thread_data will be {0, 0, ..., 0} in warp0, {32, 32, ..., 32} in warp1, {64, 64, ..., 64} in warp2, etc.
Parameters
[in]inputThe value to broadcast
[in]src_laneWhich warp lane is to do the broadcasting

Definition at line 922 of file warp_scan.cuh.

◆ ExclusiveScan() [1/4]

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 &  exclusive_output,
ScanOp  scan_op 
)
inline

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

  • \smemreuse
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());
__device__ __forceinline__ void ExclusiveScan(T input, T &exclusive_output, ScanOp scan_op)
Computes an exclusive prefix scan using the specified binary scan functor across the calling warp....
Default max functor.
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]exclusive_outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator

Definition at line 551 of file warp_scan.cuh.

◆ ExclusiveScan() [2/4]

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 &  exclusive_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 initial value is supplied, the output computed for warp-lane0 is undefined. Also provides every thread with the warp-wide warp_aggregate of all inputs.

  • \smemreuse
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]exclusive_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 668 of file warp_scan.cuh.

◆ ExclusiveScan() [3/4]

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 &  exclusive_output,
initial_value,
ScanOp  scan_op 
)
inline

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

  • \smemreuse
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]exclusive_outputCalling thread's output item. May be aliased with input.
[in]initial_valueInitial value to seed the exclusive scan
[in]scan_opBinary scan operator

Definition at line 607 of file warp_scan.cuh.

◆ ExclusiveScan() [4/4]

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 &  exclusive_output,
initial_value,
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.

  • \smemreuse
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]exclusive_outputCalling thread's output item. May be aliased with input.
[in]initial_valueInitial value to seed the exclusive scan
[in]scan_opBinary scan operator
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 729 of file warp_scan.cuh.

◆ ExclusiveSum() [1/2]

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 &  exclusive_output 
)
inline

Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the initial value, and is assigned to exclusive_output in thread0.

  • \identityzero
  • \smemreuse
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]exclusive_outputCalling thread's output item. May be aliased with input.

Definition at line 349 of file warp_scan.cuh.

◆ ExclusiveSum() [2/2]

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 &  exclusive_output,
T &  warp_aggregate 
)
inline

Computes an exclusive prefix sum across the calling warp. The value of 0 is applied as the initial value, and is assigned to exclusive_output in thread0. Also provides every thread with the warp-wide warp_aggregate of all inputs.

  • \identityzero
  • \smemreuse
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]exclusive_outputCalling thread's output item. May be aliased with input.
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 394 of file warp_scan.cuh.

◆ InclusiveScan() [1/2]

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 &  inclusive_output,
ScanOp  scan_op 
)
inline

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

  • \smemreuse
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());
__device__ __forceinline__ void InclusiveScan(T input, T &inclusive_output, ScanOp scan_op)
Computes an inclusive prefix scan using the specified binary scan functor across the calling warp.
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]inclusive_outputCalling thread's output item. May be aliased with input.
[in]scan_opBinary scan operator

Definition at line 447 of file warp_scan.cuh.

◆ InclusiveScan() [2/2]

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 &  inclusive_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.

  • \smemreuse
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;
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]inclusive_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 497 of file warp_scan.cuh.

◆ InclusiveSum() [1/2]

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 &  inclusive_output 
)
inline

Computes an inclusive prefix sum across the calling warp.

  • \smemreuse
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);
__device__ __forceinline__ void InclusiveSum(T input, T &inclusive_output)
Computes an inclusive prefix sum across the calling warp.
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]inclusive_outputCalling thread's output item. May be aliased with input.

Definition at line 254 of file warp_scan.cuh.

◆ InclusiveSum() [2/2]

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 &  inclusive_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.

  • \smemreuse
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]inclusive_outputCalling thread's output item. May be aliased with input.
[out]warp_aggregateWarp-wide aggregate reduction of input items.

Definition at line 297 of file warp_scan.cuh.

◆ Scan() [1/2]

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 initial value is supplied, the exclusive_output computed for warp-lane0 is undefined.

  • \smemreuse
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());
__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...
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 799 of file warp_scan.cuh.

◆ Scan() [2/2]

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,
initial_value,
ScanOp  scan_op 
)
inline

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

  • \smemreuse
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]initial_valueInitial value to seed the exclusive scan
[in]scan_opBinary scan operator

Definition at line 858 of file warp_scan.cuh.

Field Documentation

◆ lane_id

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
unsigned int cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::lane_id
private

Definition at line 181 of file warp_scan.cuh.

◆ temp_storage

template<typename T , int LOGICAL_WARP_THREADS = CUB_PTX_WARP_THREADS, int PTX_ARCH = CUB_PTX_ARCH>
_TempStorage& cub::WarpScan< T, LOGICAL_WARP_THREADS, PTX_ARCH >::temp_storage
private

Shared storage reference.

Definition at line 180 of file warp_scan.cuh.


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