Skip to content

dr-isa-stream-lab: INT8 u8×i8 arm and FACET STRIDE audit (D-DT64-GEMM-SHAPE-3) - #1990

Merged
AdaWorldAPI merged 2 commits into
mainfrom
ccr-8062bcc7-l7lkz9-int8-on-ba
Nov 10, 2026
Merged

AdaWorldAPI merged 2 commits into
mainfrom
ccr-8062bcc7-l7lkz9-int8-on-ba

Conversation

@AdaWorldAPI

@AdaWorldAPI AdaWorldAPI commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #1988 and #1989, both merged; this PR now targets main. Not for automatic merge.

Contract: .claude/knowledge/dr-dt64-locality-execution-contract.md (EXO-220).

Central question

Is DT64 merely routing existing SoA positions to AMX, or are we accidentally moving and folding data that ndarray's FACET STRIDE logic already knows how to process in place?

Answer: DT64 routes the positions. The BF16 arm reads A in place. The data movement that remains is the hardware's own requirement (VNNI packing of B) plus one INT8 staging copy of A. That copy exists because ndarray has no strided-A INT8 entry.

What this adds

  • A u8 × i8 → i32 arm over the same virtual object, fixture and B table as the BF16 arms. It calls ndarray::backend::gemm_i8, which runs AMX TDPBUSD.

  • The TDPBUSD operand contract is kept. A is unsigned (value + 8) and B is signed, with no reinterpretation.

    • Test: a_is_never_reinterpreted_as_signed (200 × −1 = −200·K).
  • Cross-check against BF16 on the same fixture: C_int8 = C_bf16 + 8·colsum(B).

    • Test: int8_and_bf16_agree_on_the_same_fixture.
  • Prepared-B reuse is keyed on authoritative identity, not a digest. The FNV selection key is removed. B is reused only if all of these match:

    • the object it was packed for, or else the full selection, the frame issue and the width;
    • always, the operand identity: the function's seed or the immutable table instance, plus the revision.

    Two tables with equal values and the same revision count as different operands.

    • Test: prepared_b_reuse_is_keyed_by_identity_not_a_digest.
    • Disable run: dropping the operand compare turned both prepared-B tests red.

Correction to #1987

#1987 said B preparation costs about as much as the GEMM. That was wrong. Its timer included the hash of the synthetic operand. With a B table built once, preparing B costs about 45 µs, roughly a third of the BF16 GEMM.

Results at 256 fields

All measurements: one AMX VM, same fixture, six runs. The raw output of the last three runs is in results/shape-2026-11-10-int8-run*.txt. Run-to-run variation is up to about 35%.

Row BF16 INT8
GEMM 138–152 µs (direct strided, A not copied) 61–82 µs (204–275 GMAC/s)
… of which B band gather + VNNI pack, timed apart with vnni_pack_i8 — 23–29 µs, 36–38% of the GEMM (54% at 64 fields)
Stage A 0 B (read in place) 5–7 µs, one region copy per lane; the per-value walk takes 34–43 µs
B prepared once, ~45 µs borrowed in place, ~30 ns; materializing it takes 46–59 µs
Warm end to end 103–160 µs 66–101 µs

The pack row is measured separately from the cost of reading the B table.

Audit verdicts

Operation Verdict
Positional reading (BF16 A) REUSED: strided tile GEMM, 0 bytes of A copied
DT64 routing REUSED: one borrow_all, lanes in view order
AMX accumulation REUSED: TDPBF16PS / TDPBUSD through ndarray
LUT (lut_u8, lut9) NOT APPLICABLE: no GEMM caller
Masked fold NOT APPLICABLE: a GEMM is not a fold over a mask
VNNI packing NOT APPLICABLE: required by the hardware; prepare once, reuse by identity
INT8 A staging and B re-pack OPTIMIZATION FOUND (see below)

INT8 A staging and B re-pack. In this lab, A is now a region copy and B is borrowed in place. At the ndarray layer, gemm_i8 re-packs B on every call, which costs 36–38% of its GEMM. That justifies a separate ndarray PR adding PackedI8B and a strided-A INT8 entry, the INT8 counterparts of PackedBf16B and #414. That ndarray PR is proposed, not part of this one. ndarray is unchanged here, and facet-stride-guard --diff origin/main reports 0 hits.

Governing question

What does this implementation recompute or reconstruct per operation that it could lawfully resolve once per binding?

INT8 B is gathered and VNNI-packed again on every call. A prepacked INT8 B, keyed on operand identity and revision, would do that once per binding. That is the ndarray follow-up.

Gates

  • cargo fmt --check is clean.
  • cargo clippy --release --all-targets -D warnings is clean.
  • cargo test --release: 43 passed.
  • facet-stride-guard: 0 hits.
  • Board entry: .claude/board/entries/2026-11-10-dt64-int8-facet-stride.md.
  • No G2L experiment is included.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

…MM-SHAPE-3)

Adds a u8 x i8 -> i32 arm over the same DT64 virtual object and fixture as
the BF16 arms, run through ndarray::backend::gemm_i8 (AMX TDPBUSD). A is
unsigned (value + 8) and B signed, so the instruction's operand contract
holds with no reinterpretation. C_int8 = C_bf16 + 8 * colsum(B) is checked
on the same fixture.

A is staged with one region copy per lane (5-7 us at 256 fields, against
34-43 us for the per-value walk). B is borrowed in place from its table when
the selection is a region of the right length (about 30 ns, against 46-59 us
to materialize). The band gather and VNNI pack that gemm_i8 does on every
call are timed apart with ndarray's own vnni_pack_i8: 23-29 us, 36-38% of the
INT8 GEMM at 256 fields.

Prepared-B reuse is keyed on authoritative identity instead of a digest: the
object it was packed for, otherwise the full selection, frame issue and
width, and always the operand's identity (function seed or table instance,
plus revision). The FNV selection key is removed.

Corrects #1987's "B preparation ~ GEMM": that timer included the synthetic
operand's hash. From a table built once, B preparation is about a third of
the BF16 GEMM.

ndarray is unchanged; the facet-stride guard reports no hits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

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

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c258ee48-42b9-49be-8771-930fe61c2597
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@AdaWorldAPI
AdaWorldAPI changed the base branch from ccr-8062bcc7-l7lkz9-lab-borrow-all to main November 10, 2026 17:13
@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review November 10, 2026 17:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T17:14:58.879346Z fa7e4de Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa7e4de5cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/dr-isa-stream-lab/src/shape.rs Resolved
A BTable indexes row-major, so a column past its width read the next row:
a 64-column table under a 256-column object returned B[1][0] for B[0][64]
and the GEMM completed with wrong values. Each arm that reads B (prepare,
cblas, the INT8 arm) now checks the table's rows and columns against the
object first and returns ShapeRefusal::OperandShape. The table accessors
also assert the column, so any other caller panics instead of misreading.
PreparedB::prepare returns a Result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
@AdaWorldAPI
AdaWorldAPI merged commit 0767cc0 into main Nov 10, 2026
12 checks passed
AdaWorldAPI pushed a commit that referenced this pull request Nov 10, 2026
TranslatedB::extent() reported the source's position range, so an identity
past the inner table passed admit_operand and packing indexed past the
table. extent() now reports the inner operand's own extent, and BValues
gains highest_row(selection), which TranslatedB overrides to resolve each
selected position to the identity it reads. admit_operand then refuses
with ShapeRefusal::OperandShape before any packing (#1990's contract).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk
AdaWorldAPI added a commit that referenced this pull request Nov 10, 2026
…cross GEMMs (D-DT64-G2L-1) (#1994)

* dr-isa-stream-lab: INT8 direct arm on ndarray's prepacked INT8 entries

Adds int8::direct and int8::PreparedI8B. A is read in place at the u8
lanes' pitch and B is prepared once as PackedI8B bands, through
ndarray::simd::int8_gemm_packed_strided (AdaWorldAPI/ndarray#418). The
prepared-B reuse rule moves into shape::ReuseKey, shared by the BF16 and
INT8 prepared operands so the two cannot drift.

Measured on one AMX VM (median of 41 warm runs, three runs), 256 fields x
256 columns: the direct GEMM takes 45.5-48.1 us against 78.3-78.8 us for
backend::gemm_i8, end to end 47.5-57.9 us against 88.9-92.2 us; at 64
fields 0.98-1.01 us against 3.4-3.6 us. No A copied, no allocation.

Needs ndarray#418.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* dr-isa-stream-lab: record the INT8 direct arm results

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* wip: G2L lab, one witnessed translation reused across GEMMs (untested)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* dr-isa-stream-lab: time the B pack through ndarray::simd, not hpc

The benchmark's pack-timing row called ndarray::hpc::amx_matmul::vnni_pack_i8
directly. hpc is reached only through the ndarray::simd polyfill, so the row
now times PackedI8B::pack_from, which packs into the same VNNI layout. The
measured share is unchanged (23.1 us, 39% of the gemm_i8 row at 256 fields).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* feat(dr-isa-stream-lab): G2L lab falsifier — one witnessed translation reused across GEMMs

D-DT64-G2L-1. A selection named in global ids is translated once under one
frame of the source's DR MapTable into the source's own row order (counted
lookups). The object is bound in the source's space, B is prepared once
through the translation (one map read per row), and every run reads the
source's lanes in place with zero lookups. Cross-space reads without a
translation stay refused (ADMISSION B, #1640).

One AMX VM, three runs: translate once 68-85 us (3200 lookups), prepare B
37-47 us, warm run 16-22 us with 0 lookups; re-translating per operation
128-166 us (about 8x). Six falsifiers in tests/integration/g2l.rs, four
disable runs red. Contract doc G2L row moves from OPEN to measured (lab).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* dr-isa-stream-lab: refuse a translated identity past the inner B table

TranslatedB::extent() reported the source's position range, so an identity
past the inner table passed admit_operand and packing indexed past the
table. extent() now reports the inner operand's own extent, and BValues
gains highest_row(selection), which TranslatedB overrides to resolve each
selected position to the identity it reads. admit_operand then refuses
with ShapeRefusal::OperandShape before any packing (#1990's contract).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* dr-isa-stream-lab: report G2L costs one by one

The G2L bench now reports separately: G2L lookups and translation time;
admission and packing map reads during B preparation; B bytes packed and
preparation time; A staging bytes and time per warm run; GEMM-only time;
and the complete warm run. GEMM alone is 0.71-0.86 us; staging the sparse
selection into a padded A is 11-14 us of a 20-24 us warm run, so zero
lookups is not zero data movement. BENCH-SHAPE, the board entry and the
contract doc record that K order changes under translation and is
validated only for exact integer GEMM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* board: regenerate entries index after merging main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

* dr-isa-stream-lab: refuse a translation made on another source

Two sources built in the same order have equal coordinate digests, so
Translation::check admitted a translation from the other one and packing
then panicked reading a table with a frame it never issued (Codex, #1994).
check now asks the source's own map table whether it issued the
translation's frame, and refuses with G2lRefusal::Foreign before packing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMMWgnUU9g7Ldyn6sbk

---------

Co-authored-by: Claude <noreply@anthropic.com>
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