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
35 changes: 35 additions & 0 deletions .claude/board/entries/2026-11-10-dt64-gemm-shape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 2026-11-10 — DT64-shaped 64×64 and 256×256 BF16 objects (D-DT64-GEMM-SHAPE-1/2)

**Status:** MEASURED (lab, not production admission). Crate:
`crates/dr-isa-stream-lab` (`src/shape.rs`, `src/bin/shape.rs`,
`tests/integration/shape.rs`, `BENCH-SHAPE.md`).

**Question.** Can DT64 turn source-owned lanes into the exact logical shapes
AMX consumes (64×64, 256×256), paying physical layout costs only where
unavoidable?

**Answer.** Yes for region-shaped WHERE results; staging otherwise.
**Decision: MIXED.**
- Direct for a region over a block-padded slab: 0 bytes copied, 0 allocations.
- Staged for scattered masks, interior tails, and permuted or scattered lanes.
- B is always prepared once and reused under a selection/frame/revision/width
key.
- ndarray CBLAS BF16 is 7–11× slower and is not a consumer for this shape.

**Measured (AMX VM, ±35% between runs):** at 256×256 direct takes 146–178 µs,
staged 140–155 µs (inseparable), B preparation 149–181 µs, and a single-check
resolve 14 µs. A per-field `LaneBinding::lane` resolve takes 155 µs
(quadratic). 256 demanded fields bind directly under
`Extent::DR256_SQ_X64`, with no DT64 change.

**Open:**
- `LaneBinding` has no borrow-all-after-one-check method; the lab works
around it with `check` plus `addr` plus `LaneSource::borrow`.
- Whether the 2^k slab pitch costs the direct read: odd-pitch runs were
10–20% faster, inside the noise.
- #1984 is stranded on `ccr-8062bcc7-l7lkz9-vcsr` (merged into an
already-merged parent).

**Fruit:** a `LaneBinding::borrow_all` (one check, N borrows) in
lance-graph-dt64 would remove the quadratic resolve; it needs its own
DT64 PR.
3 changes: 2 additions & 1 deletion .claude/board/entries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ 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.

587 entries, 2026-08-06 .. 2026-11-08.
588 entries, 2026-08-06 .. 2026-11-10.

| date | entry id | finding | file |
|---|---|---|---|
| 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) |
| 2026-11-07 | `D-DT64-7-L5a` | | [2026-11-07-dt64-l5a-exact-basis-witness.md](2026-11-07-dt64-l5a-exact-basis-witness.md) |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dr-isa-stream-lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ jobs:
run: cargo test --release --manifest-path crates/dr-isa-stream-lab/Cargo.toml -- --nocapture
- name: stage costs (every timed result is checked against the oracle)
run: cargo run --release --manifest-path crates/dr-isa-stream-lab/Cargo.toml --bin bench
- name: virtual-shape costs, 64x64 and 256x256 (every arm checked against the oracle)
run: cargo run --release --manifest-path crates/dr-isa-stream-lab/Cargo.toml --bin shape
167 changes: 167 additions & 0 deletions crates/dr-isa-stream-lab/BENCH-SHAPE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# dr-isa-stream-lab: DT64-shaped 64×64 and 256×256 BF16 objects

D-DT64-GEMM-SHAPE-1 (64×64) and -2 (256×256). Generated by
`cargo run --release --bin shape`; raw output of three runs is in
`results/shape-2026-11-10-run{1,2,3}.txt`. Before timing and again after the
timed runs, every arm is checked against the scalar oracle. Allocations and
peak temporary bytes come from a counting global allocator.

**Host.** Intel Xeon @ 2.10 GHz VM (AMX-BF16, AVX-512-BF16), 4 vCPU,
L1d 48 KiB, L2 2 MiB, L3 260 MiB (as reported by the guest). Tile tier
`AMX TDPBF16PS`, single-threaded, rustc 1.99.0. The numbers are not from
dedicated silicon. They moved by up to about 35% between runs with the guest
idle, so differences under that size are not findings.

## Shape

```
universe (65,536 identities x F property lanes, source-owned slab)
-> WHERE (region or scattered mask, in the lanes' coordinate space)
-> VirtualObject: LaneBinding(F fields) + selection + N columns (addresses only)
-> BF16 tiles: rows = fields, K = selected identities, cols = B columns
-> GEMM: C[F x N] FP32
```

| | 64×64 | 256×256 |
|---|---|---|
| Rows (demanded fields) | 64 | 256 |
| K (selected identities) | 64 → 2 steps of 32 | 256 → 8 steps of 32 |
| Output tiles 16×16 | 16 | 256 |
| K=32 dot-product steps (logical) | 32 | 2,048 |
| One BF16 operand | 8 KiB | 128 KiB |
| FP32 C | 16 KiB | 256 KiB |

At 256, the shape is 256 fields × 256 columns over 256 selected identities.
It is not an identity × identity adjacency matrix. The 256 fields bind
directly under `Extent::DR256_SQ_X64`, because DT64's `MAX_FIELDS` is 256, so
no composition of smaller bindings is needed and no production lane budget
changes. The lab source holds 256 lanes. That says nothing about which lanes
are resident in production (see #1973 §0).

**Logical tile geometry is not the physical operand.**
- A direct A tile is 16 consecutive slab rows at the slab pitch (65,536 bf16),
offset by the region start.
- A staged A tile is a dense 16 × K buffer.
- B is N/16 VNNI-packed K × 16 column panels.

## Results (run 1; runs 2 and 3 in `results/`)

| Metric | 64×64 | 256×256 |
|---|---|---|
| DT64 bind (cold) | 3.4 µs · 2 allocs | 8.9 µs · 6 allocs |
| Resolve: one check + all borrows (warm) | 1.8 µs · 0 allocs | 13.9 µs · 0 allocs |
| Resolve: `LaneBinding::lane` per field | 15.2 µs | 155.1 µs |
| B preparation (VNNI panels) | 13.2 µs · 8,320 B | 148.7 µs · 131,584 B |
| Direct AMX (A in place) | 5.9 µs · 0 allocs · 0 B | 145.6 µs · 0 allocs · 0 B |
| Direct AMX, pitch 65,568 | 3.9 µs | 127.0 µs |
| Staged AMX (dense A tiles) | 4.5 µs · 2,048 B scratch | 139.7 µs · 8,192 B scratch |
| ndarray CBLAS BF16 | 37.8 µs · 23 allocs · 54 KiB | 1,063 µs · 263 allocs · 785 KiB |
| Source bytes copied (direct / staged / CBLAS) | 0 / 8,192 / 8,192 | 0 / 131,072 / 131,072 |
| CBLAS B materialized row-major | 8,192 B | 131,072 B |
| End-to-end warm (resolve + direct, B reused) | 7.2 µs | 169.6 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 25.9 µs | 368.4 µs |
| Warm repetitions (100 runs, one prepare) | 7.4 µs / run | 168.0 µs / run |

Run-to-run ranges over the three runs:

| Arm | 64×64 | 256×256 |
|---|---|---|
| Direct | 4.0–5.9 µs | 146–178 µs |
| Staged | 4.1–4.9 µs | 140–155 µs |
| Warm end-to-end | 6.7–7.2 µs | 170–197 µs |

The staged arm's one allocation is its scratch buffer on first use. A caller
that keeps the buffer, as the timed loop does, allocates nothing.

**Sparse demand** (256 fields × 256 columns, 40 scattered identities, mask
WHERE):
- logical selection: 40
- K padded to 64, so 512 dense dot-product steps: the padding is multiplied
- lanes borrowed: 256 (descriptors, not bytes)
- A bytes copied: 20,480 (only the selected values)
- staged AMX: 392–557 µs over five runs, slower than the dense 256-identity region. Each
value is gathered by a bit walk; the arithmetic is not the cost.

A sparse selection does not give sparse arithmetic here. It compacts K, then
pays for the gather.

## Findings

1. **The shape routes; DT64 stores nothing.** At both sizes one binding with
one check yields every lane, with no allocation. A direct read copies 0
source bytes. Resolve borrows exactly one lane per field, whatever the
universe size (tested at 256 and 65,536). No global G2L is used.
2. **Direct and staged are not separable by time on this host.** Copying A
costs 8 KiB or 128 KiB, and at these sizes that is hidden in the tile
loads; the two arms overlap within run-to-run noise. Direct's advantage
is structural: zero copy, zero allocation, zero scratch. It is not a speed
claim.
3. **The power-of-two pitch probably costs a little.** With a 65,568-wide
pitch instead of 65,536, the direct read was 10–20% faster at 256 in every
run. That is consistent with the 16 A rows (128 KiB apart) sharing L1
sets. It is inside the noise band, so it is a hypothesis to test on
dedicated silicon, not a finding.
4. **Preparing B is the price at 256.** Packing B costs about as much as the
GEMM (149 µs vs 146 µs). Reusing the prepared B halves end-to-end time
(cold 368 µs vs warm 170 µs). The reuse is keyed to the selection, the
frame issue, the B revision and the width, and is refused when any of
them changes. Tests show that using a stale B gives a wrong answer.
5. **Resolve with a check per field is quadratic.** `LaneBinding::lane`
re-checks every bound lane on each call: 155 µs at 256 fields, against
14 µs for one check plus borrows. At 256 the single check is still about
8% of warm end-to-end time.
6. **Scaling 16 → 256 tiles is sensible.** MACs grow 64× (fields, columns
and K each grow 4×). Direct time grew 25–44×, so throughput rose from
about 45–70 to 95–130 GMAC/s. B preparation grew 11–20× for 16× the
bytes. At 256, arithmetic and preparation are about equal, and the
single check is the third cost.
7. **ndarray CBLAS BF16 is 7–11× slower than either tile arm.** It makes 263
allocations and 785 KiB of temporaries at 256: it packs both operands and
re-packs B per 16×16 tile. #1984 measured about 20× on its whole-lane
workload.

## Refusals (all tested)

Each refusal is tested two-sided where a bypass is constructible, with the
wrong answer shown:
- **Direct:** a scattered mask (`NotARegion`); separately allocated lanes;
permuted rows; a pitch without block padding.
- **Tails:**
- At the end of the universe, tails of 63 and 65 read the slab's zeroed
padding and are exact.
- In the middle of the universe they are refused (`OverRead`). Without
that refusal, a NaN in the next identity poisons the tile, even though
B's padding row is zero.
- **Orientation:**
- A square transposed slab declared in the identity row order reads wrong.
- The same slab declared in its true row order is refused at bind.
- **Binding:** a cross-space selection; a stale frame; a foreign frame; the
wrong reader scope; a changed field mapping; a different schema basis.
- **Prepared B:** a different selection, frame issue, B revision or width.

Disable runs: removing the over-read guard, the selection witness in the B
reuse key, or the binding check in resolve each fail the matching tests.

**Error policy.** BF16-exact integer fixtures must match exactly across all
four arms (accumulation stays below 2^24). For inputs rounded to bf16 on
purpose, the bounds are:
- between arms: `2 × K × 2^-24 × Σ|a·b|` (FP32 accumulation order);
- against the unrounded f64 answer: an additional `2^-8 × Σ|a·b|` (bf16
round-to-nearest on A; B is exact).

## Relation to #1984

#1984 ("Virtual CSR over the DR cube…") was merged into the branch of #1983
after #1983 had itself merged, so its commits (`1f47c03e9`, `edbf2fa44`,
`d563af107`) never reached `main`. They survive on
`ccr-8062bcc7-l7lkz9-vcsr`. This PR neither cherry-picks nor rewrites them;
its benchmark is preserved there unchanged. Its reference numbers come from
a different workload, so no speed-up is claimed across the two:

| #1984 workload | Result |
|---|---|
| WHERE 16×16 over 65,536 identities | direct AMX 172.5 µs, ndarray CBLAS 3,397.3 µs |
| Degree-8 graph | CSR 11.6 ms, AMX 32.3 ms |
| Degree-64 local graph | staged AMX 12.5 ms, CSR 75 ms |

Its graph conclusions stay separate from these matrix-shaping conclusions.
22 changes: 22 additions & 0 deletions crates/dr-isa-stream-lab/results/shape-2026-11-10-run1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 410.6 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3362 ns · 2 allocs | 8912 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1848 ns · 0 allocs · 0 B | 13.9 µs · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 15.2 µs | 155.1 µs |
| B preparation (VNNI panels) | 13.2 µs · 8192 B written · 8320 B alloc | 148.7 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 5911 ns · 44.3 GMAC/s · 0 allocs · 0 B tmp | 145.6 µs · 115.3 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3945 ns · 66.4 GMAC/s | 127.0 µs · 132.1 GMAC/s |
| Staged AMX (dense A tiles) | 4472 ns · 1 allocs · 2048 B tmp | 139.7 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 37.8 µs · 23 allocs · 54272 B tmp | 1063.2 µ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) | 7174 ns | 169.6 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 25.9 µs | 368.4 µs |
| Warm repetitions (100, per run, one prepare) | 7413 ns | 168.0 µs |
22 changes: 22 additions & 0 deletions crates/dr-isa-stream-lab/results/shape-2026-11-10-run2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 465.2 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3180 ns · 2 allocs | 8803 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1607 ns · 0 allocs · 0 B | 13.9 µs · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 10.8 µs | 151.5 µs |
| B preparation (VNNI panels) | 9532 ns · 8192 B written · 8320 B alloc | 171.0 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 4134 ns · 63.4 GMAC/s · 0 allocs · 0 B tmp | 177.7 µs · 94.4 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3659 ns · 71.6 GMAC/s | 148.4 µs · 113.0 GMAC/s |
| Staged AMX (dense A tiles) | 4897 ns · 1 allocs · 2048 B tmp | 155.3 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 38.4 µs · 23 allocs · 54272 B tmp | 1628.7 µ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) | 6872 ns | 196.6 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 22.5 µs | 480.5 µs |
| Warm repetitions (100, per run, one prepare) | 6958 ns | 174.9 µs |
22 changes: 22 additions & 0 deletions crates/dr-isa-stream-lab/results/shape-2026-11-10-run3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 392.4 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3190 ns · 2 allocs | 8868 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1474 ns · 0 allocs · 0 B | 13.8 µs · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 10.4 µs | 195.5 µs |
| B preparation (VNNI panels) | 8921 ns · 8192 B written · 8320 B alloc | 181.1 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 4038 ns · 64.9 GMAC/s · 0 allocs · 0 B tmp | 158.3 µs · 106.0 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 4394 ns · 59.7 GMAC/s | 136.3 µs · 123.1 GMAC/s |
| Staged AMX (dense A tiles) | 4102 ns · 1 allocs · 2048 B tmp | 146.4 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 38.4 µs · 23 allocs · 54272 B tmp | 1102.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) | 6665 ns | 172.7 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 29.1 µs | 399.6 µs |
| Warm repetitions (100, per run, one prepare) | 8035 ns | 203.7 µs |
Loading
Loading