Repository navigation
u64x64 lab route G: NNUE-style accumulator over a bound 64×64 Boolean tile - #429
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
h = bias + sum of w[k][r] over the set cells of a 64x64 BitTile. refresh walks set bits; update adds the rows of cells that turned on and subtracts the rows that turned off, from old ^ new. Scalar and I32x16 (from_i16_slice) variants. Weights are i16, the accumulator i32, exact by an admitted bound rather than by wrapping. Bound entry points read Source::present through fixture::Bound and refuse frames of other sources, shapes or row orders; versions may differ. Tests check every route against a per-cell i64 oracle on all 4,096 single-cell tiles, empty, full and 200 random tiles, 1,000 mixed updates undone in reverse, the bound extremes, refusals, zero allocation, and the multiplicity counterexample (a tile is a set, a bag is not). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Registers the u64x64_nnue example (refresh against update, scalar against I32x16, allocation guard, tier line) and records the measured results against the pre-registered predictions on the blackboard: P1, P2, P3, P6 hold; the 1-bit update is 58x cheaper than a half-tile refresh, not 100x; the I32x16 route is 1.06x scalar because LLVM already vectorizes the scalar add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
AdaWorldAPI
marked this pull request as ready for review
November 14, 2026 23:40
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
nnue_refresh_simd2 alternates consecutive set bits between two I32x16 accumulators; nnue_refresh_simd4 round-robins over four. Both are checked against the per-cell oracle on every corpus. The bench now interleaves the four refresh variants per sample with a rotated order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Single-cell tiles never reach the second accumulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
The weights are transposed once into bit planes (plane[b][k][j] holds bit b of w[k][r][j] over rows r); the refresh then counts popcount(tile[k] & plane) per bit and recombines with 2^b, the sign plane negative. nnue_refresh_planes popcounts every word; nnue_refresh_abakus adds the masks into carry-save columns (ternlog 0x96 / 0xE8, Harley-Seal over 16 words) and popcounts each column once. Both are density-independent and checked against the per-cell oracle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Laboratory only: no
src/edit, no public type, no production caller.Question
Can the existing 512-byte
BitTile([u64; 64], 4,096 cells: wordkis categoryk, bitris rowr) be an exact, incrementally updatable NNUE-style feature surface?The accumulator is
h[j] = bias[j] + Σ_{(k, r) set} w[k][r][j]forj < 16.Kinds kept apart
i16i32|bias| ≤ 2^15,w ≠ i16::MIN, so|h| < 2^28; refused at construction, never wrapped64×64(4,096 positional features),u64 × u64(integer multiplication) andΣ c_L·c_R(bag cardinality) are three different operations. The tile is the first one only.What
examples/u64x64/nnue.rs:nnue_refresh: walks set bits withtrailing_zerosand gathers one weight row per set bit.nnue_update:d = old ^ new, adds the rows that turned on (d & new) and subtracts those that turned off (d & old). Correct only when the accumulator is that ofold.*_simdvariants: the existingI32x16::from_i16_slicewithAdd/Sub; no new primitive.nnue_refresh_simd2/nnue_refresh_simd4: two and four independent accumulators. A recorded negative result.PlaneWeightsplusnnue_refresh_planes/nnue_refresh_abakus: per-bit addressing, described below.refresh_bound/update_bound: readSource::presentthroughfixture::Bound. An update refuses two frames of different sources (ForeignSource), shapes (Shape) or row orders (RowOrder), or without the presence field (Field), and leaves the accumulator untouched. Versions may differ: an update is between versions, and the older frame still binds to its own expectation.examples/u64x64/nnue_main.rs(exampleu64x64_nnue): the benchmark, reusing the lab harness (counting allocator, tier line). The six refresh variants are interleaved within each sample, in rotated order.Tests
tests/u64x64_nnue.rs, 12 tests, against an independent oracle that reads all 4,096 cells one bit at a time and sums ini64:i16::MIN, a bias past2^15, and a 63-row table;(k, r)edge is not equal to the tile's sum.Disable runs, all red:
i16::MINadmittedsimd2drops its second accumulatorResults: walk and update
AVX-512, read from the binary:
avx512f=true avx512bw=true avx512vpopcntdq=true. Median of 31 samples × 2,000 calls.Update on a half-full tile, ns per update:
Resident memory: weights 131,072 B (fits L2, not L1), tile 512 B, accumulator 64 B. Scratch: 0 B.
Against the predictions (pre-registered on the blackboard before the code was written):
I32x16walk is 1.06× the scalar one, not ≥2×.objdumpshows LLVM compiles the scalar 16-lane add to the samevpmovsxwd+vpaddd.Multi-accumulator refresh: hypothesis falsified
The hypothesis was that the walk is limited by the latency of the add chain on one accumulator. The kill condition was hit:
The one-accumulator loop is six instructions per set bit (
tzcnt,shl,vpmovsxwdfrom memory,vpaddd,blsr,jne). The two-accumulator version adds a branch per pair of bits. The four-accumulator version spills its accumulator array to the stack.Per-bit addressing: bit planes and the Abakus column counter
The weights are transposed once into bit planes:
plane[b][k][j]is au64whose bitris bitbofw[k][r][j]. That is 131,072 B, the same bytes as the weights. The refresh is thenh[j] = bias[j] + Σ_{b<15} 2^b·n[b][j] − 2^15·n[15][j], withn[b][j] = Σ_k popcount(tile[k] & plane[b][k][j]).Bit 15 is the sign bit, hence the minus. The tile bit is read in place as the address and no row is gathered.
planespopcounts every word (U64x8, 8 output lanes per vector).abakusadds the masks into carry-save columns: the full-adder law asternlog0x96 (sum) and 0xE8 (carry), with the carry moving to the adjacent column, using Harley-Seal over groups of 16 words. Each column is popcounted once.ns per tile, the six variants interleaved. AVX-512 runs 1 and 3 (run 2 was disturbed); AVX2 all three runs:
Against the predictions:
vpopcntqis one instruction.U64x8::popcntthere is 8 scalarcount_ones.On AVX-512, planes beat the walk from about 3/4 density (1.10× at 3/4, about 1.3× full). On AVX2 the walk wins everywhere. The planes do fixed work: 2,048
U64x8and+popcnt+add per refresh, touching all 4,096 cells × 16 lanes × 16 bits whether set or not. The walk touches one 32-byte row per set bit.Not measured
Decision
Keep laboratory only.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU