diff --git a/.claude/board/entries/2026-11-10-lab-resolve-borrow-all.md b/.claude/board/entries/2026-11-10-lab-resolve-borrow-all.md new file mode 100644 index 000000000..a51915bf1 --- /dev/null +++ b/.claude/board/entries/2026-11-10-lab-resolve-borrow-all.md @@ -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`. diff --git a/.claude/board/entries/README.md b/.claude/board/entries/README.md index 4f97a0063..54e22dc64 100644 --- a/.claude/board/entries/README.md +++ b/.claude/board/entries/README.md @@ -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) | diff --git a/.claude/knowledge/dr-dt64-locality-execution-contract.md b/.claude/knowledge/dr-dt64-locality-execution-contract.md new file mode 100644 index 000000000..4edc6b97c --- /dev/null +++ b/.claude/knowledge/dr-dt64-locality-execution-contract.md @@ -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. diff --git a/CLAUDE.md b/CLAUDE.md index 6f9d643b9..7ff6f83f3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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) diff --git a/crates/dr-isa-stream-lab/BENCH-SHAPE.md b/crates/dr-isa-stream-lab/BENCH-SHAPE.md index b55222d4b..0d0da1d08 100644 --- a/crates/dr-isa-stream-lab/BENCH-SHAPE.md +++ b/crates/dr-isa-stream-lab/BENCH-SHAPE.md @@ -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 | diff --git a/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run1.txt b/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run1.txt new file mode 100644 index 000000000..8e64a5a12 --- /dev/null +++ b/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run1.txt @@ -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 | diff --git a/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run2.txt b/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run2.txt new file mode 100644 index 000000000..88e22cec7 --- /dev/null +++ b/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run2.txt @@ -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 | diff --git a/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run3.txt b/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run3.txt new file mode 100644 index 000000000..311f0b4bc --- /dev/null +++ b/crates/dr-isa-stream-lab/results/shape-2026-11-10-borrow-all-run3.txt @@ -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 | diff --git a/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run1.txt b/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run1.txt new file mode 100644 index 000000000..f212324ae --- /dev/null +++ b/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run1.txt @@ -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 405.5 µs + +| Metric | 64×64 | 256×256 | +|---|---|---| +| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 | +| DT64 bind (cold) | 3087 ns · 2 allocs | 8302 ns · 6 allocs | +| Resolve: one check + borrows (warm) | 4018 ns · 0 allocs · 0 B | 26.4 µs · 0 allocs · 0 B | +| Resolve: `lane()` per field (warm) | 13.8 µs | 162.0 µs | +| B preparation (VNNI panels) | 9362 ns · 8192 B written · 8320 B alloc | 145.9 µs · 131072 B written · 131584 B alloc | +| Direct AMX (A in place) | 5919 ns · 44.3 GMAC/s · 0 allocs · 0 B tmp | 162.3 µs · 103.4 GMAC/s · 0 allocs · 0 B tmp | +| Direct AMX, pitch 65,568 (not 2^k) | 5268 ns · 49.8 GMAC/s | 139.7 µs · 120.1 GMAC/s | +| Staged AMX (dense A tiles) | 5629 ns · 1 allocs · 2048 B tmp | 153.1 µs · 1 allocs · 8192 B tmp | +| ndarray CBLAS BF16 | 38.5 µs · 23 allocs · 54272 B tmp | 1090.3 µ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) | 10.9 µs | 189.8 µs | +| End-to-end cold (bind + prepare + resolve + direct) | 30.6 µs | 388.1 µs | +| Warm repetitions (100, per run, one prepare) | 11.0 µs | 196.7 µs | diff --git a/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run2.txt b/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run2.txt new file mode 100644 index 000000000..a217e07fc --- /dev/null +++ b/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run2.txt @@ -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 377.5 µs + +| Metric | 64×64 | 256×256 | +|---|---|---| +| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 | +| DT64 bind (cold) | 3205 ns · 2 allocs | 8809 ns · 6 allocs | +| Resolve: one check + borrows (warm) | 4154 ns · 0 allocs · 0 B | 28.0 µs · 0 allocs · 0 B | +| Resolve: `lane()` per field (warm) | 14.2 µs | 170.1 µs | +| B preparation (VNNI panels) | 9640 ns · 8192 B written · 8320 B alloc | 150.6 µs · 131072 B written · 131584 B alloc | +| Direct AMX (A in place) | 5950 ns · 44.1 GMAC/s · 0 allocs · 0 B tmp | 172.9 µs · 97.0 GMAC/s · 0 allocs · 0 B tmp | +| Direct AMX, pitch 65,568 (not 2^k) | 5560 ns · 47.1 GMAC/s | 150.8 µs · 111.3 GMAC/s | +| Staged AMX (dense A tiles) | 5932 ns · 1 allocs · 2048 B tmp | 158.0 µs · 1 allocs · 8192 B tmp | +| ndarray CBLAS BF16 | 40.7 µs · 23 allocs · 54272 B tmp | 1078.8 µ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) | 11.4 µs | 199.4 µs | +| End-to-end cold (bind + prepare + resolve + direct) | 31.4 µs | 379.6 µs | +| Warm repetitions (100, per run, one prepare) | 11.3 µs | 211.5 µs | diff --git a/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run3.txt b/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run3.txt new file mode 100644 index 000000000..f43b0a718 --- /dev/null +++ b/crates/dr-isa-stream-lab/results/shape-2026-11-10-main-before-borrow-all-run3.txt @@ -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 375.0 µs + +| Metric | 64×64 | 256×256 | +|---|---|---| +| Output tiles / K=32 dot-product steps | 16 / 32 | 256 / 2048 | +| DT64 bind (cold) | 3002 ns · 2 allocs | 8309 ns · 6 allocs | +| Resolve: one check + borrows (warm) | 3866 ns · 0 allocs · 0 B | 26.3 µs · 0 allocs · 0 B | +| Resolve: `lane()` per field (warm) | 12.9 µs | 155.9 µs | +| B preparation (VNNI panels) | 9012 ns · 8192 B written · 8320 B alloc | 142.0 µs · 131072 B written · 131584 B alloc | +| Direct AMX (A in place) | 5596 ns · 46.8 GMAC/s · 0 allocs · 0 B tmp | 159.4 µs · 105.2 GMAC/s · 0 allocs · 0 B tmp | +| Direct AMX, pitch 65,568 (not 2^k) | 5165 ns · 50.8 GMAC/s | 142.8 µs · 117.5 GMAC/s | +| Staged AMX (dense A tiles) | 5557 ns · 1 allocs · 2048 B tmp | 151.9 µs · 1 allocs · 8192 B tmp | +| ndarray CBLAS BF16 | 54.5 µs · 23 allocs · 54272 B tmp | 1092.5 µ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) | 10.7 µs | 193.4 µs | +| End-to-end cold (bind + prepare + resolve + direct) | 25.5 µs | 371.0 µs | +| Warm repetitions (100, per run, one prepare) | 10.8 µs | 199.9 µs | diff --git a/crates/dr-isa-stream-lab/src/shape.rs b/crates/dr-isa-stream-lab/src/shape.rs index 85226b0c4..5a081c287 100644 --- a/crates/dr-isa-stream-lab/src/shape.rs +++ b/crates/dr-isa-stream-lab/src/shape.rs @@ -46,7 +46,7 @@ //! bindings or tiles. use lance_graph_dt64::dr::Frame; -use lance_graph_dt64::{CoordSpace, LaneAddr, LaneBinding, LaneRefusal, LaneSource}; +use lance_graph_dt64::{CoordSpace, LaneBinding, LaneRefusal}; use ndarray::simd::{ bf16_tile_gemm_16x16_packed, bf16_tile_gemm_16x16_packed_strided, PackedBf16B, }; @@ -224,8 +224,15 @@ pub struct VirtualObject { fields: Vec, cols: usize, selection: Selection, + /// Which bind made this object. Lanes carry it, so an arm can refuse + /// lanes another object resolved with one compare. A clone keeps it: it + /// has the same binding and the same lane addresses. + id: u64, } +/// Bind identities; only uniqueness matters. +static NEXT_OBJECT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1); + impl VirtualObject { /// Cold: bind `fields` (a multiple of 16, at most 256) through DT64 under /// the selection's row order; the view has `cols` output columns. @@ -253,6 +260,7 @@ impl VirtualObject { fields: fields.to_vec(), cols, selection, + id: NEXT_OBJECT.fetch_add(1, std::sync::atomic::Ordering::Relaxed), }) } @@ -286,8 +294,11 @@ impl VirtualObject { self.fields.len() * self.cols } - /// Warm: check the binding once against the store, view and source, then - /// borrow every demanded lane. No allocation. + /// Warm: [`LaneBinding::borrow_all`] checks the binding once against the + /// store, view and source, then hands out every bound lane in ascending + /// field order; this places them in the view's row order. Any refusal, + /// `Vanished` included, is returned before a lane is placed, so no arm + /// ever runs on a partially resolved object. No allocation. pub fn resolve<'s>( &self, world: &World, @@ -299,39 +310,28 @@ impl VirtualObject { binding: self.binding.selection(), }); } - self.binding - .check(&world.store, &world.view, socket.lanes.frames(), socket)?; - let borrow = |f: u8| -> Result, ShapeRefusal> { - let addr = self - .binding - .addr(f) - .ok_or(LaneRefusal::NotBound { field: f })?; - Ok(socket - .borrow(addr) - .ok_or(LaneRefusal::Vanished { field: f })?) - }; - let first = borrow(self.fields[0])?; + let mut by_field: [Option>; MAX_ROWS] = [None; MAX_ROWS]; + for item in + self.binding + .borrow_all(&world.store, &world.view, socket.lanes.frames(), socket)? + { + let (field, lane) = item?; + by_field[usize::from(field)] = Some(lane); + } + let lane = |f: u8| by_field[usize::from(f)].ok_or(LaneRefusal::NotBound { field: f }); + let first = lane(self.fields[0])?; let mut lanes = [first; MAX_ROWS]; for (slot, &f) in lanes.iter_mut().zip(&self.fields).skip(1) { - *slot = borrow(f)?; + *slot = lane(f)?; } Ok(self.stamp(lanes)) } - /// Lanes with their provenance: the frame issue and the address of every - /// row, as this object's binding holds them. + /// Lanes with their provenance: this object's identity and frame issue. fn stamp<'s>(&self, lanes: [SlabLane<'s>; MAX_ROWS]) -> Lanes<'s> { - let first = ( - self.fields[0], - *self.binding.addr(self.fields[0]).expect("bound"), - ); - let mut addrs = [first; MAX_ROWS]; - for (slot, &f) in addrs.iter_mut().zip(&self.fields).skip(1) { - *slot = (f, *self.binding.addr(f).expect("bound")); - } Lanes { lanes, - addrs, + object: self.id, frame: self.binding.frame().clone(), count: self.fields.len(), } @@ -341,12 +341,11 @@ impl VirtualObject { /// source, or the source has moved), another field count, or another /// lane address in any row. pub fn admit_lanes(&self, lanes: &Lanes<'_>) -> Result<(), ShapeRefusal> { - let same = lanes.count == self.fields.len() - && lanes.frame.same_issue(self.binding.frame()) - && lanes.addrs[..lanes.count] - .iter() - .zip(&self.fields) - .all(|((f, addr), &want)| *f == want && self.binding.addr(want) == Some(addr)); + // The object identity implies the lane addresses (same binding) and + // the field count; the frame is checked as well, at O(1). + let same = lanes.object == self.id + && lanes.count == self.fields.len() + && lanes.frame.same_issue(self.binding.frame()); if !same { return Err(ShapeRefusal::ForeignLanes); } @@ -384,12 +383,12 @@ impl VirtualObject { } /// The borrowed lanes of a resolved object, in view row order, with the -/// frame issue and lane addresses they were resolved under, so an arm can -/// refuse lanes that belong to another object. +/// identity of the object that resolved them and its frame issue, so an arm +/// can refuse lanes that belong to another object. #[derive(Debug, Clone)] pub struct Lanes<'s> { lanes: [SlabLane<'s>; MAX_ROWS], - addrs: [(u8, LaneAddr); MAX_ROWS], + object: u64, frame: Frame, count: usize, } diff --git a/crates/dr-isa-stream-lab/tests/integration/shape.rs b/crates/dr-isa-stream-lab/tests/integration/shape.rs index 365429557..4a726dfe8 100644 --- a/crates/dr-isa-stream-lab/tests/integration/shape.rs +++ b/crates/dr-isa-stream-lab/tests/integration/shape.rs @@ -645,3 +645,59 @@ fn a_selection_past_the_source_is_refused_by_every_arm() { let r = run(&world, &socket, dim, ok.clone()); assert_eq!(r.staged.0, want(&fx, &ok, dim)); } + +/// A lane the source no longer holds is refused by `resolve` as +/// `Vanished`, so no arm ever runs on a partially resolved object. +#[test] +fn a_vanished_lane_refuses_resolve_before_any_arm_runs() { + let dim = 64; + let fx = fx(1024, dim); + let lanes = Bf16Lanes::slab_in_order(&fx).unwrap(); + let mut socket = Socket::in_order(&lanes, dim); + socket.rows[3] = 9_999; // mapped at bind, but no such row in the slab + let world = world(dim); + let obj = VirtualObject::bind( + &world, + &socket, + &fields(dim), + dim, + Selection::region(SPACE_A, 0, 64), + ) + .unwrap(); + assert_eq!( + obj.resolve(&world, &socket).unwrap_err(), + ShapeRefusal::Lane(LaneRefusal::Vanished { field: 3 }) + ); +} + +/// Rows keep the view's field order, not the binding's ascending order: +/// fields bound in reverse give C's rows in reverse. +#[test] +fn resolve_keeps_the_view_row_order() { + let dim = 64; + let fx = fx(4096, dim); + let lanes = Bf16Lanes::slab_in_order(&fx).unwrap(); + let socket = Socket::in_order(&lanes, dim); + let world = world(dim); + let rev: Vec = (0..dim as u8).rev().collect(); + let sel = Selection::region(SPACE_A, 0, 64); + let obj = VirtualObject::bind(&world, &socket, &rev, dim, sel.clone()).unwrap(); + let l = obj.resolve(&world, &socket).unwrap(); + for (k, lane) in l.lanes().iter().enumerate() { + assert_eq!(lane.row, usize::from(rev[k]), "row {k}"); + } + let (prep, _) = PreparedB::prepare(&obj, &B); + let mut c = vec![0f32; obj.c_len()]; + staged(&obj, &l, &prep, B.rev, &mut Vec::new(), &mut c).unwrap(); + let want: Vec = oracle( + &sel, + &rev, + dim, + |i, p| f64::from(fx.value(i, p)), + |i, j| f64::from(B.value(i, j)), + ) + .iter() + .map(|&v| v as f32) + .collect(); + assert_eq!(c, want); +}