Bare-metal-style LLM inference engine written from scratch in pure C + Cell SPU intrinsics for a 2006 Sony PlayStation 3 (Cell Broadband Engine: 1 PowerPC PPE + 6 Synergistic Processing Elements, 215 MiB usable XDR DRAM).
- Zero
llama.cpp, zero CUDA, zero Python runtime, zero ML frameworks 150.72 tok/speak decode (139.5–150.7 tok/sacross--bench 7runs) and**185.8 tok/s** prefill runningSmolLM2-135M-Instruct(Q4) 100% resident in PS3 XDR DRAM137.0×faster than tuned 2-thread upstreamllama.cpp(1.10 tok/s) on the exact same PlayStation 3 —655×faster than defaultllama.cpp(0.23 tok/s), and**162×faster** than the PS3 PPE-O3baseline (0.93 tok/s)17.36 GB/ssustained LM-head XDR DRAM bandwidth (0.09%imbalance across all 6 SPEs) with**25,288 bytes(24.7 KiB)** of SPU.textmachine code (156.8 KiB / 256 KiBLocal Store) vs12 MBstrippedllama.cpp- Compiles natively on the PS3 in ~2 seconds (vs ~60 min for upstream
llama.cpp)
Hardware: 2006 Sony PlayStation 3 (Linux 6.12.62 ppc64, Cell Broadband Engine 3.192 GHz, 6 active SPUs, 79.8 MHz decrementer, 215 MiB visible XDR DRAM).
Model: HuggingFaceTB/SmolLM2-135M-Instruct (30 layers, dim=576, hidden=1536, GQA 9/3, vocab=49,152, 4-bit block-32 quantization, MAX_SEQ=512 Q8 KV cache).
| Metric | Upstream llama.cpp (ee46715 , 2-thr best) |
cell-llm (PPE-O3 baseline) |
cell-llm v5 (6× SPE fp32) |
cell-llm v6 (6× SPE int mpya + 128B DMA) |
Speedup vs llama.cpp |
|---|---|---|---|---|---|
| Peak Decode Speed | 1.10 tok/s (908.9 ms/tok )* |
0.93 tok/s (1,074 ms/tok ) |
105.6 tok/s (9.5 ms/tok ) |
150.72 tok/s ( 6.63 ms/tok ) |
137.0× |
Sustained Mean (--bench 7) |
1.10 tok/s |
0.93 tok/s |
94.8–101.3 tok/s |
139.5–139.6 tok/s ( 150.6 peak)** |
126.9× |
| Prefill (41 tokens) | 29.45 s (1.39 tok/s ) |
37.2 s (1.1 tok/s ) |
0.40 s (101.7 tok/s ) |
0.22 s (185.8 tok/s) |
133.7× |
| Model Load Time | 33.36 s (BE GGUF) |
~6 s |
5.3–8.3 s (mlock() ) |
5.3–8.3 s ( mlock() ) |
4.0× – 6.3× |
| Weight File Size | 85.93 MiB (Q4_0 BE GGUF) |
80.29 MiB (CELL-Q4_32 ) |
80.29 MiB (CELL-Q4_32 ) |
80.29 MiB (CELL-Q4_32) |
1.07× smaller |
| Context / KV Cache | fp16 KV | fp32 KV | 256 tok (11.8 MiB fp32) |
512 tok (7.03 MiB Q8) |
2× ctx /40% less RAM |
SPU .text / Binary |
12 MB stripped (18 MB raw) |
67 KB |
12.6 KiB``.text (82 KB total) |
24.7 KiB .text (<100 KB total) |
>120× smaller |
| Native PS3 Compile | ~60 min |
~1.4 s |
~2.0 s |
~2.5 s |
~1,440× faster |
*Upstream llama.cpp compiled natively on the PS3 with libggml/ libggml-cpu at -O3 -mcpu=cell -mtune=cell (PowerPC AltiVec quants enabled) and endian-swapped SmolLM2-135M-Instruct-Q4_0-BE.gguf. Default n_threads=4 scored 0.23 tok/s (4,380 ms/tok, 655× slower than v6); n_threads=1 scored 1.03 tok/s; n_threads=2 (matching the PPE's 2 SMT threads) was llama.cpp's best score at 1.10 tok/s.
**Measured with --bench 7 on the live PS3 desktop (which wakes once per second for the status bar, dipping ~2 of 7 runs to 124–132 tok/s while clean runs consistently hit 150.2–150.7 tok/s).
Per-Token Millisecond Breakdown (v6, --profile at 147.3 tok/s / 6.79 ms/tok; 6.63 ms/tok unprofiled)
- 30-Layer Q4×Q11 Integer MatVec (
QKV,W_o, fusedgate+up+SwiGLU,W_down):4.89 ms - Tied LM Head (
49,152 × 576) + In-SPE SIMD Argmax + Rep Penalty:1.07 ms(17.36 GB/ssustained XDR DRAM across 6 SPEs) - 6-SPE GQA-Paired Q8 FlashAttention-2 (GQA
9/3,head_dim=64):0.45 ms - Standalone SwiGLU Dispatch:****
0.00 ms(100% fused intoCELL_CMD_GATE_UP_SWIGLU) - PowerPC AltiVec RoPE + Fused Residual
add_rmsnorm(PPE):0.30 ms(0.09 msRoPE +0.21 msnorm) - 6-SPE Hardware Decrementer Balance (
79.8 MHz, LM head):81,332–81,595ticks (0.09%spread acrossSPE0–SPE5)
- Native Big-Endian
CELL-Q4_32Weight Format (tools/convert_cellq4.c): - Packs 4 output rows × 32 input columns into an 80-byte, 16-byte-DMA-aligned tile (4fp32scales + 64 bytes of packed 4-bit nibbles,5.0bits/weight).
- Zero byte-swapping on big-endian
ppc64;mlock()pins the entire80.29 MiBweight buffer in physical XDR DRAM so Linux never pages out a layer.
- Packs 4 output rows × 32 input columns into an
- Integer
Q4 × Q11SPUmpya/mpyhhaMatVec (spu/cell_llm_spu.c): - Quantizes the activation vectorxto 11-bit signedint16pairs (xl = q << 4matchingpk & 0x0F,xh = qmatching unshiftedpk & 0xF0 = 16 * hi), eliminating all32`` cufltinstructions and all4`` rotmnibble shifts per tile while cuttingshufbin half (32 → 16).
- Uses 8 dual
int32accumulators (spu_mule/spu_mulo/spu_mhhadd/spu_madd) to completely hide the SPU's 7-cycle integer multiply latency.
- Quantizes the activation vector
- 128-Byte Cell Cache-Line DMA Alignment + 4-Deep Power-of-2 Ring: - Clamps each SPE's tile batch size to a multiple of 4 (
batch_tiles &= ~3u, e.g.8 × 1440 = 11,520 B = 90 × 128 B), preventing unaligned 16-byte Element Interconnect Bus splits and jumping LM-head XDR bandwidth from12.7 GB/sto**17.36 GB/s** .
- Splits
run_matvec_outandrun_lm_argmaxwith a 4-deep branchless(cur + 3u) & 3uDMA ring and single 128B-alignedmfc_putwrites per slice (eliminating ~900 partial-cacheline false-sharing writes per token).
- Clamps each SPE's tile batch size to a multiple of 4 (
- Fused
CELL_CMD_GATE_UP_SWIGLU+ GQA-Paired 8-Bit KV FlashAttention-2: - Computesgatedirectly into Local Store, streamsup, applies 4-wide SIMDSiLU(gate) * upin-register, and issues a single1,024 B`` mfc_put— eliminating 30 SPE dispatches/token.
- Compresses KV cache steps to 80 bytes (
64 × uint8+fp32scale + 12 B pad,MAX_SEQ=512,7.03 MiB), halving KV DMA on 2-head SPEs (SPE 0, 2, 4) via paired integerQ·Kdot products and sharedVunpacking.
- Computes
- Zero-Syscall MMIO Mailboxes + PowerPC AltiVec PPE (
ppe/cell_llm.c,ppe/cell_llm_web.h): - Persistent SPE contexts dispatched via directSPE_MAP_PSmemory-mappedSPU_In_Mbox/SPU_Out_Mboxregisters withlwsyncordering.
- PowerPC AltiVec (
<altivec.h>) vectorizedrmsnorm, fused residualadd_rmsnorm(for bothW_oandW_down), and vectorizedapply_rope. - Built-in
--bench <N>,--profile,--chat(stickynvtop-style ANSI terminal HUD), and--serve 8080(pure-C Web Chat + OpenAI-compatiblePOST /v1/chat/completionsSSE server).
- Persistent SPE contexts dispatched via direct
Download model.safetensors and tokenizer.json from HuggingFaceTB/SmolLM2-135M-Instruct, then run:
make convert_cellq4
./convert_cellq4 weights/model.safetensors weights/smollm2-135m-cellq4.cbin
python3 tools/export_tokenizer.py weights/tokenizer.json weights/smollm2.ctok
make SPU_CC=/path/to/spu-gcc SPU_SIZE=/path/to/spu-size \
LIBSPE2_INC=/path/to/libspe2/include LIBSPE2_LIB=/path/to/libspe2/lib
./cell-llm --model weights/smollm2-135m-cellq4.cbin \
--tok weights/smollm2.ctok \
--spu spu/cell_llm_spu.elf \
--bench 7 --profile \
--prompt "Explain in two short sentences what a GPU is."
./cell-llm --model weights/smollm2-135m-cellq4.cbin \
--tok weights/smollm2.ctok \
--spu spu/cell_llm_spu.elf --chat
./cell-llm --model weights/smollm2-135m-cellq4.cbin \
--tok weights/smollm2.ctok \
--spu spu/cell_llm_spu.elf --serve 8080
./cell-llm --model weights/smollm2-135m-cellq4.cbin \
--tok weights/smollm2.ctok --ppe-only \
--prompt "Explain in two short sentences what a GPU is."
MIT — Venia LLC (@veniallc)