From 348eebebad3a38a8fad6f3d470b04a6c5953dcd3 Mon Sep 17 00:00:00 2001 From: Federico Carrone Date: Sun, 29 Nov 2026 20:43:36 -0300 Subject: [PATCH] build: pin lambda-hdl v0.18 (d746a1a) as git dep; refresh docs for v2.8 - lakefile: replace ../lambda-hdl path with pinned git revision; CI no longer checks out lambda-hdl's moving main - README: v2.8, lambda-hdl v0.18, 57 audited theorems, bv_decide trusted base, measured SoC 50c wall cycles (771), relative links - CHANGELOG: add 2.8.0 and Unreleased entries; relative links --- .github/workflows/ci.yml | 14 +--- CHANGELOG.md | 69 +++++++++++------- README.md | 154 +++++++++++++++++++++++---------------- lake-manifest.json | 7 +- lakefile.lean | 3 +- 5 files changed, 143 insertions(+), 104 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39b9b22..cbd961c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,9 @@ jobs: verify: runs-on: ubuntu-latest steps: - - name: Checkout lambda-gpu - uses: actions/checkout@v4 - with: - path: lambda-gpu - - name: Checkout sibling lambda-hdl - uses: actions/checkout@v4 - with: - repository: unbalancedparentheses/lambda-hdl - path: lambda-hdl + - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Run full λ-GPU formal proofs, Z3 CEC/BMC/k-Ind, Yosys LEC, arcilator, Verilator, Yosys PPA & 32-run GEMM Refinement - working-directory: lambda-gpu + # lambda-hdl is fetched by Lake at the revision pinned in lake-manifest.json. + - name: Run proofs, Z3 CEC/BMC/k-Ind, Yosys LEC, arcilator, Verilator, Yosys PPA & GEMM refinement run: nix develop --command bash -c "make all verilator-direct yosys && lake exe lambda-gpu-gemm-refinement" diff --git a/CHANGELOG.md b/CHANGELOG.md index ea58204..052bbd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,33 @@ All notable architectural milestones, verification runs, and PPA/timing results in `lambda-gpu` are logged here. +## [Unreleased] + +### Changed +- `lambda-hdl` is now a pinned git dependency (`d746a1a`, v0.18.0) recorded in `lake-manifest.json`, replacing the `../lambda-hdl` sibling path. CI no longer checks out lambda-hdl's moving `main`. +- Documentation links are repository-relative instead of absolute local `file:///` paths. +- README documents the trusted base of the `bv_decide` proofs. + +## [2.8.0] — 2026-11-28 (PipedTileCore Wire-Order Fix & Variable-Latency GEMM Refinement) + +### Fixed +- **`PipedTileCore` topological wire order**: the LDS writeback muxes `s3_lds_d{0..3}` are now declared in `declRFBRAMs`, before `wb_v{0..3}` consumes them, reading the synchronous `smem_b{0..3}_rdata` outputs directly ([PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean)). +- `fp32AddExpr_eval_eq_spec` closed with `rfl` for lambda-hdl v0.18 ([BF16Proofs.lean](LambdaGPU/Proofs/BF16Proofs.lean)). + +### Added +- **32-schedule variable-latency 4×4 GEMM refinement (`lake exe lambda-gpu-gemm-refinement`)** ([GemmRefinement.lean](LambdaGPU/Examples/GemmRefinement.lean)): drives the `PipedTileCore` HDL semantics with 2 data seeds × 4×4 per-request DMA latencies `{1, 3, 17, 50}` and periodic request backpressure, and checks the 16 ordered GMEM writes against the ISA golden model. `writes_of_matchesISA` lifts each passing run, via `compileGemm4x4_end_to_end_spec`, to the mathematical matrix product. +- CI runs the GEMM refinement. + ## [2.7.0] — 2026-11-28 (69.88 MHz Post-Route Lattice ECP5-85F Timing Closure, 4-Stage Tensor Core, Parallel-Speculative BF16/FP32 Arithmetic & Compiled CIRCT `arcilator` C++ Execution + Benchmark) ### Added -- **Real Post-Route Lattice ECP5-85F Timing Closure (`54.15 MHz → 69.88 MHz`, `+29.0%`!) & Xilinx `ABC9` Depth Reduction (`lev = 15, levB = 19`)** ([BF16.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/BF16.lean), [PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean), [pnr_ecp5.sh](file:///home/unbalancedparen/projects/lambda-gpu/scripts/pnr_ecp5.sh)): +- **Real Post-Route Lattice ECP5-85F Timing Closure (`54.15 MHz → 69.88 MHz`, `+29.0%`!) & Xilinx `ABC9` Depth Reduction (`lev = 15, levB = 19`)** ([BF16.lean](LambdaGPU/HDL/BF16.lean), [PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean), [pnr_ecp5.sh](scripts/pnr_ecp5.sh)): - Guided directly by `nextpnr-ecp5` routed critical path analysis across 3 measured iterations: 1. **EX0/EX1 Split of Vector Softmax & EA Datapath**: Split `bf16AddWire` into 2-stage `bf16AddStage1Wire` (EX0) → `bf16AddStage2Wire` (EX1), moved zero-DSP `bf16Exp2Wire` & `bf16RcpWire` (shared 16-bit `s25_vspec{0..3}`) and 3-input effective address adders (`ex0_ea{0..3}`) into Stage EX0 at **zero extra pipeline cycles** and **zero extra DSPs**. 2. **4-Stage Matrix Engine (`M0A [TQUEUE Mux] → M0B [Pure FF → MULT18X18D] → M1 [Align + Add/Sub] → M2 [CLZ + Norm + WB]`)**: Cut the 32-entry `tq0_mem`/`tq1_mem` mux cleanly before `MULT18X18D` (preserving 4-cycle row distance & zero RAW hazards) and split MMA `bf16Add` across `M1 → M2`. 3. **Parallel-Speculative Exponent & Dual-Path FP32 Aligner**: Precomputed `eUnb0/1`, `uf0/1`, `ovf0/1` in parallel with `MULT18X18D` in `bf16MulToFp32Wire` & `bf16MulFromProdWire` (replacing 4 sequential 10-bit carry chains with a single 2:1 mux!), and added a dual-path aligner (`diffAB`/`diffBA` + `shB`/`shA` in parallel with 31-bit `aGeB`) in `fp32AddStage1Wire` — ALL proved **100% bit-exact (`unsat`)** across all $2^{32}$/$2^{64}$ inputs by Z3 CEC! 4. Enabled timing-driven `--freq 80` in `scripts/pnr_ecp5.sh`. -- **Native Compiled CIRCT `arcilator` C++ Verification & Head-to-Head Throughput Benchmark (`make arcilator`, `make arcilator-bench`)** ([gen_arc_header.py](file:///home/unbalancedparen/projects/lambda-gpu/scripts/gen_arc_header.py), [tb_arcilator.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_arcilator.cpp), [tb_piped_core.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_piped_core.cpp), [Makefile](file:///home/unbalancedparen/projects/lambda-gpu/Makefile)): +- **Native Compiled CIRCT `arcilator` C++ Verification & Head-to-Head Throughput Benchmark (`make arcilator`, `make arcilator-bench`)** ([gen_arc_header.py](scripts/gen_arc_header.py), [tb_arcilator.cpp](sim/tb_arcilator.cpp), [tb_piped_core.cpp](sim/tb_piped_core.cpp), [Makefile](Makefile)): - Emits zero-overhead `ArcPipedTileCore` C++ bindings directly from `arcilator --state-file=gen/PipedTileCore_arc.json --no-runtime --emit-llvm`, compiles `PipedTileCore_arc_bench.ll` with `clang++ -O3`, and executes **ALL 40/40 λ-GPU kernel runs (20 kernels × `{1c, 50c DRAM}`)** bit-for-bit against Lean's Golden oracle — giving **3-way independent simulator cross-validation** (`Lean Golden ≡ Verilator 5.054 ≡ CIRCT arcilator LLVM IR`)! ### Verified (100% Bit-for-Bit Pass) @@ -32,16 +49,16 @@ All notable architectural milestones, verification runs, and PPA/timing results ## [2.6.0] — 2026-11-28 (Direct Z3-Verified `TileScoreboardCtrl` Submodule Instantiation, Multi-Block Online FlashAttention-2 `4x8`, Universal End-to-End Compiler Proof & 4-Beat `ARLEN=3` AXI4 Bursts) ### Added -- **Direct Instantiation of Z3-Verified `TileScoreboardCtrl` (`u_sb`) inside `PipedTileCore` — Zero Model-Extraction Gap!** ([ScoreboardBMC.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ScoreboardBMC.lean), [PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean)): +- **Direct Instantiation of Z3-Verified `TileScoreboardCtrl` (`u_sb`) inside `PipedTileCore` — Zero Model-Extraction Gap!** ([ScoreboardBMC.lean](LambdaGPU/HDL/ScoreboardBMC.lean), [PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean)): - Replaced `PipedTileCore`'s inline `tq0_*`/`tq1_*`/`mma_busy` scoreboard registers and control rules with a **true hierarchical `SubModInst` (`submod "u_sb" tileScoreboardCtrl`)** — the exact RTL submodule proved by Z3 16-cycle BMC + Unbounded $k$-Induction ($t \in [0, \infty)$) and Yosys pure-I/O Backend LEC! - Preserved hierarchically through CIRCT `firtool`, Yosys Xilinx synthesis (`TileScoreboardCtrl`: 51 cells / 17 `FDRE`), and `LambdaMesh2x2SoC` (now **14 hierarchical submodules** and **72 live RTL `HAssert` invariants** checked simultaneously in Verilator: `4×7` `TileScoreboardCtrl` + `4×8` `SplitToAXI4Bridge` + `8` `AXI4Mux4` + `4` `AXI4LiteCSR`!). -- **True Multi-Block Online-Rescaling FlashAttention-2 (`flash_online_attn_4x8`)** ([V2Kernels.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Kernels/V2Kernels.lean), [tb_piped_core.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_piped_core.cpp)): +- **True Multi-Block Online-Rescaling FlashAttention-2 (`flash_online_attn_4x8`)** ([V2Kernels.lean](LambdaGPU/Kernels/V2Kernels.lean), [tb_piped_core.cpp](sim/tb_piped_core.cpp)): - Streams **2 distinct $4 \times 4$ K/V blocks** ($K_0, V_0$ and $K_1, V_1$, total sequence length $N = 8$, **256 mixed-precision `W_MMA_BF16_F32` MACs**), maintaining running per-row `(m_prev, l_prev, O_prev)` in SMEM and performing true online FlashAttention-2 rescaling ($\alpha = 2^{m_{\text{prev}} - m_{\text{new}}}$, $\beta = 2^{m_{\text{cur}} - m_{\text{new}}}$, $l_{\text{new}} = \alpha l_{\text{prev}} + \beta l_{\text{cur}}$, $O_{\text{new}} = (\alpha O_{\text{prev}} + \beta O_{\text{cur}}) / l_{\text{new}}$) using hardware `V_BF16_EXP2`, `V_BF16_RCP`, `V_BF16_MUL`, `V_BF16_ADD`/`SUB`, `V_BF16_MAX`, and `V_SHFL`! - Verified bit-exact against Lean's `Golden` oracle AND independently validated against IEEE-754 `float64` full $4 \times 8$ attention: **`max|O_hw - O_f64| = 0.0066` (`0.86%` relative error!)**. -- **Universal Zero-`sorry` End-to-End Multi-Step Compiler Correctness Theorem (`compileGemm4x4_end_to_end_spec`)** ([CompilerProofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/CompilerProofs.lean), [Audit.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/Audit.lean)): +- **Universal Zero-`sorry` End-to-End Multi-Step Compiler Correctness Theorem (`compileGemm4x4_end_to_end_spec`)** ([CompilerProofs.lean](LambdaGPU/Proofs/CompilerProofs.lean), [Audit.lean](LambdaGPU/Proofs/Audit.lean)): - Added `stepWarp_t_mov`, `stepWarp_stg`, and proved **`compileGemm4x4_end_to_end_spec`** **universally over ALL $2^{1024}$ possible 4×4 `BitVec 32` input matrices `A, B`**: assembling and executing all 16 instructions of `compileGemm4x4 0 16 32` terminates cleanly (`halted = true`, `cycles = 16`) and writes the exact mathematical product `C[r,c] = ∑_k A[r,k]*B[k,c]` into `gmem[32..47]`! - Total machine-checked zero-`sorry` Lean 4 theorems increased from **52 → 55** (`Audit.lean`). -- **True 4-Beat `ARLEN=3` 64-Byte ARM AXI4 Burst Reads for Contiguous `DMA_PUSH` Tiles** ([PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean), [CoreAXI4.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/CoreAXI4.lean), [Mesh2x2SoC.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/Mesh2x2SoC.lean), built on `lambda-hdl` v0.11): +- **True 4-Beat `ARLEN=3` 64-Byte ARM AXI4 Burst Reads for Contiguous `DMA_PUSH` Tiles** ([PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean), [CoreAXI4.lean](LambdaGPU/HDL/CoreAXI4.lean), [Mesh2x2SoC.lean](LambdaGPU/HDL/Mesh2x2SoC.lean), built on `lambda-hdl` v0.11): - Contiguous `DMA_PUSH` (`stride == 4`) issues a single 4-beat 64-byte `ARLEN=3` burst instead of 4 separate 16-byte single-beat `AR` requests — cutting AXI4 `AR` read handshakes by an **exact 4.0×** (`32 → 8` on the 4-core SoC; `8 → 2` on `tileGemm_4x4_wmma` / `bf16_gemm_4x4_wmma`; `16 → 4` on `fused_flash_attn_4x4`) and speeding up the full 4-core SoC by **55 wall cycles**! ### Verified (100% Bit-for-Bit Pass) @@ -62,15 +79,15 @@ All notable architectural milestones, verification runs, and PPA/timing results ## [2.5.0] — 2026-11-27 (GPU End-to-End Backend LEC, RTL-Level Z3 BMC + Unbounded $k$-Induction, Multi-Head FlashAttention-2 4-Core SoC & GitHub Actions CI) ### Added -- **Real RTL-Level Z3 BMC (16 Cycles) + Unbounded $k$-Induction (`make bmc`)** ([ScoreboardBMC.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ScoreboardBMC.lean), [Makefile](file:///home/unbalancedparen/projects/lambda-gpu/Makefile)): +- **Real RTL-Level Z3 BMC (16 Cycles) + Unbounded $k$-Induction (`make bmc`)** ([ScoreboardBMC.lean](LambdaGPU/HDL/ScoreboardBMC.lean), [Makefile](Makefile)): - Extracted `TileScoreboardCtrl` matching `PipedTileCore`'s exact `TQUEUE` (`Q0/Q1`, depth 2, `alloc`/`ready`/`head`/`tail` + DMA inflight counters) and `W_MMA` occupancy controller with **7 formal 1-inductive `HAssert` invariants** (`q0_ready_le_alloc`, `q1_ready_le_alloc`, `q0_alloc_le_2`, `q1_alloc_le_2`, `q0_inflight_exact`, `q1_inflight_exact`, `mma_busy_has_tiles`). - Proved **UNSAT** by BOTH **16-cycle Z3 BMC** (`TileScoreboardCtrl_bmc.smt2`) AND **Unbounded $k$-Induction ($t \in [0, \infty)$)** (`TileScoreboardCtrl_kind.smt2`), PLUS non-vacuity overflow mutant (`Mutant_TileScoreboardCtrl_bug_bmc.smt2`) caught as **`sat`**! -- **GPU End-to-End Backend LEC (`make lec`)** ([Makefile](file:///home/unbalancedparen/projects/lambda-gpu/Makefile), [GenMain.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/GenMain.lean)): +- **GPU End-to-End Backend LEC (`make lec`)** ([Makefile](Makefile), [GenMain.lean](LambdaGPU/GenMain.lean)): - Enabled `--lowering-options=disallowLocalVariables,disallowPackedArrays` in CIRCT `firtool` so Yosys cleanly parses all generated CIRCT SystemVerilog (including `PipedTileCore_firtool.sv`!). - Proved **`Direct SV ≡ CIRCT firtool SV`** via Yosys 8-cycle pure-I/O miter SAT across **4/4 GPU controller & SoC interconnect modules** (`TileScoreboardCtrl`, `SplitToAXI4Bridge`, `AXI4Mux4`, `AXI4LiteCSR`) + **1/1 non-vacuity mutant (`TileScoreboardCtrl_mutant.sv`) REJECTED**! -- **Upgraded 4-Core `LambdaMesh2x2` & `LambdaMesh2x2SoC` Heterogeneous Multi-Head Workload** ([V2Kernels.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Kernels/V2Kernels.lean), [tb_mesh_soc.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_mesh_soc.cpp), [tb_mesh_noc.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_mesh_noc.cpp)): +- **Upgraded 4-Core `LambdaMesh2x2` & `LambdaMesh2x2SoC` Heterogeneous Multi-Head Workload** ([V2Kernels.lean](LambdaGPU/Kernels/V2Kernels.lean), [tb_mesh_soc.cpp](sim/tb_mesh_soc.cpp), [tb_mesh_noc.cpp](sim/tb_mesh_noc.cpp)): - Upgraded Core 3 to execute **live Mixed-Precision Online-Softmax FlashAttention-2 (`meshNoCCore3FlashAttn`: `W_MMA_BF16_F32` + warp-parallel Softmax `EXP2`/`RCP`/`MUL` → FP32)** concurrently alongside Cores 0–2's zero-DRAM-spill 3-stage Tile-NoC Attention pipeline (`Y = ((Q×Kᵀ)×V)×W_O`) over the single shared 128-bit ARM AXI4 DRAM bus! -- **GitHub Actions CI Workflow** ([ci.yml](file:///home/unbalancedparen/projects/lambda-gpu/.github/workflows/ci.yml)): +- **GitHub Actions CI Workflow** ([ci.yml](.github/workflows/ci.yml)): - Automated Nix CI running `make all verilator-direct yosys` (all Lean proofs, 8 Z3 CEC + 2 Z3 RTL BMC/k-Ind + 2 mutants, 4 Yosys LEC + mutant, CIRCT `firtool` + `arcilator`, 76/76 Verilator core + Mesh + AXI4 + 4-core SoC, axiom audit, bug-injection, and Yosys PPA) on every push/PR to `main`. ### Verified (100% Bit-for-Bit Pass) @@ -91,15 +108,15 @@ All notable architectural milestones, verification runs, and PPA/timing results ## [2.4.0] — 2026-11-27 (True Mixed-Precision Online-Softmax FlashAttention-2, Zero-DSP `EXP2`/`RCP`, Shared-DSP `V_BF16_MUL`, 54.15 MHz Post-Route ECP5 & 52 Zero-`sorry` Proofs) ### Added -- **Native Mixed-Precision Softmax & ML Vector ISA Extensions (8 New Opcodes at ZERO Extra DSPs!)** ([ISA.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Spec/ISA.lean), [Asm.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Spec/Asm.lean), [BF16.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/BF16.lean), [ALU.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ALU.lean), [PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean)): +- **Native Mixed-Precision Softmax & ML Vector ISA Extensions (8 New Opcodes at ZERO Extra DSPs!)** ([ISA.lean](LambdaGPU/Spec/ISA.lean), [Asm.lean](LambdaGPU/Spec/Asm.lean), [BF16.lean](LambdaGPU/HDL/BF16.lean), [ALU.lean](LambdaGPU/HDL/ALU.lean), [PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean)): - Added `V_FP32_TO_BF16` (`0x37`), `V_BF16_TO_FP32` (`0x38`), `V_FP32_MAX` (`0x39`), **`V_BF16_EXP2` (`0x3A`)**, **`V_BF16_RCP` (`0x3B`)**, **`V_BF16_ADD` (`0x3C`)**, **`V_BF16_SUB` (`0x3D`)**, and **`V_BF16_MUL` (`0x3E`)**. - **Zero-DSP Hardware `V_BF16_EXP2`** (`bf16Exp2Spec/Expr/Wire`): Q6.7 fixed-point shift + 16-entry concave correction LUT (`<0.4%` fractional error, **0.00% bit-exact** on every integer $k \in [-63, 63]$, proved strictly non-negative across all 65,536 BF16 inputs via `bf16Exp2Spec_nonneg`!). - **Zero-DSP Hardware `V_BF16_RCP`** (`bf16RcpSpec/Expr/Wire`): exact power-of-2 fast path + 32-entry mantissa LUT (`<1.5%` error, **0.00% exact** on all powers of 2!). - **Shared-DSP `V_BF16_MUL` (`bf16MulFromProdSpec/Expr/Wire`)**: Muxes Stage EX0's existing 32×32 lane multipliers (`ex0_vmul0..3`) for `V_BF16_MUL` mantissa multiply and completes sign/exponent/normalize in Stage EX1 with **ZERO extra DSPs** (proved bit-identical to `bf16MulSpec` across all $2^{32}$ inputs in `bf16MulFromProd_eq_bf16Mul`!), while `V_BF16_ADD` and `V_BF16_SUB` share a single wire-factored `bf16AddWire` per lane! -- **End-to-End Mixed-Precision Online-Softmax FlashAttention-2 Kernel (`flash_softmax_attn_4x4`)** ([V2Kernels.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Kernels/V2Kernels.lean), [tb_piped_core.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_piped_core.cpp)): +- **End-to-End Mixed-Precision Online-Softmax FlashAttention-2 Kernel (`flash_softmax_attn_4x4`)** ([V2Kernels.lean](LambdaGPU/Kernels/V2Kernels.lean), [tb_piped_core.cpp](sim/tb_piped_core.cpp)): - Computes $S_{\text{fp32}} = Q_{\text{bf16}} \times K^\top_{\text{bf16}}$ via `W_MMA_BF16_F32` → casts FP32→BF16 → warp-parallel `V_SHFL XOR` row-max reduction (`m_r`) → stable shift $S - m_r$ → hardware `V_BF16_EXP2` → warp-parallel `V_SHFL XOR` row-sum reduction (`l_r`) → hardware `V_BF16_RCP` + `V_BF16_MUL` ($P = e / l_r$) → $O_{\text{fp32}} = P_{\text{bf16}} \times V_{\text{bf16}}$ via `W_MMA_BF16_F32`! - Cross-checked against BOTH Lean's bit-exact `Golden` oracle AND an independent IEEE-754 `float64` mathematical `exp2`-softmax reference in Verilator! -- **7 New Lean 4 Proofs + 3 New Live Z3 CEC Proofs** ([BF16Proofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/BF16Proofs.lean), [ALUProofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/ALUProofs.lean), [Audit.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/Audit.lean)): +- **7 New Lean 4 Proofs + 3 New Live Z3 CEC Proofs** ([BF16Proofs.lean](LambdaGPU/Proofs/BF16Proofs.lean), [ALUProofs.lean](LambdaGPU/Proofs/ALUProofs.lean), [Audit.lean](LambdaGPU/Proofs/Audit.lean)): - Proved `bf16MulFromProd_eq_bf16Mul` (`bv_decide`, $2^{32}$), `bf16Exp2Spec_nonneg` (`bv_decide`, $2^{16}$), `bf16Exp2Expr_eval_eq_spec`, `bf16RcpExpr_eval_eq_spec`, `bf16Exp2_exact_vectors`, `bf16Rcp_exact_vectors`, plus extended `valuExpr_eval_eq_spec` & `valuFromMulExpr_eval_eq_spec` to all 25 VALU opcodes (**52 zero-`sorry` Lean 4 theorems**!). - Added Z3 CEC proofs `CEC_BF16Exp2_wire_vs_spec.smt2`, `CEC_BF16Rcp_wire_vs_spec.smt2`, and `CEC_BF16MulFromProd_wire_vs_spec.smt2` (**8/8 positive CEC `unsat` + 1/1 mutant `sat`**!). @@ -117,16 +134,16 @@ All notable architectural milestones, verification runs, and PPA/timing results ## [2.3.0] — 2026-11-27 (6-Stage `PipedTileCore`, 3-Stage Mixed-Precision `BF16 × BF16 → FP32` Tensor Core, 53.67 MHz Post-Route ECP5, CIRCT `arcilator` & 45 Zero-`sorry` Proofs) ### Added -- **6-Stage Pipelined `PipedTileCore` (`IF → ID/RF → OP [Resolve] → EX0 [Mul] → EX1 [Zero-Mul ALU+SMEM+Engines] → WB`)** ([PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean), [ALU.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ALU.lean), [ALUProofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/ALUProofs.lean)): +- **6-Stage Pipelined `PipedTileCore` (`IF → ID/RF → OP [Resolve] → EX0 [Mul] → EX1 [Zero-Mul ALU+SMEM+Engines] → WB`)** ([PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean), [ALU.lean](LambdaGPU/HDL/ALU.lean), [ALUProofs.lean](LambdaGPU/Proofs/ALUProofs.lean)): - Guided directly by `nextpnr-ecp5`'s v2.2 post-route critical path (`DP16KD BRAM + resolveOpnd → MULT18X18D → VALU`), split Execute into three dedicated stages: `OP` (operand resolve only), `EX0` (`s2r_* → MULT18X18D → s25_*`, pure FF-to-FF multipliers + `dp4aDotExpr`), and `EX1` (zero-multiplier `saluFromMulExpr` / `valuFromMulExpr`, proved bit-exact against `saluSpec`/`valuSpec` in `ALUProofs.lean`!). - Cut real post-route ECP5-85F logic delay by **1.53× (`10.36 ns` → `6.76 ns`)**, boosting real post-route `Fmax` from **`44.96 MHz` → `53.67 MHz` (+19.4%)** even while adding a full 23-bit mantissa IEEE-754 FP32 Tensor Core! -- **3-Stage Mixed-Precision `BF16 × BF16 → FP32` Tensor Core (`W_MMA_BF16_F32`, `0x67`) at ZERO Extra DSPs** ([ISA.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Spec/ISA.lean), [BF16.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/BF16.lean), [BF16Proofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/BF16Proofs.lean), [V2Kernels.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Kernels/V2Kernels.lean)): +- **3-Stage Mixed-Precision `BF16 × BF16 → FP32` Tensor Core (`W_MMA_BF16_F32`, `0x67`) at ZERO Extra DSPs** ([ISA.lean](LambdaGPU/Spec/ISA.lean), [BF16.lean](LambdaGPU/HDL/BF16.lean), [BF16Proofs.lean](LambdaGPU/Proofs/BF16Proofs.lean), [V2Kernels.lean](LambdaGPU/Kernels/V2Kernels.lean)): - Proved **`bf16MulToFp32_hi16_eq_bf16Mul`** (`bv_decide` across all $2^{32}$ inputs): the top 16 bits `[31:16]` of lossless widening `bf16MulToFp32Spec` are **bit-for-bit identical** to `bf16MulSpec`, letting ONE shared 4-wide multiplier array power BOTH `W_MMA_BF16` and `W_MMA_BF16_F32` at **0 extra DSPs** (still **48 `DSP48E1`** / **48 `MULT18X18D`**)! - Exploited the 4-cycle row distance (`K`-outer / `Row`-inner) to pipeline the Matrix Engine into **3 stages with ZERO RAW hazards**: `M0` (`bf16MulToFp32Wire`) → `M1` (`fp32AddStage1Wire`: magnitude compare + alignment shift + 25b add/sub) → `M2` (`fp32AddStage2Wire`: balanced log-depth 24-bit `clz24Expr` + normalize shift + pack → `tmem0`). - Added native **`bf16_f32_gemm_4x4`** mixed-precision GEMM kernel + live Z3 CEC proofs **`CEC_BF16MulToFp32_wire_vs_spec.smt2`** (all $2^{32}$ inputs → **`unsat`**) and **`CEC_FP32Add_wire_vs_spec.smt2`** (proving the 2-stage `fp32AddStage1Wire → fp32AddStage2Wire` split ≡ `fp32AddSpec` across all $2^{64}$ inputs → **`unsat`**!). -- **Small-Step Operational Semantics Hoare Lemmas (`CompilerProofs.lean`)** ([CompilerProofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/CompilerProofs.lean)): +- **Small-Step Operational Semantics Hoare Lemmas (`CompilerProofs.lean`)** ([CompilerProofs.lean](LambdaGPU/Proofs/CompilerProofs.lean)): - Added 7 zero-`sorry` operational semantics lemmas on `Golden.stepWarp` (`stepWarp_s_movi`, `stepWarp_t_clear`, `stepWarp_dma_push`, `stepWarp_w_mma_i8`, `stepWarp_w_mma_bf16`, `stepWarp_w_mma_bf16_f32`, `stepWarp_s_end`) built on `decodeRaw_encodeRaw` and `mkMovi_imm32` — bringing total audited GPU theorems from **33 → 45**! -- **CIRCT `arcilator` LLVM IR Compilation (`make arcilator`)** ([Makefile](file:///home/unbalancedparen/projects/lambda-gpu/Makefile)): +- **CIRCT `arcilator` LLVM IR Compilation (`make arcilator`)** ([Makefile](Makefile)): - Compiles both `PipedTileCore` (`7,935` lines LLVM IR) and the full 4-core `LambdaMesh2x2SoC` (`25,362` lines LLVM IR) cleanly through `firtool --ir-hw → arcilator --emit-llvm`. ### Verified (100% Bit-for-Bit Pass) @@ -145,14 +162,14 @@ All notable architectural milestones, verification runs, and PPA/timing results ## [2.2.0] — 2026-11-27 (Full 4-Core AXI4+AXI4-Lite SoC, Z3 CEC BF16 Proof Closure, Native BF16 Fused Attention & Real ECP5 Post-Route Timing) ### Added -- **Full SoC-Ready 4-Core GPU (`LambdaMesh2x2SoC`)** ([Mesh2x2SoC.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/Mesh2x2SoC.lean), [tb_mesh_soc.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_mesh_soc.cpp)): +- **Full SoC-Ready 4-Core GPU (`LambdaMesh2x2SoC`)** ([Mesh2x2SoC.lean](LambdaGPU/HDL/Mesh2x2SoC.lean), [tb_mesh_soc.cpp](sim/tb_mesh_soc.cpp)): - Preserves **10 true hierarchical submodules** through CIRCT `firtool 1.163.0`: `4 × PipedTileCore` + `4 × SplitToAXI4Bridge` + `1 × AXI4Mux4` (4→1 unified 128-bit ARM AXI4 DRAM Master with lossless `8b → 10b` ID widening) + `1 × AXI4LiteCSR` (32-bit ARM AXI4-Lite Host Control & Telemetry CSRs with auto-generated `gen/gpu_soc_csr.h`!). - **55 live RTL `HAssert` invariants** active simultaneously in hardware simulation (`4×4` TQUEUE + `4×7` Bridge + `7` AXI4Mux4 + `4` AXI4LiteCSR). -- **Live Z3 Combinational Equivalence Checking (`make cec`) — Closing the BF16 Wire-DAG ↔ Spec Gap** ([GenMain.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/GenMain.lean), [flake.nix](file:///home/unbalancedparen/projects/lambda-gpu/flake.nix)): +- **Live Z3 Combinational Equivalence Checking (`make cec`) — Closing the BF16 Wire-DAG ↔ Spec Gap** ([GenMain.lean](LambdaGPU/GenMain.lean), [flake.nix](flake.nix)): - Proved **`bf16MulWire ≡ bf16MulExpr ≡ bf16MulSpec`** (`CEC_BF16Mul_wire_vs_spec.smt2` → **`unsat`** across all $2^{32}$ inputs!), **`bf16AddWire ≡ bf16AddExpr ≡ bf16AddSpec`** (`CEC_BF16Add_wire_vs_spec.smt2` → **`unsat`** across all $2^{32}$ inputs!), and **`valuExpr ≡ valuExpr.opt`** (`CEC_VALU_opt.smt2` → **`unsat`**), PLUS non-vacuity mutant `Mutant_CEC_BF16Mul_bug.smt2` → **`sat`**! -- **Native BFloat16 Vector Epilogue Ops (`V_BF16_RELU`, `V_BF16_MAX`) & End-to-End BF16 Fused Attention** ([ISA.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Spec/ISA.lean), [ALU.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ALU.lean), [V2Kernels.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Kernels/V2Kernels.lean)): +- **Native BFloat16 Vector Epilogue Ops (`V_BF16_RELU`, `V_BF16_MAX`) & End-to-End BF16 Fused Attention** ([ISA.lean](LambdaGPU/Spec/ISA.lean), [ALU.lean](LambdaGPU/HDL/ALU.lean), [V2Kernels.lean](LambdaGPU/Kernels/V2Kernels.lean)): - Added `V_BF16_RELU` (`0x35`) and `V_BF16_MAX` (`0x36`) with `valuExpr_eval_eq_spec` still proved by `rfl`, powering 100% native **`bf16_fused_attn_4x4`** (`Q×Kᵀ [W_MMA_BF16] → V_BF16_RELU → ×V [W_MMA_BF16]`). -- **Real Open-Source Post-Route FPGA Place-and-Route Timing** ([pnr_ecp5.sh](file:///home/unbalancedparen/projects/lambda-gpu/scripts/pnr_ecp5.sh)): +- **Real Open-Source Post-Route FPGA Place-and-Route Timing** ([pnr_ecp5.sh](scripts/pnr_ecp5.sh)): - Full `yosys synth_ecp5` + `nextpnr-ecp5 --85k --package CABGA381 --speed 8 --out-of-context` placement & routing of `PipedTileCore`. ### Verified (100% Bit-for-Bit Pass) @@ -170,10 +187,10 @@ All notable architectural milestones, verification runs, and PPA/timing results ## [2.1.0] — 2026-11-27 (2-Stage Pipelined BF16 MMA + Z3-Verified ARM AXI4 GPU Core on `lambda-hdl` v0.6) ### Added -- **2-Stage Pipelined `W_MMA_BF16` & `W_MMA_I8` Matrix Engine** ([PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean)): +- **2-Stage Pipelined `W_MMA_BF16` & `W_MMA_I8` Matrix Engine** ([PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean)): - Switched iteration to **`K`-outer / `Row`-inner** (`mma_step[3:2] = k`, `mma_step[1:0] = row`): consecutive cycles write distinct `tmem0` rows (`0, 1, 2, 3`), creating a 4-cycle distance before any row is re-read (**ZERO RAW hazards**, exact `k = 0..3` accumulation order for bit-exact non-associative BF16!). - Split `bf16MulWire` (`Stage M0`) → pipeline registers `mma_p_*` → `bf16AddWire` (`Stage M1`), eliminating `bf_c*_out` completely from the critical path! -- **Hierarchical ARM AMBA AXI4 128-Bit GPU Core (`LambdaGPUCoreAXI4`)** ([CoreAXI4.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/CoreAXI4.lean), [tb_core_axi4.cpp](file:///home/unbalancedparen/projects/lambda-gpu/sim/tb_core_axi4.cpp)): +- **Hierarchical ARM AMBA AXI4 128-Bit GPU Core (`LambdaGPUCoreAXI4`)** ([CoreAXI4.lean](LambdaGPU/HDL/CoreAXI4.lean), [tb_core_axi4.cpp](sim/tb_core_axi4.cpp)): - Instantiates `u_core : PipedTileCore` + `lambda-hdl` v0.6's Z3-verified `u_axi4 : SplitToAXI4Bridge` (all 7 ARM IHI 0022E stability `HAssert`s proved **UNSAT** for all $t \in [0, \infty)$!) preserving true hierarchy through CIRCT `firtool 1.163.0`. - Added Verilator AXI4 128-bit DRAM Slave testbench with **live staggered `ARREADY`/`AWREADY`/`WREADY` backpressure** and 50-cycle read latency. @@ -193,19 +210,19 @@ All notable architectural milestones, verification runs, and PPA/timing results ### Changed - **100% Sparkle Removal**: Deleted all Sparkle dependencies and legacy `LambdaGPU/RTL/*`, `Smoke*.lean`, and `*CoSimGen.lean` files (archived v1 Sparkle `.sv` baselines under `bench/v1_sparkle/` for reproducible side-by-side Yosys PPA & timing comparisons). -- **Rebuilt ALUs & BFloat16 on `LambdaHDL.HExpr`** ([ALU.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ALU.lean), [BF16.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/BF16.lean), [ALUProofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/ALUProofs.lean), [BF16Proofs.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/Proofs/BF16Proofs.lean)): +- **Rebuilt ALUs & BFloat16 on `LambdaHDL.HExpr`** ([ALU.lean](LambdaGPU/HDL/ALU.lean), [BF16.lean](LambdaGPU/HDL/BF16.lean), [ALUProofs.lean](LambdaGPU/Proofs/ALUProofs.lean), [BF16Proofs.lean](LambdaGPU/Proofs/BF16Proofs.lean)): - `dp4aExpr_eval_eq_spec`, `saluExpr_eval_eq_spec`, `valuExpr_eval_eq_spec`, `bf16MulExpr_eval_eq_spec`, and `bf16AddExpr_eval_eq_spec` are **1-line `rfl` proofs** and remain bit-exact after `LambdaHDL.HExpr.opt` via `eval_opt`. - Added full `bf16AddSpec`/`bf16AddExpr`, `bf16MacSpec`/`bf16MacExpr`, and wire-factored linear-size `bf16MulWire`/`bf16AddWire`/`bf16MacWire` DAG builders. ### Added -- **4-Stage Pipelined `PipedTileCore` on `lambda-hdl` v0.4** ([PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean)): +- **4-Stage Pipelined `PipedTileCore` on `lambda-hdl` v0.4** ([PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean)): - 4-stage pipeline (`IF → ID/RF → EX → WB`) with non-blocking warp replay on Stage 1 scoreboard/queue hazards (zero head-of-line blocking across warps!). - **19 explicit `MemKind.syncBRAM` memories** (`imem`, 2×`sgpr`, 12×`vgpr`, 4-bank `smem`) inferring **15 true Xilinx Block RAMs (`1 × RAMB36E1` + `14 × RAMB18E1`)** and **9.88× fewer LUTRAMs** (`128` vs. `1,264`). - **External 128-bit Split-Transaction DRAM Bus** with 4-warp concurrent non-blocking `LDG`, pipelined 4-beat `DMA_PUSH`, and automatic coalesced / broadcast / scattered LSU serialization. - **K-Pipelined Matrix Engine** (`4 INT32 + 4 BF16 MACs/cycle`, 16 cycles/tile) supporting BOTH `W_MMA_I8` AND native **`W_MMA_BF16`** — guided by `LambdaHDL.Estimate.reportPPA` to cut critical-path depth by **2.79×** (`162 → 58` est. LUT-eq) and `DSP48E1` count from `112 → 48`! - **Direct Core-to-Core `TILE_SEND` Hardware Tile NoC TX/RX** streaming 4×4 tiles straight from `TMEM` into remote `Q0`/`Q1` with **0 DRAM bytes spilled**. - Formal `HAssert` invariants on `TQUEUE` occupancy/allocation + in-Lean static PPA & Bluespec/Koika Rule Schedule report (`39` atomic rules, `673/741` pairs Conflict-Free!). -- **True Hierarchical 2×2 Multi-Core Mesh (`LambdaMesh2x2`)** ([Mesh2x2.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/Mesh2x2.lean)): +- **True Hierarchical 2×2 Multi-Core Mesh (`LambdaMesh2x2`)** ([Mesh2x2.lean](LambdaGPU/HDL/Mesh2x2.lean)): - Instantiates `4 × PipedTileCore` (`u_core0`..`u_core3`) via `SubModInst` (preserving module boundaries through CIRCT `firtool`, `213 KB` vs. Sparkle's `631 KB` flattened monolith!). - 1-cycle registered 4×4 Direct Hardware Tile NoC router. diff --git a/README.md b/README.md index 9ac21a4..a635177 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,94 @@ -# `lambda-gpu` (λ-GPU) v2.7 - -**A from-scratch, zero-CPU-compromise, formally verified 4-Core 64-bit Tile-Dataflow + SIMT Compute GPU SoC (`λISA-64`) with a 6-Stage `PipedTileCore`, Direct Z3-Verified `TileScoreboardCtrl` (`u_sb`) Submodule, 4-Stage Mixed-Precision `BF16 × BF16 → FP32` Tensor Core, True Multi-Block Online-Rescaling FlashAttention-2 (`4x8`, 0.86% rel error vs. IEEE `float64`, ZERO extra DSPs!), 4-Beat `ARLEN=3` 64-Byte ARM AXI4 Burst Interconnect (4× fewer `AR`s!), Universal End-to-End Compiler Correctness Proof (all $2^{1024}$ 4×4 matrices), Yosys Pure-I/O Miter Backend LEC, Native Compiled CIRCT `arcilator` C++ Execution (`2.527 MHz sim`, 40/40 bit-exact!), and `69.88 MHz` Real Post-Route Lattice ECP5-85F Timing — built in Lean 4 on [`lambda-hdl`](https://github.com/unbalancedparentheses/lambda-hdl) v0.11 (ZERO Sparkle, ZERO `sorry`, 55 Lean 4 theorems + 10/10 Z3 CEC/BMC/k-Ind + 4/4 Yosys LEC + Verilator + `arcilator` + Yosys + `nextpnr-ecp5` verified).** - ---- - -## Architectural & Soundness Highlights (v2.7) - -- **100% Native 64-bit GPU ISA (`λISA-64`)** — Zero RISC-V/CPU compromise: 4-bit SASS async barrier `waitMask`, 2-bit `depBar`, 3-bit lane predication, unified operands, `V_MAC`, `V_DP4A`, `V_SHFL`, RDNA `S_AND_SAVEEXEC`/`XOR`/`OR`, full **Softmax FlashAttention-2 ML Vector Ops (`V_BF16_RELU`, `V_BF16_MAX`, `V_FP32_TO_BF16`, `V_BF16_TO_FP32`, `V_FP32_MAX`, `V_BF16_EXP2`, `V_BF16_RCP`, `V_BF16_ADD`, `V_BF16_SUB`, `V_BF16_MUL`)**, `DMA_PUSH` (with 4-beat `ARLEN=3` 64-byte bursts!), `W_MMA_I8`, **`W_MMA_BF16`**, **`W_MMA_BF16_F32`**, `T_CLEAR`, `T_MOV`, and **`TILE_SEND`**. -- **6-Stage `PipedTileCore` + 4-Stage FP32 Tensor Core + Direct `TileScoreboardCtrl` (`u_sb`) — `69.88 MHz` Post-Route ECP5-85F!** ([PipedTileCore.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/PipedTileCore.lean), [BF16.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/BF16.lean), [ScoreboardBMC.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/ScoreboardBMC.lean)): - - **Real Post-Route Timing Closure**: EX0/EX1 split of `bf16Add` + EX0 precompute of `EXP2`/`RCP`/`EA`, 4-stage Matrix Engine (`M0A [TQUEUE Mux] → M0B [Pure FF → MULT18X18D] → M1 [Dual-Path Align + Add/Sub] → M2 [CLZ + Norm + WB]`), and parallel-speculative exponent precompute push real post-route 40nm ECP5-85F `Fmax` to **`69.88 MHz`** (`5.79 ns` logic + `8.52 ns` routing, **+55.4% faster than v2.2**) and cut Xilinx `ABC9` mapped LUT depth to **`lev = 15` (avg `1.35`), `levB = 19`**! - - **Zero Model-Extraction Gap**: `PipedTileCore` directly instantiates the Z3-verified `TileScoreboardCtrl` (`submod "u_sb" tileScoreboardCtrl`) for `TQUEUE` (`Q0`/`Q1`) and `W_MMA` occupancy control! - - **Two Proved DSP-Sharing Theorems (`bf16MulToFp32_hi16_eq_bf16Mul` & `bf16MulFromProd_eq_bf16Mul`)**: proved via `bv_decide` across all $2^{32}$ inputs — ONE shared 4-wide matrix multiplier array powers BOTH `W_MMA_BF16` and `W_MMA_BF16_F32`, AND Stage EX0's existing integer lane multipliers power `V_BF16_MUL`, keeping **ZERO extra DSPs** (**48 `DSP48E1`** / **48 `MULT18X18D`**)! - - **15 true Xilinx Block RAMs** (`1 × RAMB36E1` + `14 × RAMB18E1`) via `lambda-hdl`'s explicit `MemKind.syncBRAM` (**9.88× fewer LUTRAMs** than Sparkle v1). -- **Full SoC-Ready 4-Core GPU (`LambdaMesh2x2SoC`) with 4-Beat `ARLEN=3` AXI4 Bursts** ([Mesh2x2SoC.lean](file:///home/unbalancedparen/projects/lambda-gpu/LambdaGPU/HDL/Mesh2x2SoC.lean)): - - Preserves **14 true hierarchical submodules** through **CIRCT `firtool 1.163.0`** AND compiles cleanly to **CIRCT `arcilator` LLVM IR** (`29,334` lines for the full 4-core SoC, `9,138` lines for `PipedTileCore`): `4 × (PipedTileCore + TileScoreboardCtrl u_sb)` + Direct 4×4 Hardware Tile NoC + `4 × SplitToAXI4Bridge` (with 4-beat `ARLEN=3` burst reads!) + `1 × AXI4Mux4` (unified 128-bit ARM AXI4 DRAM Master) + `1 × AXI4LiteCSR` (32-bit ARM AXI4-Lite Host Control & Telemetry CSRs with auto-generated `gen/gpu_soc_csr.h`). - - **72 live RTL `HAssert` invariants** checked simultaneously during Verilator simulation! -- **3-Way Independent Bit-Exact Verification & Closed-Loop Formal Soundness**: - - **3 Independent Simulators**: **Lean 4 Golden Oracle ≡ Verilator 5.054 (`80/80` PASS) ≡ Native Compiled CIRCT `arcilator` LLVM IR (`40/40` PASS at `2.527 MHz sim`!)**. - - **55 zero-`sorry` Lean 4 theorems** (`Audit.lean`), including **`compileGemm4x4_end_to_end_spec`** (universal end-to-end 16-step matrix-multiply correctness over all $2^{1024}$ 4×4 inputs!) + **5/5 injected GPU bugs rejected** at compile time ([bug_injection_test.sh](file:///home/unbalancedparen/projects/lambda-gpu/scripts/bug_injection_test.sh)). - - **Live Z3 CEC + RTL BMC + Unbounded $k$-Induction**: **10/10 positive Z3 proofs `unsat`** (8 CEC including parallel-speculative BF16/FP32 + 16-cyc RTL BMC + Unbounded $k$-Induction on live `TileScoreboardCtrl`) + **2/2 non-vacuity mutants `sat`**! - - **GPU End-to-End Backend LEC (`make lec`)**: proves **`Direct SV ≡ CIRCT firtool SV`** via Yosys 8-cycle pure-I/O miter SAT across **4/4 GPU controller & SoC interconnect modules** + **1/1 mutant REJECTED**! - ---- - -## Verified Benchmark, SoC, PPA & Real Post-Route Timing Results (v2.7) - -### 1. Three-Way Bit-for-Bit Verification & Simulator Throughput (`Verilator 5.054` vs. `CIRCT arcilator`) -All **20 kernels × {1-cycle DRAM, 50-cycle DRAM}** PASS bit-for-bit across **CIRCT `firtool` SV (Verilator, 40/40)**, **Direct SV (Verilator, 40/40)**, AND **Native Compiled CIRCT `arcilator` LLVM IR (`clang++ -O3`, 40/40)** = **120/120 single-core runs PASS**! - -- **Head-to-Head Simulator Throughput (`make arcilator-bench`, 100× 20-Kernel Suite = `652,600` GPU cycles)**: - - **CIRCT `arcilator` (`clang++ -O3`)**: **`652,600` cycles in `258.23 ms` → `2.527 MHz` (`2,527.2 kCycles/sec`)** - - **Verilator 5.054 (`-O3`)**: **`652,600` cycles in `260.36 ms` → `2.507 MHz` (`2,506.5 kCycles/sec`)** -- **`flash_online_attn_4x8`** (True Multi-Block Online-Rescaling FlashAttention-2 across 2 × 4×4 K/V blocks): **`1,456 cyc`** @ 1c / **`1,648 cyc`** @ 50c DRAM (`256` mixed-precision `W_MMA_BF16_F32` MACs + running `(m, l, O)` SMEM rescaling), independent IEEE-754 `float64` accuracy **`max|O_hw - O_f64| = 0.0066` (`0.86%` rel)**! -- **`flash_softmax_attn_4x4`** (Single-Block Mixed-Precision Online-Softmax FlashAttention-2): **`536 cyc`** @ 1c / **`632 cyc`** @ 50c DRAM (`128` mixed-precision MACs), IEEE-754 `float64` **`max|rowSum(P) - 1| = 0.0159`**, **`max|O_hw - O_f64| = 0.0290` (`1.65%` rel)**! -- **`tileGemm_4x4_wmma`** (50c DRAM): **`166 cyc`** vs. `matMul_4x4_simt` (`2,692 cyc`) → **`16.22×` faster** (**`AXI4 AR = 2`**, 4× burst reduction!) -- **`latHide_4warp_16w`** (50c DRAM): **`223 cyc`** vs. `latHide_1warp_16w` (`688 cyc`) → **`3.09×` SIMT latency hiding** -- **`tiledGemm_4x16x4_2warp_spec`** (50c DRAM): **`321 cyc`** vs. 1-warp (`504 cyc`) → **`1.57×` double-buffered overlap** - -### 2. Full 4-Core GPU SoC (`LambdaMesh2x2SoC_firtool.sv`) — AXI4-Lite Host CSRs + 4-Beat `ARLEN=3` 128-Bit AXI4 DRAM -Heterogeneous multi-head 4-core workload (`Core 0: Q×Kᵀ --NoC--> Core 1: S×V --NoC--> Core 2: O×W_O → DRAM` + concurrent **`Core 3: Live Online-Softmax FlashAttention-2 (BF16 → FP32)`**) driven purely via **ARM AXI4-Lite CSRs** over a **single shared 128-bit AXI4 DRAM bus** with live staggered backpressure: -- **1-Cycle DRAM**: **`573` wall cyc** | CSR `mma=320`, `ret=110` | **`AXI4 AR=8`** (**4.0× fewer ARs!**), `AW=12, W=12, B=12` | **`CoreWr=[0,0,4,8]` (0 DRAM bytes spilled for `S` & `O`!)** | **0/72 `HAssert` violations** | **PASS** -- **50-Cycle DRAM**: **`672` wall cyc** | CSR `mma=320`, `ret=110` | **`AXI4 AR=8`** (**4.0× fewer ARs!**), `AW=12, W=12, B=12` | **`CoreWr=[0,0,4,8]` (0 DRAM bytes spilled!)** | **0/72 `HAssert` violations** | **PASS** - -### 3. Yosys Xilinx 7-Series PPA & Real Post-Route Lattice ECP5-85F Timing - -| Metric | Sparkle v1 Unpipelined `lambdaTileCore` | `lambda-hdl` v2.2 (4-Stage) | `lambda-hdl` v2.5 (6-Stage) | **`lambda-hdl` v2.7 (6-Stage + 4-Stage MMA + Speculative BF16/FP32)** | Delta vs. v1 / v2.2 | -|---|---:|---:|---:|---:|---:| -| **Xilinx 7-Series LCs (`synth_xilinx -family xc7`)** | 8,867 | 8,873 | 11,501 | **11,900** | Full FP32 Tensor Core + Softmax + `u_sb` + 4-Beat Burst | -| **Xilinx `DSP48E1` Slices** | 112 | 48 | 48 | **48** | **`2.33×` fewer DSPs (0 extra for FP32 + Softmax!)** | -| **True Xilinx Block RAMs** | **0** | 15 | 15 | **`15` (`1 RAMB36E1` + `14 RAMB18E1`)** | **Real BRAMs for IMEM, SGPR, VGPR** | -| **Distributed LUTRAMs** | 1,264 | 128 | 128 | **128 (`RAM64X1S`)** | **`9.88×` fewer LUTRAMs** | -| **Flip-Flops / Latches** | 1,543 / 0 | 3,755 / 0 | 5,474 / 0 | **5,991 / 0** | **0 latches** | -| **Yosys `ABC9` Pre-Map AIG Depth (`lev`, avg)** | 107 (avg 11.15) | 52 (avg 3.43) | 45 (avg 2.64) | **38 (avg 2.35)** | **`2.82×` peak / `4.74×` avg shallower than v1!** | -| **Yosys `ABC9` Mapped LUT Depth (`lev`, avg)** | 27 (avg 3.33) | 20 (avg 1.69) | 17 (avg 1.48) | **15 (avg 1.35), `levB = 19`** | **`1.80×` peak / `2.47×` avg shallower than v1!** | -| **Real Post-Route FPGA `Fmax` (`nextpnr-ecp5`, ECP5-85F-8)** | — | 44.96 MHz (`10.36ns` logic) | 54.15 MHz (`6.78ns` logic) | **`69.88 MHz`** (**`5.79ns` logic** + `8.52ns` route; `27%` LUT4, `8%` FF) | **`+55.4%` vs v2.2 (`+29.0%` vs v2.5)!** | - ---- - -## Quick Start +# `lambda-gpu` (λ-GPU) v2.8 + +A from-scratch, formally verified 4-core 64-bit tile-dataflow + SIMT compute GPU SoC with its own ISA (`λISA-64`), written in Lean 4 on [`lambda-hdl`](https://github.com/unbalancedparentheses/lambda-hdl) v0.18. + +- **Core**: 6-stage `PipedTileCore` with a 4-stage mixed-precision `BF16 × BF16 → FP32` tensor core and a Z3-verified `TileScoreboardCtrl` submodule (`u_sb`). +- **SoC**: 2×2 mesh of cores over a hardware tile NoC, a 128-bit ARM AXI4 DRAM master with 4-beat (`ARLEN=3`) bursts, and AXI4-Lite host CSRs. +- **Workloads**: 20 kernels including INT8/BF16 WMMA GEMM and single- and multi-block online-softmax FlashAttention-2. +- **Verification**: 57 audited Lean theorems (zero `sorry`), including end-to-end compiler correctness for 4×4 GEMM over all inputs; Z3 CEC/BMC/k-induction; Yosys LEC of the direct vs. CIRCT backends; three-way bit-exact simulation (Lean golden model, Verilator, CIRCT `arcilator`). +- **Timing**: 69.88 MHz post-route on a Lattice ECP5-85F (`nextpnr-ecp5`). + +## Quick start ```bash nix develop -make all # Build Lean + 55 proofs + static check + FIRRTL/SV + CIRCT firtool + Verilator (Core + Mesh + AXI4 Core + Full 4-Core SoC) + 8/8 Z3 CEC + RTL Z3 BMC/k-Ind + 4/4 Yosys LEC + Compiled CIRCT arcilator C++ Execution (40/40) + Axiom Audit + 5/5 Bug-Injection Audit -make arcilator-bench # Run head-to-head 652,600-cycle throughput benchmark: CIRCT arcilator (-O3) vs Verilator 5.054 (-O3) -make yosys # Run Yosys Xilinx 7-series PPA & ABC9 timing comparison (Sparkle v1 vs lambda-hdl v2.7) -make pnr # Run real Lattice ECP5-85F Place-and-Route timing via yosys + nextpnr-ecp5 --freq 80 +make all # proofs, codegen, firtool, Verilator, Z3, LEC, arcilator, audit, bug injection +make verilator-direct # Verilator on the direct (non-firtool) SV backend +lake exe lambda-gpu-gemm-refinement # 32-schedule variable-latency GEMM refinement +make arcilator-bench # arcilator vs. Verilator throughput +make yosys # Yosys Xilinx 7-series PPA +make pnr # ECP5-85F place & route ``` + +`lambda-hdl` is fetched by Lake at the revision pinned in [`lake-manifest.json`](lake-manifest.json). + +## Architecture + +- **ISA (`λISA-64`)** ([ISA.lean](LambdaGPU/Spec/ISA.lean)): native 64-bit GPU ISA, not RISC-V based. SASS-style async barrier `waitMask` and `depBar`, 3-bit lane predication, RDNA-style `S_AND_SAVEEXEC`/`XOR`/`OR`, `V_MAC`, `V_DP4A`, `V_SHFL`, BF16/FP32 vector ops for softmax (`V_BF16_EXP2`, `V_BF16_RCP`, `V_BF16_MAX`, `V_FP32_MAX`, conversions, add/sub/mul/relu), `DMA_PUSH`, `W_MMA_I8`, `W_MMA_BF16`, `W_MMA_BF16_F32`, `T_CLEAR`, `T_MOV`, `TILE_SEND`. +- **`PipedTileCore`** ([PipedTileCore.lean](LambdaGPU/HDL/PipedTileCore.lean), [BF16.lean](LambdaGPU/HDL/BF16.lean)): + - 6-stage pipeline with an EX0/EX1 split of `bf16Add`, plus EX0 precompute of `EXP2`, `RCP` and effective addresses. + - 4-stage matrix engine: `M0A` (TQUEUE mux) → `M0B` (`MULT18X18D`) → `M1` (dual-path align + add) → `M2` (CLZ + normalize + writeback). + - It instantiates the same `TileScoreboardCtrl` that Z3 verifies (`submod "u_sb"`), so there is no model-extraction gap for TQUEUE/MMA occupancy control. + - DSP sharing: `bf16MulToFp32_hi16_eq_bf16Mul` and `bf16MulFromProd_eq_bf16Mul` prove that one multiplier array serves both `W_MMA_BF16` and `W_MMA_BF16_F32`, and that the EX0 integer lane multipliers serve `V_BF16_MUL`. As a result FP32 and softmax add no DSPs (48 total). +- **4-core SoC** ([Mesh2x2SoC.lean](LambdaGPU/HDL/Mesh2x2SoC.lean)): + - 4 × (`PipedTileCore` + `u_sb`), a direct 4×4 tile NoC, 4 × `SplitToAXI4Bridge`, `AXI4Mux4` and `AXI4LiteCSR`. It also generates the host header `gen/gpu_soc_csr.h`. + - The hierarchy survives CIRCT `firtool`, and the design compiles to `arcilator` LLVM IR. + - Live `HAssert` protocol and occupancy invariants are checked during Verilator simulation. + +## Verification + +| Check | Command | Result | +|---|---|---| +| Lean proofs + axiom audit | `make proofs audit` | 57 theorems, no `sorryAx` | +| Bug injection | `make bug-inject` | 5/5 injected bugs rejected | +| Z3 CEC / RTL BMC / k-induction | `make cec bmc` | 10/10 `unsat`, 2/2 mutants `sat` | +| Backend LEC (direct SV ≡ firtool SV) | `make lec` | 4/4 modules equivalent, 1/1 mutant rejected | +| Verilator, firtool + direct SV | `make verilator verilator-direct` | 80/80 kernel runs bit-exact vs. Lean golden | +| CIRCT `arcilator` | `make arcilator` | 40/40 kernel runs bit-exact | +| AXI4 core with backpressure | `make verilator` | 10/10 runs, 0 `HAssert` violations | +| 4-core SoC | `make verilator` | 1c and 50c DRAM pass, 0 DRAM spill for `S`/`O`, 0 `HAssert` violations | +| GEMM refinement | `lake exe lambda-gpu-gemm-refinement` | 32/32 memory schedules match the ISA | + +Notable theorems: +- **`compileGemm4x4_end_to_end_spec`**: the compiled 16-step GEMM program computes the 4×4 matrix product for all 2^1024 inputs. +- **`writes_of_matchesISA`** ([GemmRefinement.lean](LambdaGPU/Examples/GemmRefinement.lean)): lifts each passing HDL run, under any DMA latency and backpressure schedule, to the mathematical product. + +**Trusted base.** The audit reports only the standard axioms (`propext`, `Classical.choice`, `Quot.sound`) plus `bv_decide`'s native axioms. 13 theorems are proved with `bv_decide`, and Lean records 44 `…_native.bv_decide.ax_*` axioms for them; those rely on the SAT solver and LRAT checker being run natively, not checked by the Lean kernel. Affected: the BF16 multiply/DSP-sharing lemmas, EXEC divergence and predication, the barrier drain, and the round-robin scheduler proofs. + +## Results + +Cycle counts are from Verilator (`make verilator`) with 1-cycle / 50-cycle DRAM. + +| Kernel | 1c | 50c | Note | +|---|---:|---:|---| +| `tileGemm_4x4_wmma` | 118 | 166 | 16.2× faster than `matMul_4x4_simt` (2,692) at 50c; 2 AXI4 `AR`s | +| `flash_softmax_attn_4x4` | 536 | 632 | 128 mixed-precision MACs; 1.65% rel. error vs. IEEE `float64` | +| `flash_online_attn_4x8` | 1,456 | 1,648 | 2 K/V blocks with online rescaling; 0.86% rel. error vs. `float64` | +| `latHide_4warp_16w` | 150 | 223 | 3.09× vs. 1 warp (688) at 50c | +| `tiledGemm_4x16x4_2warp_spec` | 269 | 321 | 1.57× vs. 1 warp (504) at 50c | + +**4-core SoC**: a heterogeneous multi-head attention workload. Core 0 computes Q×Kᵀ, passes it over the NoC to core 1 (×V), which passes it to core 2 (×W_O → DRAM). Core 3 runs online-softmax FlashAttention-2 concurrently, and the host drives everything over AXI4-Lite. + +| DRAM latency | Wall cycles | AXI4 AR / AW / W / B | Core writes | +|---|---:|---|---| +| 1 cycle | 573 | 8 / 12 / 12 / 12 | `[0,0,4,8]` | +| 50 cycles | 771 | 8 / 12 / 12 / 12 | `[0,0,4,8]` | + +**Simulator throughput** (`make arcilator-bench`, 652,600 GPU cycles, measured at v2.7): `arcilator` + `clang++ -O3` runs at 2.527 MHz; Verilator 5.054 `-O3` at 2.507 MHz. + +**PPA and timing** (`PipedTileCore` + `u_sb`, measured at v2.7): + +| Metric | Sparkle v1 (unpipelined) | v2.2 (4-stage) | v2.5 (6-stage) | v2.7 | +|---|---:|---:|---:|---:| +| Xilinx 7-series LCs | 8,867 | 8,873 | 11,501 | 11,900 | +| `DSP48E1` | 112 | 48 | 48 | 48 | +| Block RAMs | 0 | 15 | 15 | 15 (1 × RAMB36E1 + 14 × RAMB18E1) | +| LUTRAMs | 1,264 | 128 | 128 | 128 | +| FFs / latches | 1,543 / 0 | 3,755 / 0 | 5,474 / 0 | 5,991 / 0 | +| ABC9 pre-map AIG depth (avg) | 107 (11.15) | 52 (3.43) | 45 (2.64) | 38 (2.35) | +| ABC9 mapped LUT depth (avg) | 27 (3.33) | 20 (1.69) | 17 (1.48) | 15 (1.35) | +| ECP5-85F post-route Fmax | — | 44.96 MHz | 54.15 MHz | 69.88 MHz | + +At 69.88 MHz the critical path is 5.79 ns of logic plus 8.52 ns of routing. The design uses 27% of the ECP5's LUT4s, 8% of its FFs and 48/156 `MULT18X18D`. + +See [CHANGELOG.md](CHANGELOG.md) for the full history. diff --git a/lake-manifest.json b/lake-manifest.json index bcee3eb..040cd81 100644 --- a/lake-manifest.json +++ b/lake-manifest.json @@ -1,12 +1,15 @@ {"version": "1.2.0", "packagesDir": ".lake/packages", "packages": - [{"type": "path", + [{"url": "https://github.com/unbalancedparentheses/lambda-hdl", + "type": "git", + "subDir": null, "scope": "", + "rev": "d746a1aaf20e5a7fd198a31f212fcf58eba26326", "name": "«lambda-hdl»", "manifestFile": "lake-manifest.json", + "inputRev": "d746a1a", "inherited": false, - "dir": "../lambda-hdl", "configFile": "lakefile.lean"}], "name": "«lambda-gpu»", "lakeDir": ".lake", diff --git a/lakefile.lean b/lakefile.lean index 5536c2b..cea855c 100644 --- a/lakefile.lean +++ b/lakefile.lean @@ -4,7 +4,8 @@ open Lake DSL package «lambda-gpu» where version := v!"0.2.0" -require «lambda-hdl» from "../lambda-hdl" +require «lambda-hdl» from git + "https://github.com/unbalancedparentheses/lambda-hdl" @ "d746a1a" @[default_target] lean_lib «LambdaGPU» where