Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .claude/board/entries/2026-11-10-dt64-int8-facet-stride.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 2026-11-10 — INT8 over the DT64 virtual object; FACET STRIDE audit

**Status:** MEASURED (lab). `crates/dr-isa-stream-lab/src/int8.rs`,
`BENCH-SHAPE.md` § SHAPE-3.

**INT8 arm.** `u8 × i8 → i32` through `backend::gemm_i8` (AMX TDPBUSD). A is
unsigned and B signed, with no reinterpreting cast (a test pins it). The
results satisfy `C_int8 = C_bf16 + 8·colsum(B)` exactly.

**At 256 fields:**

| | INT8 | BF16 |
|---|---|---|
| Warm end-to-end | 85–101 µs | 144–160 µs |
| GEMM | 216–228 GMAC/s | 110–113 GMAC/s |

**Correction.** #1987's "B preparation" timed the synthetic hash. Read from a
table, prepared B costs 46–62 µs (not 149–181 µs).

**Audit verdicts:**

| Operation | Verdict |
|---|---|
| Positional reading (BF16) | REUSED |
| DT64 routing | REUSED |
| AMX accumulation | REUSED |
| LUT / masked fold | NOT APPLICABLE |
| VNNI packing | NOT APPLICABLE (mandatory) |

**OPTIMIZATION FOUND (lab-local):**
- region A copy: 3.5–6× faster;
- in-place B: 30 ns instead of 58 µs.

**Open:** ndarray has no strided-A INT8 entry and no prepacked INT8 B (the
twins of #414 / `PackedBf16B`), so INT8 copies A and re-packs B on every
call. Measured apart: the pack is 23–29 µs (36–38% of the INT8 GEMM) and the
A copy 5–7 µs, together about 30–45% of INT8 warm time. A separate ndarray
PR is proposed.

**Prepared-B reuse** is keyed on object identity, full selection equality,
frame issue, width and operand identity (seed or table instance, plus
revision). There is no digest.
3 changes: 2 additions & 1 deletion .claude/board/entries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ index row, (3) no duplicate entry id. Checks 1 and 2 are deliberately
opposite directions; the stranding this convention prevents shows up in
exactly one of them, never both.

590 entries, 2026-08-06 .. 2026-11-10.
591 entries, 2026-08-06 .. 2026-11-10.

| date | entry id | finding | file |
|---|---|---|---|
| 2026-11-10 | `lab-resolve-borrow-all` | | [2026-11-10-lab-resolve-borrow-all.md](2026-11-10-lab-resolve-borrow-all.md) |
| 2026-11-10 | `dt64-lane-borrow-all` | | [2026-11-10-dt64-lane-borrow-all.md](2026-11-10-dt64-lane-borrow-all.md) |
| 2026-11-10 | `dt64-int8-facet-stride` | | [2026-11-10-dt64-int8-facet-stride.md](2026-11-10-dt64-int8-facet-stride.md) |
| 2026-11-10 | `D-DT64-GEMM-SHAPE-1` | | [2026-11-10-dt64-gemm-shape.md](2026-11-10-dt64-gemm-shape.md) |
| 2026-11-08 | `dr-isa-stream-lab` | | [2026-11-08-dr-isa-stream-lab.md](2026-11-08-dr-isa-stream-lab.md) |
| 2026-11-07 | `D-DT64-7-L5b` | | [2026-11-07-dt64-l5b-historical-basis.md](2026-11-07-dt64-l5b-historical-basis.md) |
Expand Down
2 changes: 1 addition & 1 deletion .claude/knowledge/dr-dt64-locality-execution-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ field mapping, operand identity and version.
| #1987 — BF16 virtual 64×64 and 256×256 objects over source-owned lanes | MEASURED, merged | One binding feeds direct strided AMX (0 bytes of A copied), staged, CBLAS and oracle arms with exact parity; refusals for frame, scope, mapping, basis, coordinate space, foreign lanes and out-of-range selections |
| #1988 — `LaneBinding::borrow_all` | VERIFIED-IN-CODE, merged | One check, then every bound lane; N source lookups instead of N² |
| Lab resolve on `borrow_all` (follow-up) | MEASURED, not merged | Resolve at 256 fields 1.6–2.0 µs vs 13.8–13.9 µs (#1987 as first measured) and 26–28 µs (`main` after the provenance fix); the old cost was `LaneBinding::addr`, a linear scan called per field |
| INT8 vs BF16 over the same object (follow-up) | MEASURED, not merged | `u8 × i8 → i32` end to end 85–101 µs vs BF16 144–160 µs at 256 fields on one VM; INT8 still copies A and re-packs B per call (no strided-A / prepacked-B INT8 entry in ndarray) |
| INT8 vs BF16 over the same object (follow-up) | MEASURED, not merged | `u8 × i8 → i32` end to end 66–101 µs vs BF16 103–160 µs at 256 fields on one VM; INT8 still copies A (5–7 µs) and re-packs B per call (23–29 µs, 36–38% of its GEMM), because ndarray has no strided-A / prepacked-B INT8 entry |
| #1987's "B preparation ≈ GEMM" | REJECTED-BY-MEASUREMENT | That timer included the synthetic operand's hash; from a table built once, prepared B costs about a third of the GEMM |
| G2L across different source orders | OPEN | Not demonstrated: every fixture shared one coordinate space, and differing spaces were refused, not translated |
| Foundry operational-ontology parity | HYPOTHESIS | Research goal; nothing here establishes it |
Expand Down
94 changes: 94 additions & 0 deletions crates/dr-isa-stream-lab/BENCH-SHAPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,97 @@ Disable runs, each with the code restored afterwards:
| Swallowing item refusals | the `Vanished` test |
| The object-identity check | `lanes_from_another_object_are_refused_by_every_arm` |
| Placing lanes in binding order instead of view order | the row-order test |

## D-DT64-GEMM-SHAPE-3: INT8 (u8 × i8 → i32) and the FACET STRIDE audit

`src/int8.rs` puts the same `VirtualObject` over u8 lanes and runs it as
`u8 × i8 → i32` through ndarray's INT8 facade: `backend::gemm_i8` →
`simd_int_ops::gemm_u8_i8` → AMX `TDPBUSD`. A stays unsigned and B signed,
which is TDPBUSD's native contract; there is no reinterpreting cast, and
`a_is_never_reinterpreted_as_signed` pins it (200 × −1 must give −200·K, not
+56·K). The INT8 and BF16 arms share one fixture. With `A_u8 = A + 8`, the
results satisfy `C_int8 = C_bf16 + 8·colsum(B)` exactly, and a test checks
this.

### A measurement correction to the results above

The earlier "B preparation" rows (149–181 µs at 256 fields) timed
`BOperand::value`, a hash computed per element, not data movement. The
benchmark now reads B from a `BTable` built once. Prepared VNNI B then costs
**46–62 µs** at 256 fields, about a third of the GEMM, not about equal to it.
Finding 4 above overstated preparation by about 3×.

### Results (256 fields, six runs on one host, `results/shape-2026-11-10-int8-run*.txt` holds the last three)

Same host, same fixture and same B table for every row. Ranges are across
runs. The VM's run-to-run variation is up to about 35%, so differences inside
that band are not findings.

| Step | BF16 | INT8 |
|---|---|---|
| Resolve (borrow_all) | 2.0–2.5 µs | 2.0–2.8 µs |
| Stage A | 0 B (direct) | 6–10 µs · 64 KiB (one copy per lane) |
| Stage A, per-value walk (baseline) | — | 36–56 µs |
| B | prepared once: 46–62 µs, then reused | in place for a region: 30 ns, 0 B; materialized: 58 µs |
| GEMM | 138–152 µs direct (110–122 GMAC/s) | 61–82 µs (204–275 GMAC/s), B VNNI-packed inside every call, 3 allocs · 12 KiB |
| of which: B band gather + VNNI pack, timed apart with ndarray's own `vnni_pack_i8` | — | 23–29 µs (36–38% of the GEMM; 54% at 64 fields) |
| Warm end-to-end | 103–160 µs | 66–101 µs |

At 64 fields, warm end-to-end is 6.5–6.7 µs (BF16) and 6.0–10.8 µs (INT8).

### FACET STRIDE audit

The six operations are separate, and each gets its own verdict.

| Operation | Where | Verdict |
|---|---|---|
| 1. Positional source-lane reading | BF16 `direct` reads 16 slab rows in place at the slab pitch; INT8 must copy A because ndarray's INT8 facade takes dense A only | **REUSED** for BF16 (the pattern, not `simd_stride` code). INT8 stays a copy until ndarray gains a strided-A INT8 entry |
| 2. LUT transformation (`lut_u8`, `lut9`) | no byte transform anywhere in these pipelines; `simd_stride` has no GEMM callers in ndarray | **NOT APPLICABLE** |
| 3. Masked folding / reduction | GEMM arms do none; a scattered WHERE mask is compacted by a per-bit walk when A is staged | **NOT APPLICABLE** to the GEMM. The compaction is a candidate for a masking-ops compress; not measured here |
| 4. DT64 coordinate / shape routing | `borrow_all`, one check, O(N) | **REUSED.** The O(N²) `addr` walk is gone (see the borrow_all section) |
| 5. VNNI operand packing | `vnni_pack_bf16` / `vnni_pack_i8` are plain index moves, no shuffles | **NOT APPLICABLE:** required by the hardware. But INT8 re-packs B inside every call because there is no `PackedI8B`; that is repeated work, not a layout problem |
| 6. AMX dot-product accumulation | TDPBF16PS / TDPBUSD through the facade | **REUSED** |

**Prepared-B reuse key.** Reuse is keyed on authoritative identity, never on a
digest:
- the object that was packed for (one compare);
- for any other object, the selection compared in full, the frame issue and
the width;
- the operand's identity: the defining function's seed, or the immutable
table's construction instance, plus the revision.

The earlier FNV selection key is gone. Two tables with equal values and an
equal revision are different operands. Tests: `prepared_b_reuse_is_keyed_by_identity_not_a_digest`,
`prepared_b_is_reused_and_invalidated`.

**OPTIMIZATION FOUND** (measured, lab-local, no semantic change):
- **Copy A per lane.** A region of A is now one copy per lane instead of a
per-value walk: 3.5–6× faster at 256 fields.
- **Borrow B in place.** For a full-width region, B comes straight from the
table: 30 ns instead of 58 µs, and 0 bytes written.
- **Resolve with `borrow_all`.** Single-check resolution is 7× faster than
#1987's original.

**Not proposed: an ndarray change.** A strided-A INT8 entry plus a prepacked
INT8 B, the INT8 twins of #414 and `PackedBf16B`, would save at most:
- the A copy, 6–10 µs, about 10% of INT8 end-to-end;
- the per-call B pack inside `gemm_i8`, which the facade does not expose and
so was not measured on its own.

Measured: the per-call B band gather plus pack inside `gemm_i8` is 23–29 µs
at 256 fields, 36–38% of the INT8 GEMM, and the A copy is 5–7 µs. Together
that is about 30–45% of INT8 warm end-to-end time. This is an independently
measured case for a separate ndarray PR. It is proposed, not part of this
change.

**Central question.** DT64 is routing SoA positions, not moving them. Four
places paid for the same work twice, all found by measurement, and the first
three are now fixed:
1. per-field `addr` scans in resolve;
2. a per-value walk where a region copy would do;
3. hashing inside a "preparation" timer;
4. INT8 B re-packed on every call: measured at 36–38% of the INT8 GEMM, and
open at the ndarray layer.

The FACET STRIDE guard (`facet-stride-guard.sh --diff`) reports 0 hits on
this change. ndarray is unchanged.
30 changes: 30 additions & 0 deletions crates/dr-isa-stream-lab/results/shape-2026-11-10-int8-run1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Host: Intel(R) Xeon(R) Processor @ 2.10GHz; 4 logical CPUs; cache (cpu0): L1 Data 48K, L1 Instruction 32K, L2 Unified 2048K, L3 Unified 266240K
Tile tier: AMX TDPBF16PS. Single-threaded. 41 warm runs per row (median).

Sparse demand (256 fields x 256 cols, 40 scattered identities): logical selection 40 · K padded 64 · lanes borrowed 256 · A bytes copied 20480 · dense dot-product steps 512 · staged AMX 375.1 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3183 ns · 2 allocs | 8873 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1248 ns · 0 allocs · 0 B | 2045 ns · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 13.7 µs | 151.5 µs |
| B preparation (VNNI panels) | 4044 ns · 8192 B written · 8320 B alloc | 45.0 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 5888 ns · 44.5 GMAC/s · 0 allocs · 0 B tmp | 137.9 µs · 121.7 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3802 ns · 68.9 GMAC/s | 124.8 µs · 134.5 GMAC/s |
| Staged AMX (dense A tiles) | 4140 ns · 1 allocs · 2048 B tmp | 83.4 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 32.4 µs · 23 allocs · 54272 B tmp | 939.9 µs · 263 allocs · 803840 B tmp |
| Source bytes copied (direct / staged / CBLAS) | 0 / 8192 / 8192 | 0 / 131072 / 131072 |
| CBLAS B materialized | 8192 B | 131072 B |
| FP32 accumulator (C) | 16384 B | 262144 B |
| End-to-end warm (resolve + direct, B reused) | 6531 ns | 140.5 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 13.7 µs | 213.2 µs |
| Warm repetitions (100, per run, one prepare) | 7340 ns | 154.3 µs |
| INT8 resolve (u8 lanes, one check) | 1220 ns | 1933 ns |
| INT8 stage A (region: one copy per lane) | 289 ns · 4096 B | 7078 ns · 65536 B |
| INT8 stage A, per-value walk (baseline) | 3574 ns | 42.9 µs |
| INT8 B for a region, in place from the table | 30 ns · 0 B written | 30 ns · 0 B written |
| INT8 materialize B (row-major i8) | 4273 ns · 4096 B | 58.0 µs · 65536 B |
| INT8 GEMM `backend::gemm_i8` (packs B per call) | 3553 ns · 73.8 GMAC/s · 3 allocs · 3072 B tmp | 77.3 µs · 217.1 GMAC/s · 3 allocs · 12288 B tmp |
| INT8 B band gather + VNNI pack (done inside each gemm_i8 call) | 1926 ns · 54% of the GEMM row | 29.4 µs · 38% of the GEMM row |
| INT8 end-to-end warm (resolve + stage + GEMM) | 10.5 µs | 87.2 µs |
30 changes: 30 additions & 0 deletions crates/dr-isa-stream-lab/results/shape-2026-11-10-int8-run2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Host: Intel(R) Xeon(R) Processor @ 2.10GHz; 4 logical CPUs; cache (cpu0): L1 Data 48K, L1 Instruction 32K, L2 Unified 2048K, L3 Unified 266240K
Tile tier: AMX TDPBF16PS. Single-threaded. 41 warm runs per row (median).

Sparse demand (256 fields x 256 cols, 40 scattered identities): logical selection 40 · K padded 64 · lanes borrowed 256 · A bytes copied 20480 · dense dot-product steps 512 · staged AMX 285.5 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3178 ns · 2 allocs | 8808 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1236 ns · 0 allocs · 0 B | 2042 ns · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 11.8 µs | 151.4 µs |
| B preparation (VNNI panels) | 3186 ns · 8192 B written · 8320 B alloc | 45.1 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 4316 ns · 60.7 GMAC/s · 0 allocs · 0 B tmp | 138.1 µs · 121.5 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3812 ns · 68.8 GMAC/s | 124.6 µs · 134.6 GMAC/s |
| Staged AMX (dense A tiles) | 4079 ns · 1 allocs · 2048 B tmp | 83.7 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 32.8 µs · 23 allocs · 54272 B tmp | 954.6 µs · 263 allocs · 803840 B tmp |
| Source bytes copied (direct / staged / CBLAS) | 0 / 8192 / 8192 | 0 / 131072 / 131072 |
| CBLAS B materialized | 8192 B | 131072 B |
| FP32 accumulator (C) | 16384 B | 262144 B |
| End-to-end warm (resolve + direct, B reused) | 6516 ns | 103.2 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 13.8 µs | 158.9 µs |
| Warm repetitions (100, per run, one prepare) | 6467 ns | 118.3 µs |
| INT8 resolve (u8 lanes, one check) | 1237 ns | 1553 ns |
| INT8 stage A (region: one copy per lane) | 310 ns · 4096 B | 5364 ns · 65536 B |
| INT8 stage A, per-value walk (baseline) | 3553 ns | 34.5 µs |
| INT8 B for a region, in place from the table | 30 ns · 0 B written | 23 ns · 0 B written |
| INT8 materialize B (row-major i8) | 4242 ns · 4096 B | 45.6 µs · 65536 B |
| INT8 GEMM `backend::gemm_i8` (packs B per call) | 3552 ns · 73.8 GMAC/s · 3 allocs · 3072 B tmp | 61.0 µs · 274.9 GMAC/s · 3 allocs · 12288 B tmp |
| INT8 B band gather + VNNI pack (done inside each gemm_i8 call) | 1927 ns · 54% of the GEMM row | 23.1 µs · 38% of the GEMM row |
| INT8 end-to-end warm (resolve + stage + GEMM) | 5909 ns | 66.3 µs |
30 changes: 30 additions & 0 deletions crates/dr-isa-stream-lab/results/shape-2026-11-10-int8-run3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Host: Intel(R) Xeon(R) Processor @ 2.10GHz; 4 logical CPUs; cache (cpu0): L1 Data 48K, L1 Instruction 32K, L2 Unified 2048K, L3 Unified 266240K
Tile tier: AMX TDPBF16PS. Single-threaded. 41 warm runs per row (median).

Sparse demand (256 fields x 256 cols, 40 scattered identities): logical selection 40 · K padded 64 · lanes borrowed 256 · A bytes copied 20480 · dense dot-product steps 512 · staged AMX 360.4 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3192 ns · 2 allocs | 9047 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1250 ns · 0 allocs · 0 B | 2028 ns · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 11.7 µs | 151.6 µs |
| B preparation (VNNI panels) | 3224 ns · 8192 B written · 8320 B alloc | 45.0 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 4479 ns · 58.5 GMAC/s · 0 allocs · 0 B tmp | 143.9 µs · 116.6 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3902 ns · 67.2 GMAC/s | 130.2 µs · 128.9 GMAC/s |
| Staged AMX (dense A tiles) | 4302 ns · 1 allocs · 2048 B tmp | 86.4 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 32.7 µs · 23 allocs · 54272 B tmp | 952.1 µs · 263 allocs · 803840 B tmp |
| Source bytes copied (direct / staged / CBLAS) | 0 / 8192 / 8192 | 0 / 131072 / 131072 |
| CBLAS B materialized | 8192 B | 131072 B |
| FP32 accumulator (C) | 16384 B | 262144 B |
| End-to-end warm (resolve + direct, B reused) | 6685 ns | 147.5 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 14.0 µs | 220.7 µs |
| Warm repetitions (100, per run, one prepare) | 6767 ns | 155.2 µs |
| INT8 resolve (u8 lanes, one check) | 1279 ns | 1996 ns |
| INT8 stage A (region: one copy per lane) | 286 ns · 4096 B | 6828 ns · 65536 B |
| INT8 stage A, per-value walk (baseline) | 3541 ns | 42.1 µs |
| INT8 B for a region, in place from the table | 30 ns · 0 B written | 30 ns · 0 B written |
| INT8 materialize B (row-major i8) | 4262 ns · 4096 B | 58.7 µs · 65536 B |
| INT8 GEMM `backend::gemm_i8` (packs B per call) | 3552 ns · 73.8 GMAC/s · 3 allocs · 3072 B tmp | 82.1 µs · 204.3 GMAC/s · 3 allocs · 12288 B tmp |
| INT8 B band gather + VNNI pack (done inside each gemm_i8 call) | 1922 ns · 54% of the GEMM row | 29.4 µs · 36% of the GEMM row |
| INT8 end-to-end warm (resolve + stage + GEMM) | 10.8 µs | 87.5 µs |
Loading
Loading