File size: 5,655 Bytes
fb6457c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | # Binary Substrate Harness β Complete Architecture Specification
## Executive Summary
The Binary Substrate Harness (BSH) is a static, zero-dependency, ahead-of-time compiled computational environment for transformer inference. It eliminates dynamic memory allocation, garbage collection, and runtime introspection. The architecture operates exclusively on pre-allocated, contiguous virtual memory pages. All tensor geometries and execution graphs are resolved during the reduction phase, leaving a purely deterministic, flattened instruction pipeline.
---
## 1. Recursive Dependency Graph & Decomposition
The framework abstraction collapses through the following rigid reduction hierarchy:
```
1. NEURAL NETWORK (layers + learned parameters)
β (unwrap into sequential affine transforms)
2. MODEL (static DAG of tensor operations)
β (express as topologically sorted operations)
3. GRAPH (memory-mapped buffer order)
β (flatten each tensor to 1D contiguous space)
4. TENSOR (multi-dimensional array)
β (unfold as loop nest over strides)
5. OPERATOR (loops with memory access patterns)
β (block into register-sized tiles)
6. MATRIX/VECTOR (SIMD register tiles)
β (IEEE 754 bit pattern)
7. SCALAR (32-bit or 16-bit float)
β (ALU bitwise logic)
8. INTEGER/BIT (machine operations)
β (hardware instruction)
9. INSTRUCTION (x86_64/ARM64/SASS opcode)
β (state of CPU registers + condition codes)
10. MACHINE STATE (architectural state)
```
**Key Property**: At each level, all abstractions are fully reduced. The system cannot be simplified further without breaking the I/O state model.
---
## 2. Neural-Operation Lowering Rules
### 2.1 Softmax Recursion
**Mathematical Definition**:
```
softmax(x_i) = e^(x_i) / Ξ£_j e^(x_j)
```
**Hardware Lowering**:
1. Base conversion: e^x = 2^(xΒ·logβ(e))
2. Range reduction: 2^(I+F) = 2^I Γ 2^F
3. 2^I implemented as integer addition to IEEE 754 exponent bias
4. 2^F implemented via 3rd-degree minimax polynomial + FMA instructions
**Critical**: No libm calls, no transcendental lookups. Pure minimax polynomial evaluation = deterministic latency.
### 2.2 Scaled Dot-Product Attention
```
Attention(Q, K, V) = softmax(QK^T / βd_k) V
```
**Lowering**:
- Collapse to GEMM (General Matrix Multiplication)
- GEMM β Macro-kernel (L2 blocking) β Micro-kernel (L1 blocking) β Inner loop
- Inner loop: Unrolled independent outer products via SIMD
- No matrix abstraction at runtime; only register streams
---
## 3. Deterministic State Model
**State Transition**:
```
S_{t+1} = Ξ¦(S_t, I_t)
```
Where:
- S: Memory state (buffer contents)
- I: Verified input payload (with provenance header)
- Ξ¦: Static neural transformation
**Invariant**: Identical (S_0, I_{0...n}) β identical output (bit-for-bit) on compatible microarchitectures.
---
## 4. SYSCALL ABI & Assembly Boundary
**Register Layout** (x86_64 System V):
```
%rax: Syscall number (also return value)
%rdi: Arg 1 (e.g., fd)
%rsi: Arg 2 (e.g., buffer pointer)
%rdx: Arg 3 (e.g., count/size)
%r10: Arg 4 (replaces %rcx)
%r8: Arg 5
%r9: Arg 6
```
**Permitted Syscalls**:
1. `sys_read (0x00)`: Ingest input payloads
2. `sys_write (0x01)`: Emit inference results
3. `sys_mmap (0x09)`: Allocate memory regions
4. `sys_exit (0x3C)`: Terminate execution
---
## 5. Primitive Operation Inventory
**18 x86_64 Mnemonics**:
Control Flow:
- `jmp`, `je`, `jne`, `syscall`
Memory Movement:
- `mov`, `vmovaps`, `vmovups`, `vbroadcastss`
Scalar/Integer:
- `add`, `sub`, `imul`, `shl`, `shr`, `and`, `or`
Vector/SIMD:
- `vaddps`, `vsubps`, `vmulps`, `vfmadd231ps`, `vmaxps`
---
## 6. Memory Layout
```
0x0000000000400000 β ELF Header + .text (14.2 KB)
β _start, sys_mmap bootstrap
β gemm_micro_kernel, softmax_fma_loop
ββββββββββββββββββββββββββββββββββ
0x0000000000500000 β .rodata (Read-Only)
β Minimax Polynomial Coefficients
β Static Model Weights
ββββββββββββββββββββββββββββββββββ
0x0000000000600000 β .bss (Read-Write, Uninitialized)
β Ingestion Buffer (4 KB)
ββββββββββββββββββββββββββββββββββ
0x0000000000601000 β Execution Arena (960 KB)
β K/V Cache, Temp buffers
ββββββββββββββββββββββββββββββββββ
0x00000000006F0000 β Output Buffer (4 KB)
ββββββββββββββββββββββββββββββββββ
```
---
## 7. Fixed-Point Analysis
**99% Template Saturation**: System reached irreducible substrate.
Abstractions removed:
- Python GIL
- PyTorch Autograd engine
- CUDA runtime initialization
- Dynamic shape inference
- cuBLAS heuristic dispatcher
- Threading pools
- Garbage collector
Remaining dependencies: Bare-metal kernel ABI only.
---
## 8. Reproducible Build Procedure
```bash
# 1. Offline tensor compiler (PyTorch β C/Assembly DAG)
python3 lower_model.py model.pt --output harness_dag.s
# 2. Assemble
as -mcpu=native harness_dag.s -o harness.o
# 3. Link (no libc, no dynamic linking)
ld -nostdlib -static harness.o -o BSH_Twin_v1.bin
# 4. Verify determinism
sha256sum BSH_Twin_v1.bin
# Compare against declared manifest
```
---
**Last Updated**: 2026-09-27
**Version**: 1.0
**Status**: Specification Complete
|