Skip to content

simd: masked_strided_group_sum — the strided sub-word gather consumers lacked - #283

Merged
AdaWorldAPI merged 1 commit into
masterfrom
claude/c64-6502-falsifier-shztkk
Aug 25, 2026
Merged

simd: masked_strided_group_sum — the strided sub-word gather consumers lacked#283
AdaWorldAPI merged 1 commit into
masterfrom
claude/c64-6502-falsifier-shztkk

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Closes a named gap rather than adding surface speculatively.

lance-graph-java's mask-native sweep needed "gather a sub-word group out of a strided register under a runtime grouping and widen-accumulate". masked_sum_i32 is contiguous i32; eq_u32_strided_to_mask reads one aligned u32 per record. Neither covers it, so the consumer carried its own scalar loop and documented the absence as a W1a gap — added THERE, consumed here — which is the shape the "all SIMD from ndarray::simd" invariant asks for. That consumer's loop is now one delegating call.

The kernel is scalar, and the doc gives the reasoning rather than an apology

One small register per record at a large stride (512 bytes in the motivating case) is memory-bound; records are not adjacent so several cannot be vector-loaded; and widening six u16s inside one record would optimise the part that is already free. A contiguous or small-stride variant would genuinely vectorise and is named as a different primitive — not a flag on this one.

Correctness details that are easy to get wrong

  • Overflow is reported, not wrapped: accumulates in i128, range-checks once. With group_bytes = 4 one record contributes up to groups × (2³² − 1).
  • Sub-word loads are byte-wise: a group's offset is not guaranteed aligned for a 3-byte grouping, and an unaligned wide read is UB in Rust even where the hardware tolerates it.
  • Dirty mask tails are clamped, same guard and same reason as masked_sum_i32.

Tests

Six, each falsifiable — notably that the three groupings of one register must give three different answers, so a kernel ignoring its grouping fails; plus the two contract violations (group_bytes outside 1..=4, a record reading past the buffer) as should_panic.


Generated by Claude Code

…s lacked

Closes a named gap rather than adding surface speculatively. lance-graph-java's
mask-native sweep needed "gather a sub-word group out of a strided register
under a runtime grouping and widen-accumulate": masked_sum_i32 is contiguous
i32, eq_u32_strided_to_mask reads one aligned u32 per record, and neither
covers it. The consumer carried its own scalar loop and documented the absence
as a W1a gap -- added THERE, consumed here -- which is exactly the shape the
"all SIMD from ndarray::simd" invariant asks for.

The kernel is scalar, and the doc says why with the reasoning rather than an
apology: one small register per record at a large stride (512 bytes in the
motivating case) is memory-bound, records are not adjacent so several cannot be
vector-loaded, and widening six u16s inside one record would optimise the part
that is already free. A contiguous or small-stride variant WOULD vectorise and
is named as a different primitive, not a flag on this one.

Overflow accumulates in i128 and range-checks once, returning None rather than
a wrapped value: with group_bytes = 4 a single record contributes up to
groups × (2^32 - 1). Sub-word loads are byte-wise because a group's offset is
not guaranteed aligned for a 3-byte grouping, and an unaligned wide read is UB
in Rust even where the hardware tolerates it.

Six tests, each falsifiable: the three groupings of one register must give
three DIFFERENT answers (so a kernel ignoring its grouping fails); the mask and
stride both bind; a dirty tail bit past n_records is ignored; overflow is
reported with the row bound asserted rather than narrated; and the two contract
violations (group_bytes outside 1..=4, a record reading past the buffer) panic.
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 24f56203-8f75-444c-9f6c-92e2391c0e44


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Aug 25, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_b253c248-01f9-482d-8bd0-90ec71b1e3ef)

@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review August 25, 2026 12:29
@AdaWorldAPI
AdaWorldAPI merged commit c6262d6 into master Aug 25, 2026
21 checks passed
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.

2 participants