Template Numerical Library: Lambda Functions for Segment Scan Operations

Template Numerical Library version\ main:0b2c40fb1

Loading...
Searching...
No Matches
Lambda Functions for Segment Scan Operations

This page describes the lambda function signatures used in segment scan (prefix-sum) operations.

# Fetch Lambda

The fetch lambda retrieves the value of an element for the scan operation. It has one of the following forms:

Full form:

auto fetch = [=] __cuda_callable__ ( IndexType segmentIdx, IndexType localIdx, IndexType globalIdx )
{
// Return the value at the given position
return ...;
};
__cuda_callable__
#define __cuda_callable__
Definition Macros.h:49

Brief form:

auto fetch = [=] __cuda_callable__ ( IndexType globalIdx )
{
// Return the value at the given position
return ...;
};

In both variants:

- segmentIdx is the index of the segment.
- localIdx is the rank of the element within the segment.
- globalIdx is the index of the element in the corresponding container.

# Reduction Function Object

The scan operation uses a reduction function object to combine values. See Function objects for reduction operations for available reduction operations like:

- TNL::Plus - Addition
- TNL::Multiplies - Multiplication
- TNL::Min - Minimum
- TNL::Max - Maximum

# Write Lambda

The write lambda stores the result of the scan operation. It has the following signature:

auto write = [=] __cuda_callable__ ( IndexType globalIdx, ValueType value )
{
// Write the value at the given position
output[globalIdx] = value;
};

- globalIdx is the index where the result should be written.
- value is the scan result to write.

Note: The implementation allows in-place scan (the write function may modify the input array).

# Condition Lambda

The condition lambda determines which elements should be included in the scan operation. It has the following signature:

auto condition = [=] __cuda_callable__ ( IndexType segmentIdx, IndexType localIdx, IndexType globalIdx ) -> bool
{
// Return true if element should be included in scan
return ...;
};

- segmentIdx is the index of the segment.
- localIdx is the rank of the element within the segment.
- globalIdx is the index of the element in the corresponding container.

The lambda should return true if the element should be included in the scan.