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
23 changes: 23 additions & 0 deletions .claude/board/entries/2026-11-10-lab-resolve-borrow-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 2026-11-10 — The ISA lab resolves through `LaneBinding::borrow_all`

**Status:** MEASURED (lab). `crates/dr-isa-stream-lab/src/shape.rs`.

`VirtualObject::resolve` now uses DT64's `borrow_all` (#1988) in place of a
hand-rolled check followed by `LaneBinding::addr` + `LaneSource::borrow`. Lane
provenance is the identity of the resolving object plus its frame issue,
compared in O(1).

**Measured, warm resolve at 256 fields:**

| Implementation | Time |
|---|---|
| #1987 as first measured | 13.8–13.9 µs |
| `main` after #1987's provenance fix | 26–28 µs |
| `borrow_all` (this change) | 1.6–2.0 µs |
| `lane()` per field (baseline) | 119–170 µs |

**Finding:** `LaneBinding::addr` is a linear scan. Any per-field loop over it
is O(N²), and that is where the original 14 µs came from, not from the check.

**Open:** consumers that call `addr` per field elsewhere should move to
`borrow_all`.
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.

589 entries, 2026-08-06 .. 2026-11-10.
590 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 | `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) |
Expand Down
146 changes: 146 additions & 0 deletions .claude/knowledge/dr-dt64-locality-execution-contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# DR × DT64 Locality and Execution Contract

> READ BY: any session that touches DR coordinates, DT64 bindings
> (`LaneBinding`, `ClassView`, `WideFieldMask`, `VirtualObject`), source-owned
> SoA lanes, Quack / mask-RISC lowering, or an ndarray / AMX execution path
> fed from bound lanes; every reviewer of such a PR; `layer-boundary-warden`,
> `fold-carrier-scientist`, `zero-copy-warden`, `v3-mailbox-warden`.
>
> Status: CURRENT-CONTRACT for the invariant and the five boundaries.
> The evidence section is graded per item; read the grade, not the tone.
> Linear decision: EXO-220 in P-EXO-11.
> Born 2026-11-10 from D-DT64-GEMM-SHAPE-1/2/3 (#1987, #1988 and follow-ups).

## Central invariant

**Resolve identity and location once per valid binding, execute against
source-owned ordered planes locally, and only re-resolve, re-derive or
materialize when an explicit semantic, version or hardware requirement makes
it necessary.**

The governing question for every PR:

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

The test: *changing the menu should not require rebuilding the restaurant.*

The goal is amortizing knowledge of location, not merely avoiding copies. A
zero-copy path that repeats a lookup per element or per field is still the
phone book carried into the kitchen. (Measured instance below: a zero-copy
resolve that was O(N²) because it called a linear-scan lookup per field.)

## The five boundaries

Each has one owner. A design that moves a responsibility across one of these
lines needs an explicit decision, not a convenience.

### 1. DR: witnessed coordinate and address fabric

DR says *where* a value is: positions in a coordinate space, routed through a
store whose frame, route and coordinate revisions are witnessed. It carries no
ISA, ndarray or AMX meaning.

- Global-to-local (G2L) mapping is an **optional, admitted binding
operation** used only when coordinate spaces differ. It is never a
compulsory step before each operation, and never applied to coordinates
that are already aligned.
- A lane in another row order is refused (`LaneRefusal::CoordinateSpace`),
not silently translated.
- G2L does not grant Gather. Cross-table, value-directed position reads stay
under ADMISSION B (#1640) and the Gather restrictions; a prepared map does
not admit itself.

### 2. DT64: logical shape, interpretation and versioned binding

DT64 is the menu. `ClassView`, `WideFieldMask` and a CustomObject-style
`VirtualObject` say which fields a consumer wants, in what order and shape,
and how properties and methods are interpreted. A binding (`LaneBinding`)
holds addresses only and is checked against route, frame, schema basis,
mapping, scope and coordinate space.

- Reordering or reshaping the menu changes the view, never the kitchen.
- A valid binding is reused; it is re-made only when one of its witnesses
changes.
- DT64 is not a value store and not a matrix store.

### 3. Source-owned SoA: one canonical value owner

The source owns the inventory: ordered planes in its own layout and its own
frame store. Consumers borrow lanes; they do not copy them into a parallel
object universe.

- No per-object physical copy of source-owned values.
- A copy is legitimate only as a bounded staging step for execution
(boundary 4), and it is counted.

### 4. Quack / mask-RISC / ndarray / ISA: lawful execution

Quack defines and lowers the lawful operation; mask-RISC and ndarray (through
`ndarray::simd`) execute it; the ISA does the arithmetic.

- Read operands in place when the source geometry fits the instruction
(FACET STRIDE: read positions where they sit).
- Stage only what the instruction cannot consume directly, and only the tiles
it needs.
- Hardware-required layouts (AMX VNNI packing of B) are execution
requirements, not a second canonical representation. Prepare them once and
reuse them under authoritative operand identity and version; never re-derive
them per operation without a reason.
- Typed arithmetic contracts are preserved (AMX `TDPBUSD`: unsigned u8 A,
signed i8 B; no implicit reinterpretation).

### 5. IAM: independent authorization

Authorization is its own decision, checked at the read or execution boundary.
It is **never inferred from a matching DR scope**: `Scope { id }` is a value
the binding checks for consistency, not proof that the reader may read. A
binding that type-checks does not authorize; an authorized reader still needs
a valid binding.

## What must not be introduced silently

- Another canonical identity authority.
- A per-object physical copy of source-owned data.
- A compulsory G2L conversion for already aligned coordinates.
- Repeated binding or lookup for an unchanged valid context.
- An ndarray or AMX meaning inside the DR address contract.
- Unauthorized Gather, cross-space reads or stale-frame reuse.
- Reuse of a prepared operand keyed by a hash alone. Reuse must rest on
authoritative identity and version (selection equality, frame issue,
operand identity and revision, shape), not on a digest that can collide.

Witnesses to keep: scope, coordinate space, route, source frame, schema basis,
field mapping, operand identity and version.

## Evidence (graded)

| Item | Grade | What it shows |
|---|---|---|
| #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) |
| #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 |

All timings: one VM (Xeon with AMX-BF16, 4 vCPU), single-threaded, medians of
41 warm runs, three runs per figure, ranges reported; run-to-run variation up
to about 35%. Not certified on dedicated silicon.

## Applying it in review

For each PR touching these boundaries, answer in the PR body:

1. What is resolved once per binding, and what per operation?
2. Which witnesses invalidate the reuse, and are all of them checked?
3. Which bytes are copied, and which boundary requires the copy?
4. Which claims are measured (with the command and host), and which are
hypotheses?

## Recorded

- Linear decision: [EXO-220](https://linear.app/exo-red/issue/EXO-220) in P-EXO-11.
- Source PRs: #1987 and #1988 (merged), and the two lab follow-ups that cite
this document.
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ SIBLING REPOS:
.claude/knowledge/compilation-vs-runtime-substrate.md — MANDATORY before filing a cross-repo issue or writing any seam/lowering design that pairs a consumer repo with SoA/temporal.rs/NARS/RBAC/mailbox vocabulary: contracts compile types; codegen emits into consumer repos; cargo builds them; the running engine's internals never gate a build or a typed-value construction (the door-knocking-compiler test). Born from OGAR #208 (closed hallucinated). Carried by layer-boundary-warden / codegen-flow-cartographer.
.claude/knowledge/assembler-vs-storage-substrate.md — MANDATORY before assigning responsibility across the OGAR↔lance-graph boundary or naming any "ingest" API: OGAR = the V3 assembler substrate (IR/mint/codegen); lance-graph = spine (contracts+query); Lance = calcification, never an ingest endpoint. Ownership quick-map + failure signatures from the 2026-07-14 #691/#208 chain. Carried by layer-boundary-warden / codegen-flow-cartographer.
.claude/knowledge/split-tunnel-sparse-append-resident-fold.md — PATTERN (MEASURED in a consumer): write = sparse append, one Lance version per batch, never compacted; read = fold over resident records; Lance read once, at replay. History 0.72 ms vs 336 ms scanning Lance. Read before designing any write path, history/diff read, or a hot-path Lance read
.claude/knowledge/dr-dt64-locality-execution-contract.md — CURRENT-CONTRACT: resolve identity and location once per valid binding, execute against source-owned planes locally; five boundaries (DR fabric / DT64 menu / source-owned SoA / Quack-mask-RISC-ndarray-ISA execution / IAM). Read before any DR, DT64 binding, bound-lane execution or prepared-operand reuse work; every PR answers "what is recomputed per operation that could be resolved once per binding?"
.claude/CALIBRATION_STATUS_GROUND_TRUTH.md — OVERRIDE: read BEFORE any SESSION_*.md
.claude/PLAN_BF16_DISTANCE_TABLES.md — 5-phase plan for BF16 distance tables
.claude/TECHNICAL_DEBT_SIGNED_SESSION.md — 56% useful, 44% bypass (honest review)
Expand Down
54 changes: 54 additions & 0 deletions crates/dr-isa-stream-lab/BENCH-SHAPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,57 @@ a different workload, so no speed-up is claimed across the two:
| Degree-64 local graph | staged AMX 12.5 ms, CSR 75 ms |

Its graph conclusions stay separate from these matrix-shaping conclusions.

## Resolve on `LaneBinding::borrow_all` (2026-11-10, after #1988)

`VirtualObject::resolve` now calls DT64's `LaneBinding::borrow_all`: one
binding check, then every bound lane in ascending field order, placed into the
view's row order. Any refusal, `Vanished` included, is returned before a lane
is placed, so no arm runs on a partially resolved object.

Lane provenance is now the identity of the object that resolved the lanes,
plus its frame issue. Both are compared in O(1).

The per-field `LaneBinding::lane` route is kept only as a benchmark
baseline.

Resolve, warm, medians of three runs each (raw output in `results/`):

| Implementation | 64 fields | 256 fields |
|---|---|---|
| #1987 as first measured: check, then `LaneBinding::addr` per field | 1.5–1.8 µs | 13.8–13.9 µs |
| `main` after #1987's lane-provenance fix (addresses stamped per row) | 3.9–4.2 µs | 26.3–28.0 µs |
| **`borrow_all` + object identity (this change)** | **0.97–1.2 µs** | **1.6–2.0 µs** |
| `LaneBinding::lane` per field (baseline) | 9.2–14.2 µs | 119–170 µs |

Why both earlier versions were slower:

- **#1987 as first measured was already quadratic.** `LaneBinding::addr`
scans the bound lanes linearly, and the hand-written loop called it once per
field.
- **The provenance fix made it worse.** It added a second `addr` per row in
resolve, and a third in every arm's admission check.
- **`borrow_all` removes the scan.** It walks the bound lanes once, and the
admission check compares one identity, so both are linear.

At 256 fields the check-once resolve is therefore about 7× faster than the
expected 14 µs, not merely preserved.

Warm end-to-end at 256 fields (resolve + direct AMX, B reused) fell from
190–199 µs on `main` to 104–108 µs. That figure includes the direct GEMM,
which varies run to run on this VM.

Correctness is unchanged:
- exact oracle parity for all four arms at both sizes;
- every refusal test passes;
- two new tests:
- a lane mapped at bind but missing at resolve is refused as `Vanished`;
- fields bound in reverse order give C's rows in reverse order.

Disable runs, each with the code restored afterwards:

| Disabled | Test that fails |
|---|---|
| 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 |
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 290.8 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3182 ns · 2 allocs | 7727 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1221 ns · 0 allocs · 0 B | 1920 ns · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 11.9 µs | 154.6 µs |
| B preparation (VNNI panels) | 9523 ns · 8192 B written · 8320 B alloc | 145.4 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 4476 ns · 58.6 GMAC/s · 0 allocs · 0 B tmp | 115.1 µs · 145.8 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3985 ns · 65.8 GMAC/s | 92.9 µs · 180.6 GMAC/s |
| Staged AMX (dense A tiles) | 4397 ns · 1 allocs · 2048 B tmp | 102.8 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 39.6 µs · 23 allocs · 54272 B tmp | 828.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) | 6546 ns | 107.0 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 22.0 µs | 260.0 µs |
| Warm repetitions (100, per run, one prepare) | 6683 ns | 110.5 µs |
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 317.5 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 2510 ns · 2 allocs | 6909 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 974 ns · 0 allocs · 0 B | 1622 ns · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 9177 ns | 119.4 µs |
| B preparation (VNNI panels) | 7436 ns · 8192 B written · 8320 B alloc | 116.8 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 3151 ns · 83.2 GMAC/s · 0 allocs · 0 B tmp | 102.1 µs · 164.3 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 2745 ns · 95.5 GMAC/s | 90.1 µs · 186.1 GMAC/s |
| Staged AMX (dense A tiles) | 3089 ns · 1 allocs · 2048 B tmp | 99.6 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 30.1 µs · 23 allocs · 54272 B tmp | 834.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) | 4826 ns | 104.0 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 19.7 µs | 252.2 µs |
| Warm repetitions (100, per run, one prepare) | 5228 ns | 265.0 µs |
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 545.9 µs

| Metric | 64×64 | 256×256 |
|---|---|---|
| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 |
| DT64 bind (cold) | 3088 ns · 2 allocs | 8553 ns · 6 allocs |
| Resolve: one check + borrows (warm) | 1210 ns · 0 allocs · 0 B | 2025 ns · 0 allocs · 0 B |
| Resolve: `lane()` per field (warm) | 11.5 µs | 147.4 µs |
| B preparation (VNNI panels) | 9162 ns · 8192 B written · 8320 B alloc | 147.4 µs · 131072 B written · 131584 B alloc |
| Direct AMX (A in place) | 4125 ns · 63.6 GMAC/s · 0 allocs · 0 B tmp | 139.4 µs · 120.4 GMAC/s · 0 allocs · 0 B tmp |
| Direct AMX, pitch 65,568 (not 2^k) | 3660 ns · 71.6 GMAC/s | 140.8 µs · 119.1 GMAC/s |
| Staged AMX (dense A tiles) | 4081 ns · 1 allocs · 2048 B tmp | 100.4 µs · 1 allocs · 8192 B tmp |
| ndarray CBLAS BF16 | 50.6 µs · 23 allocs · 54272 B tmp | 843.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) | 6741 ns | 107.9 µs |
| End-to-end cold (bind + prepare + resolve + direct) | 24.4 µs | 247.8 µs |
| Warm repetitions (100, per run, one prepare) | 7776 ns | 118.9 µs |
Loading
Loading