Skip to content

Commit bbca88e

Browse files
authored
Merge pull request #234 from AdaWorldAPI/claude/hevc-amortization-map
Knowledge: HEVC/H.265 amortization map onto the BF16 16×16 AMX tile substrate
2 parents 071d40a + af72945 commit bbca88e

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# HEVC / H.265 amortization map — onto the BF16 16×16 AMX tile substrate
2+
3+
> READ BY: cognitive-architect, savant-architect, amx-savant, truth-architect,
4+
> l3-strategist, product-engineer
5+
>
6+
> Status ledger. Every row is tagged **[MEASURED #PR]** (probe run) /
7+
> **[SHIPPED]** (code exists + tested, not yet wired into the codec pipeline) /
8+
> **[MECHANISM — unmeasured, probe named]** / **[PARTIAL]** / **[DOESN'T FIT]**.
9+
> No unmarked conjecture. Companion to
10+
> `.claude/knowledge/pr-x12-codec-cognitive-substrate-mapping.md` (the E-7/H-7
11+
> plan this measures against).
12+
13+
## The thesis (operator, 2026-07-04)
14+
15+
> Use the BF16 16×16 AMX GEMM / blasgraph neighborhood / Morton-tile pyramid /
16+
> perturbation-shader cascade (+ AMX masking or other algorithms for certain
17+
> stages) **to amortize H.265 / HEVC.**
18+
19+
Amortize = the codec's per-block marginal cost collapses to **a gather (bit
20+
shift) + one 16×16 BF16 AMX tile op** (`hpc::bf16_tile_gemm::bf16_tile_gemm_16x16`
21+
`TDPBF16PS`), routed over a Morton/HHTL tile pyramid whose codebooks/bases are
22+
**deterministic and built once** (the helix "template is free, regenerable —
23+
only the endpoint costs" principle), then reused across every block and every
24+
frame. One tile machine + one pyramid + one place/residue codec, not N bespoke
25+
HEVC kernels.
26+
27+
## The one primitive, three layers
28+
29+
| layer | what it is | shipped in |
30+
|---|---|---|
31+
| **address (bit shift)** | integer motion / tile position / CTU quad-tree = pure addressing, zero arithmetic (`VPGATHERDD`) | `hpc::cascade` (Morton), blasgraph `heel_hip_twig_leaf` / `clam_neighborhood` (lance-graph) |
32+
| **couple (tile op)** | a 16×16 BF16 GEMM `C = A·B` = one `TDPBF16PS` — every linear field coupling / transform / covariance projection | `hpc::bf16_tile_gemm::bf16_tile_gemm_16x16`, `hpc::splat3d::spd3::sandwich_x16` |
33+
| **code (place/residue)** | deterministic pyramid PLACE (free) + coded RESIDUE magnitude; the perturbation phase IS the Walsh–Hadamard sign transform of the address tree | `hpc::splat3d::helix_orient`, `crates/helix` (lance-graph), OGAR `guid-prefix-shape-routing.md §4b` |
34+
| **entropy (palette pack)** | small-alphabet indices → variable-width SIMD bit-pack (VPSHUFB, 16 idx/cycle) — the parallel entropy layer that replaces serial CABAC | `ndarray::palette_codec` / `nibble` / `byte_scan` (Pumpkin/Minecraft port; 28+23+18 tests) |
35+
36+
The perturbation-shader cascade and the codec transform are **the same object**:
37+
OGAR canon states "the perturbation pyramid becomes the Walsh–Hadamard transform
38+
of the address tree" (`OGAR/CLAUDE.md`, Bipolar-phase pyramid), and PR #232
39+
measured WHT (the ±1 add/subtract sign transform) as the codec transform,
40+
matching the DCT within 2%. Same ±1 sign butterfly, two names.
41+
42+
## HEVC stage → substrate primitive
43+
44+
| HEVC stage | reduces to | status |
45+
|---|---|---|
46+
| **Motion estimation** (block match / SAD→SSD) | `A·B` middle term of SSD = i8/bf16 GEMM | **[MEASURED #230]** — ME argmin == direct SSD, 256/256, via `int8_gemm_i32` |
47+
| **Motion compensation** (integer-pel) | gather at MV offset + residual add | **[MEASURED #230]** — bit-exact `recon = shifted_ref + residual` |
48+
| **Inverse transform** (integer DCT/DST 4–32) | separable `M·X` = tile GEMM; WHT (sign-only) suffices | **[MEASURED #232]** — WHT tracks DCT ≤2%; transform is a *no-op* when motion whitens the residual (dct/dir → 1) |
49+
| **Intra prediction** (planar/DC/33 angular) | directional extrapolation from neighbors = linear field op = tile GEMM; the angle is a helix direction code | **[MEASURED shape #233]** — field coupling `Xᵀ·X` / `Mᵀ·Σ·M` = tile op @ 0.1–0.4% Frobenius. Full intra-mode probe: **unmeasured** |
50+
| **Sub-pel interpolation** (8-tap luma / 4-tap chroma) | separable FIR = small GEMM per block = tile op | **[MECHANISM — unmeasured]** probe: `subpel_tap_tile` (8-tap separable == `bf16_tile_gemm_16x16`, bit-close to the reference filter) |
51+
| **Reference-sample smoothing / covariance** | Gaussian/covariance projection = the EWA sandwich | **[MEASURED #233]**`sandwich_x16` shape @ 0.4% |
52+
| **CTU quad-tree partition** (64→32→16→8) | Morton/HHTL tier cascade = the address pyramid | **[MECHANISM — shipped]** `hpc::cascade`, blasgraph HHTL; codec `Ctu` quad-tree. Routing-parity probe unmeasured |
53+
| **Deblocking + SAO** (in-loop filters) | conditional edge filter + offset LUT — clip/branch-heavy, *not pure GEMM* | **[PARTIAL — AMX masking]** the operator's "AMX masking": the filter is a masked tile op (predicated add), SAO is a gather-LUT. Fits with masking, not plain GEMM. Unmeasured |
54+
| **Entropy — palette-pack module** (parallel, small-alphabet) | small alphabet (≤256 basin/centroid indices) → **variable-width SIMD palette pack** (VPSHUFB, 16 idx/cycle) | **[SHIPPED module / PROPOSED codec wiring]** `ndarray::palette_codec` (Pumpkin/Minecraft port, 28 tests): `pack_indices_simd`/`unpack_indices_simd` bit-exact all 1–8 widths; `transcode` = per-block bit-width; `nibble`+`byte_scan` complete the byte layer. **Not yet wired as the codec's entropy stage** — the shipped codec (`hpc::codec::ans`) currently does static per-block rANS over the 4 `CellMode` tags. Using palette-index packing *as* the codec's entropy layer is the proposed change. |
55+
| **CABAC entropy** (context-adaptive binary arithmetic — `.265` compat only) | serial, bit-level, data-dependent arithmetic coding | **[DOESN'T FIT — and the substrate can route around it]** CABAC is a serial dependency chain, not a GEMM; AMX/tiles do not help. It is required ONLY to decode an *existing* `.265` bitstream (the M2 serial front-end). The substrate quantises to a small palette, so its entropy need is met by the SIMD-parallel palette-pack row above (SHIPPED module; PROPOSED as the codec's stage) — with, at most, a light static-rANS pass over the packed indices for the last few %. So "route around CABAC" = replace context-adaptive arithmetic coding with parallel palette-pack (+ optional non-adaptive rANS), NOT "zero entropy coding." The boundary is `.265`-compat, not the substrate's own entropy needs. |
56+
57+
## What amortizes, precisely
58+
59+
- **Build once, reuse per block.** The transform basis (WHT ±1 sign matrix), the
60+
interpolation taps, the Morton pyramid, the palette/centroid codebooks, and the
61+
golden-spiral place template are **deterministic** — computed once, never
62+
stored per-block (helix principle). The 64×64 gridlake = 4×4 = 16 tile positions.
63+
- **BUT: dispatch at the R-5 batch crossover — the tile path is NOT unconditional.**
64+
Per the companion plan's **R-5** rule (`pr-x12-codec-cognitive-substrate-mapping.md`
65+
§2.2; `pr-x12-substrate-canon-resolutions.md` §R-5): a single 32×32 DCT via
66+
butterflies is ~80 ops vs ~32K for the GEMM form — **per-block, butterflies win
67+
by ~400×**. The BF16 tile GEMM only wins **above** the batch crossover, where
68+
hardware fusion amortises across many blocks. Crossover is per-arch:
69+
**SPR = 64, ICX = 32, Zen4 = 96, Apple M = 256, Graviton = 128** blocks. So the
70+
amortized dispatch is: **per-CTU / low-latency / small-batch → per-block WHT
71+
butterflies; per-frame / large-batch (N ≥ crossover) → batched BF16 tile GEMM.**
72+
A ledger that read "every block pays a tile op" would mis-route small-CTU work
73+
onto the tile path and invalidate the measurement — ship both, dispatch on N.
74+
- **One kernel family, many stages.** ME, inverse transform, intra prediction,
75+
sub-pel, and covariance are all the same *algebra* (`M·X` / `Xᵀ·X` / `Mᵀ·Σ·M`),
76+
realised as **butterflies below the crossover, `bf16_tile_gemm_16x16` above it**.
77+
The substrate is the zero-FP cognitive shader (gather + tile/butterfly ops), so
78+
"the codec IS the substrate" holds down to the instruction (`TDPBF16PS` in the
79+
batched regime).
80+
- **The transform mostly vanishes.** Per #232, good motion whitens the residual
81+
and the transform's advantage → 1 (a no-op); where it survives it is a
82+
multiply-free WHT. So the amortized codec spends tile ops on prediction, not on
83+
transform-coding a well-predicted residual.
84+
85+
## The two honest boundaries
86+
87+
1. **CABAC is not a GEMM — but the substrate routes around it.** CABAC entropy
88+
(de)coding is inherently serial arithmetic coding; the tile substrate does not
89+
amortize it, and a real `.265` decoder still needs it (the M2 serial
90+
front-end). BUT the substrate does not *need* CABAC: it quantises to a small
91+
palette (≤256 basin/centroid indices), so its entropy need can be met by
92+
**variable-width SIMD palette packing** (`ndarray::palette_codec`, the
93+
Pumpkin/Minecraft port — `unpack_indices_simd`, VPSHUFB, 16 idx/cycle,
94+
`transcode` for per-block bit-width). This module is **shipped + tested** but
95+
**not yet wired as the codec's entropy stage** (the shipped codec uses
96+
`hpc::codec::ans` static rANS over the 4 `CellMode` tags) — the wiring is the
97+
proposed change. The point stands: a substrate-native pipeline has **no
98+
context-adaptive serial stage**`gather + tile op + palette-pack` — with, at
99+
most, a *non-adaptive* static-rANS pass over the packed indices (order-0,
100+
interleavable, not a CABAC-style dependency chain). The boundary is `.265`
101+
*compatibility*, not the substrate's own entropy needs. (Palette packing is a
102+
rate/parallelism trade vs an optimal arithmetic coder — near-optimal when the
103+
palette is well-chosen.)
104+
2. **The golden-spiral is for directional/sparse data, not dense scalars.** Per
105+
#231 (measured negative), coding a *dense scalar* residual with sparse
106+
golden-spiral anchors loses to local DPCM; the golden-spiral / helix codec
107+
belongs on directions (surfel normals, plausibly MV fields), not the dense
108+
luma residual. Use DPCM/WHT there.
109+
110+
## Probe queue (next falsifiable steps, in order)
111+
112+
1. **`subpel_tap_tile`** — HEVC 8-tap separable interpolation == `bf16_tile_gemm_16x16`,
113+
Frobenius-close to the reference FIR. (Cleanest next measurement; mechanism
114+
already clear.)
115+
2. **`intra_angular_tile`** — the 33 angular intra modes as directional tile-op
116+
extrapolations; measure PSNR vs the HEVC reference predictor.
117+
3. **`deblock_masked_tile`** — deblocking as a predicated (AMX-masked) tile op;
118+
measure vs the HEVC clip-based filter (tests the operator's "AMX masking").
119+
4. **CTU quad-tree routing parity** — Morton/HHTL cascade partition == HEVC CTU
120+
split decisions on a real frame.
121+
5. **M2 (separate track)** — CABAC serial front-end to extract MVs+residuals from
122+
a real `.265` bitstream. Not tile-amortizable; the honest hard part.
123+
124+
## Anchors
125+
126+
PRs #230 (ME=GEMM, MC bit-exact), #231 (residue upscaling — measured negative for
127+
dense scalar), #232 (transform no-op × WHT), #233 (field coupling = AMX tile op,
128+
on real `TDPBF16PS`). Shipped: `hpc::bf16_tile_gemm`, `hpc::splat3d::spd3`,
129+
`hpc::cascade`, `hpc::codec`; the Pumpkin/Minecraft entropy layer
130+
`palette_codec` / `nibble` / `byte_scan` (69 tests); lance-graph blasgraph HHTL;
131+
OGAR perturbation pyramid = WHT.

0 commit comments

Comments
 (0)