Commit 5c37f0c
committed
D1.2 rotation primitives + thinking-tissue north-star epiphany
First real kernel deliverable of Phase 1: RotationKernel trait + three
impls (Identity / Hadamard / OPQ-stub) with typed RotationError.
95/95 cognitive-shader-driver tests pass under --features serve
(+15 new D1.2 tests).
crates/cognitive-shader-driver/src/rotation_kernel.rs (~330 LOC):
RotationKernel trait — object-safe, Send+Sync+Debug:
apply(&self, &mut [f32]) -> Result<(), RotationError>
dim() -> u32
signature() -> u64 # feeds CodecParams::kernel_signature
backend() -> &'static str # "avx512" | "stub" (never "scalar")
IdentityRotation { dim }
— zero-overhead pass-through; apply() is a no-op
HadamardRotation { dim }
— REAL in-place Sylvester butterfly, O(N log N) add/sub,
no allocations
— validates dim is power-of-two (Sylvester requirement)
— Rule C compliance: stays at Tier-3 F32x16 (add/sub, not matmul;
AMX adds no value per plan appendix §12 C)
— rustc + target-cpu=x86-64-v4 already emits AVX-512 add/sub
from the straight-line loop → no JIT compilation needed
OpqRotationStub { matrix_blob_id, dim }
— real impl plugs into D1.1b CodecKernelEngine adapter +
ndarray::hpc::jitson_cranelift::JitEngine + tile_dpbf16ps AMX
matmul when amx_available()
— apply() returns OpqMatrixNotLoaded (typed error) until the
matrix-blob loader lands
build(&Rotation, dim) -> Result<Box<dyn RotationKernel>> factory
— dispatches on WireCodecParams.pre_rotation variant
— returns typed errors on dim mismatch or non-pow2 Hadamard
Tests (15 new):
Identity: noop + dim-mismatch error
Hadamard:
- orthogonality: H_4 · [1,0,0,0] == [1,1,1,1] (first column)
- H · H = n · I (applying twice scales by n, verified at N=8)
- norm² preservation up to n× scale (verified at N=16)
- rejects non-pow2 dim (N=6)
OPQ stub: returns OpqMatrixNotLoaded with blob_id preserved
build(): identity / hadamard / hadamard-dim-mismatch / hadamard-
non-pow2 / opq-stub
Signatures: distinct across variants, stable for same shape,
blob-id-sensitive for OPQ
Board hygiene (CLAUDE.md Mandatory rule):
STATUS_BOARD.md:
D1.2 Queued → In PR
EPIPHANIES.md PREPEND (two entries):
1. "Thinking styles ARE codecs over the semantic field"
(north-star forward-looking deposit, not a work item)
— codec infrastructure IS the template for production-grade
thinking tissue. Mapping table documents the codec→thinking
correspondence: CodecParams↔ThinkingStyleParams,
kernel_signature↔style_signature, token_agreement↔
conclusion_agreement, etc. Phase 5+ drops in
WireThinkCalibrate + ThinkingStyleKernelCache using the
same scaffolding. Generalisation isn't porting — it's
recognising thinking styles as a SPECIAL CASE of the
codec pattern.
2. "D1.2 Hadamard is pure-Rust, not a JIT-necessary primitive"
— narrows D1.1b scope by 30-40%. Only OPQ (matmul) needs
Cranelift JIT emission; Identity (no-op) and Hadamard
(butterfly) stay as plain-Rust Tier-3 F32x16 paths. Rustc's
AVX-512 codegen under target-cpu=x86-64-v4 is already
optimal for add/sub-structured kernels.
Rules honored:
Rule A — in-place &mut [f32] slice, no allocations in apply()
Rule B — ndarray::simd::* not needed for these shapes; compiler
emits AVX-512 from straight-line loops
Rule C — Hadamard stays at Tier 3 (add/sub, no AMX benefit);
OPQ stub will route to Tier 1 AMX when matrix loaded
Rule D — Rotation variants come from YAML via WireRotation (D0.1)
Rule E — kernel signature() + backend() are object-methods per
the Wire-surface-IS-SIMD-surface pattern
Rule F — no serialization anywhere; in-memory f32 buffer only
https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh1 parent cf42a4a commit 5c37f0c
4 files changed
Lines changed: 463 additions & 1 deletion
File tree
- .claude/board
- crates/cognitive-shader-driver/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
68 | 144 | | |
69 | 145 | | |
70 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
| |||
0 commit comments