KokkosGraph provides routines to traverse the merge path induced by two ordered rank-1 inputs. Instead of generating a materialized merged output, these routines invoke a user-provided stepper for every step along the path. This is useful for performing custom work during a merge operation without the overhead of allocating a new merged view.
Available Routines
merge_path_thread: Used when the caller wants to perform custom per-step work within a single thread. It allows forwarding optional contexts (ctxs) to the stepper.merge_path_team: Partitions the merge path across a Kokkos team. It forwards a thread-level context to each stepper invocation.
Core Abstractions
StepperContext: A struct recording the current positions in the inputs and the path:ai: Position in the first input (a).bi: Position in the second input (b).pi: Overall position in the path.
StepDirection: An enum indicating which input is being consumed in the current step:StepDirection::a: The step consumes an element from input a.StepDirection::b: The step consumes an element from input b.
// Example of a basic thread-level merge path traversal
#include <Kokkos_Core.hpp>
#include <KokkosGraph_MergePath.hpp>
template <class AView, class BView>
void example(const AView& a, const BView& b) {
auto stepper = [](KokkosGraph::StepDirection dir,
KokkosGraph::StepperContext step) {
(void)dir;
(void)step;
};
KokkosGraph::merge_path_thread(a, b, a.size() + b.size(), stepper);
}