Skip to content

Add exact keyed collection reduction - #19

Merged
PraneethMerugu merged 1 commit into
mainfrom
codex/keyed-reduction-pr18
Sep 15, 2026
Merged

PraneethMerugu merged 1 commit into
mainfrom
codex/keyed-reduction-pr18

Conversation

@PraneethMerugu

Copy link
Copy Markdown
Owner

Outcome

Adds one exact fixed-capacity keyed collection reduction to LocalMath's existing StageProgram and KernelAbstractions executor. This is the reusable storage/publication primitive required by CorePotts maintained generation-aware owner-pair multiplicity without an O(C²) directory or collision-unsafe hash.

Contract

  • exact Int32, UInt32, or bounded flat-tuple keys
  • unique stage-entry keys
  • existing value first, then participating contributions in canonical (source, lane) order
  • explicit new-key identity and retain/drop-identity policy
  • private O(capacity + source_count × maximum) workspace
  • failure-atomic records and logical-count publication on invalid prior count, duplicate prior keys, invalid control, or overflow
  • one shared CPU/Metal semantic implementation; no Potts vocabulary, registry, hash mode, relaxed fold, or second executor

Compiler and allocation evidence

  • matched Collect host orchestration: 112 typed statements, 79 calls, 22 Any SSA slots
  • keyed host orchestration: 222 typed statements, 165 calls, 31 Any SSA slots
  • device-reachable materialization boundary: 129 statements, 73 calls, zero Any-valued expressions (37 control-flow/return CodeInfo slots)
  • device-reachable sort boundary: 260 statements, 139 calls, zero Any-valued expressions (87 control-flow/return CodeInfo slots)
  • device-reachable fold boundary: 363 statements, 204 calls, zero Any-valued expressions (105 control-flow/return CodeInfo slots)
  • device-reachable publication boundary: 231 statements, 137 calls, zero Any-valued expressions (63 control-flow/return CodeInfo slots)
  • capacity specialization count: 1 across capacities 4 and 8
  • across four operation/retention variants, bounds/emission/sort/segment/finalize/publication each have one specialization; folding has four, as intended
  • warm public call: 8,432 bytes versus 4,768 bytes for the matched Collect control
  • the 3,664-byte delta is shared KernelAbstractions kernel/NDRange/keyword/argument construction and receipt bookkeeping; device workspace is preparation-owned and execution performs no device allocation
  • the reproducible probes were executed through a Kaimon persistent LocalMath project session

Eliminating that host delta safely requires an executor-wide prepared-launch/fusion contract. This PR does not add a keyed-only shortcut or fuse across required global scan barriers.

Validation

  • focused keyed CPU contracts: 40/40
  • real Metal with scalar indexing disabled: 24/24
  • full LocalMath package suite: 1,853/1,853
  • documentation build, doctests, link checks, and rendering: passed
  • public constructor/API regression after final tightening: 27/27
  • independent review and final narrow re-review: clean

Chain position

Planning companion C08, based on merged LocalMath PR18 (9d3e1a24). It precedes Core R10 maintained spatial queries and Potts R11 lowering.

@PraneethMerugu
PraneethMerugu marked this pull request as ready for review September 15, 2026 00:07
@PraneethMerugu
PraneethMerugu merged commit 7082ed8 into main Sep 15, 2026
7 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.

1 participant