Template Numerical Library: Lambda Functions for Segment Sort Operations

Template Numerical Library version\ main:16b9213d5

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

This page describes the lambda function signatures used in segment sort operations.

# Fetch Lambda

The fetch lambda retrieves the value of an element for comparison during sorting. 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.

# Compare Lambda

The compare lambda determines the ordering of two elements during sorting. It has the following signature:

auto compare = [=] __cuda_callable__ ( ValueType a, ValueType b ) -> bool
{
// Return true if a should come before or equal to b
return a <= b;
};

The lambda should return true if a should come before or be equal to b in the sorted order.

# Swap Lambda

The swap lambda exchanges two elements during the sorting process. It has the following signature:

auto swap = [=] __cuda_callable__ ( IndexType globalIdx1, IndexType globalIdx2 )
{
// Swap elements at positions globalIdx1 and globalIdx2
...
};

- globalIdx1 is the index of the first element to swap.
- globalIdx2 is the index of the second element to swap.

# Condition Lambda

The condition lambda determines which segments should be sorted. It has the following signature:

auto condition = [=] __cuda_callable__ ( IndexType segmentIdx ) -> bool
{
// Return true if segment should be sorted
return ...;
};

- segmentIdx is the index of the segment.

The lambda should return true if the segment should be sorted.