Skip to content

gh-216: add intersect - #245

Open
LuhTonkaYeat wants to merge 3 commits into
SparseLinearAlgebra:mainfrom
LuhTonkaYeat:feature/cl-intersect
Open

LuhTonkaYeat wants to merge 3 commits into
SparseLinearAlgebra:mainfrom
LuhTonkaYeat:feature/cl-intersect

Conversation

@LuhTonkaYeat

@LuhTonkaYeat LuhTonkaYeat commented Sep 21, 2026 •

Copy link
Copy Markdown

Adds exec_intersect --- set intersection of two sorted key-value arrays with a
binary operation applied to matched values.

Implementation

  • CPU: cpu_intersect.hpp (two-pointer merge).
  • OpenCL: cl_intersect.hpp + kernel intersect.cl (naive fallback);
    shared merge module cl_merge.hpp + kernels merge.cl / merge_union.cl.
    Public API, schedule task, registry entries (INT/UINT/FLOAT), C binding
    spla_Exec_intersect.

OpenCL notes

  • Merge path: array A is split into tiles, each tile binary-searches its window
    in B; per-tile counts are turned into output offsets with an exclusive scan,
    so the result is deterministic, sorted and written without atomics.
  • Shared module: the same primitive is exposed via cl_merge.hpp for other
    algorithms; input and output buffer offsets allow processing CSR row slices
    without copying.
  • Union mode: merge of two sorted key-value arrays with equal keys folded by the
    binary operation; uses diagonal merge-path partition (co-rank search) with
    boundary snapping so an equal pair is never split between tiles.
  • Hybrid: strongly asymmetric inputs fall back to the binary-search kernel,
    which iterates the smaller array and is faster there.
  • Result stored as a coordinate (COO) vector so genuine zero keys/values are
    not confused with empty entries.
  • Grid-stride kernel loop keeps large inputs correct despite the grid clamp.
    Null-argument guard for parity with CPU.

Tests

CPU: test_intersect (7 cases).
OpenCL: test_opencl_intersect (22 cases) — types, boundary keys/values, tile
boundaries, exact tile multiples, asymmetric sizes in both directions, large
inputs, negative cases, deferred (scheduled) path, sorted deterministic output.
Merge module: test_merge_union (14 checks) — folding union, intersection,
buffer offsets, tile boundaries, large inputs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant