cub::GridQueue

Defined in /home/runner/work/cccl/cccl/cub/cub/grid/grid_queue.cuh

template<typename OffsetT>
class GridQueue

GridQueue is a descriptor utility for dynamic queue management.

Overview

GridQueue descriptors provides abstractions for “filling” or “draining” globally-shared vectors.

A “filling” GridQueue works by atomically-adding to a zero-initialized counter, returning a unique offset for the calling thread to write its items. The GridQueue maintains the total “fill-size”. The fill counter must be reset using GridQueue::ResetFill by the host or kernel instance prior to the kernel instance that will be filling.

Similarly, a “draining” GridQueue works by works by atomically-incrementing a zero-initialized counter, returning a unique offset for the calling thread to read its items. Threads can safely drain until the array’s logical fill-size is exceeded. The drain counter must be reset using GridQueue::ResetDrain or GridQueue::FillAndResetDrain by the host or kernel instance prior to the kernel instance that will be filling. (For dynamic work distribution of existing data, the corresponding fill-size is simply the number of elements in the array.)

Iterative work management can be implemented simply with a pair of flip-flopping work buffers, each with an associated set of fill and drain GridQueue descriptors.

Template Parameters

OffsetT – Signed integer type for global offsets

Public Functions

inline GridQueue()

Constructs an invalid GridQueue descriptor.

inline GridQueue(void *d_storage)

Constructs a GridQueue descriptor around the device storage allocation.

Parameters

d_storage – Device allocation to back the GridQueue. Must be at least as big as AllocationSize().

inline cudaError_t FillAndResetDrain(OffsetT fill_size, cudaStream_t stream = 0)

This operation sets the fill-size and resets the drain counter, preparing the GridQueue for draining in the next kernel instance. To be called by the host or by a kernel prior to that which will be draining.

inline cudaError_t ResetDrain(cudaStream_t stream = 0)

This operation resets the drain so that it may advance to meet the existing fill-size. To be called by the host or by a kernel prior to that which will be draining.

inline cudaError_t ResetFill(cudaStream_t stream = 0)

This operation resets the fill counter. To be called by the host or by a kernel prior to that which will be filling.

inline cudaError_t FillSize(OffsetT &fill_size, cudaStream_t stream = 0)

Returns the fill-size established by the parent or by the previous kernel.

inline OffsetT Drain(OffsetT num_items)

Drain num_items from the queue. Returns offset from which to read items. To be called from CUDA kernel.

inline OffsetT Fill(OffsetT num_items)

Fill num_items into the queue. Returns offset from which to write items. To be called from CUDA kernel.

Public Static Functions

static inline size_t AllocationSize()

Returns the device allocation size in bytes needed to construct a GridQueue instance.