cd /news/artificial-intelligence/bare-metal-c-llm-engine-for-a-2006-p… · home › topics › artificial-intelligence › article
[ARTICLE · art-181353] src=github.com ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Bare-metal C LLM engine for a 2006 PS3 (150.7 tok/s, 137x llama.cpp)

A from-scratch pure-C inference engine for the 2006 Sony PlayStation 3 reached 150.72 tokens per second decoding SmolLM2-135M-Instruct (Q4), 137.0× faster than a tuned 2-thread build of upstream llama.cpp (1.10 tok/s) on the same console, the project reports. The engine, cell-llm v6, uses the Cell Broadband Engine's 6 Synergistic Processing Elements with integer mpya instructions and 128-byte DMA, sustaining 17.36 GB/s on the LM head with 0.09% imbalance across SPEs, and prefills 41 tokens at 185.8 tok/s versus llama.cpp's 29.45 seconds. It runs with zero llama.cpp, CUDA, Python runtime or ML frameworks, fits in 24.7 KiB of SPU .text (versus 12 MB stripped llama.cpp), and compiles natively on the PS3 in about 2.5 seconds against roughly 60 minutes for upstream llama.cpp.

recommendation

Offload matvecs to all 6 Cell SPEs with integer mpya and 128-byte DMA, and fuse gate+up+SwiGLU into one dispatch to cut per-token time; the source measured 150.72 tok/s versus 1.10 tok/s for 2-thread llama.cpp.

more in playbook: Inference and self-hosting
read6 min views6 publishedDec 3, 2026
Bare-metal C LLM engine for a 2006 PS3 (150.7 tok/s, 137x llama.cpp)
Image: Michielbdejong (auto-discovered)

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/s peak decode ( 139.5–150.7 tok/s across--bench 7 runs) and**185.8 tok/s** prefill running SmolLM2-135M-Instruct (Q4) 100% resident in PS3 XDR DRAM
  • 137.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-O3 baseline (0.93 tok/s )
  • 17.36 GB/s sustained LM-head XDR DRAM bandwidth (0.09% imbalance across all 6 SPEs) with**25,288 bytes (24.7 KiB)** of SPU.text machine code (156.8 KiB / 256 KiB Local Store) vs12 MB strippedllama.cpp
  • Compiles natively on the PS3 in ~2 seconds (vs ~60 min for upstreamllama.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, fused gate+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/s sustained 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 into CELL_CMD_GATE_UP_SWIGLU )
  • PowerPC AltiVec RoPE + Fused Residual add_rmsnorm (PPE):0.30 ms (0.09 ms RoPE +0.21 ms norm)
  • 6-SPE Hardware Decrementer Balance (79.8 MHz, LM head): 81,332 –81,595 ticks (0.09% spread acrossSPE0 –SPE5 )
  1. Native Big-Endian CELL-Q4_32 Weight Format (tools/convert_cellq4.c): - Packs 4 output rows × 32 input columns into an 80-byte, 16-byte-DMA-aligned tile (4fp32 scales + 64 bytes of packed 4-bit nibbles,5.0 bits/weight).
  • Zero byte-swapping on big-endian ppc64 ;mlock() pins the entire80.29 MiB weight buffer in physical XDR DRAM so Linux never pages out a layer.
  1. Packs 4 output rows × 32 input columns into an
  2. Integer Q4 × Q11 SPU mpya / mpyhha MatVec (spu/cell_llm_spu.c): - Quantizes the activation vector x to 11-bit signedint16 pairs (xl = q << 4 matchingpk & 0x0F ,xh = q matching unshiftedpk & 0xF0 = 16 * hi ), eliminating all32`` cuflt instructions and all4`` rotm nibble shifts per tile while cuttingshufb in half (32 → 16 ).
  • Uses 8 dual int32 accumulators (spu_mule /spu_mulo /spu_mhhadd /spu_madd ) to completely hide the SPU's 7-cycle integer multiply latency.
  1. Quantizes the activation vector
  2. 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/s to**17.36 GB/s** .
  • Splits run_matvec_out andrun_lm_argmax with a 4-deep branchless(cur + 3u) & 3u DMA ring and single 128B-alignedmfc_put writes per slice (eliminating ~900 partial-cacheline false-sharing writes per token).
  1. Clamps each SPE's tile batch size to a multiple of 4 (
  2. Fused CELL_CMD_GATE_UP_SWIGLU + GQA-Paired 8-Bit KV FlashAttention-2: - Computes gate directly into Local Store, streamsup , applies 4-wide SIMDSiLU(gate) * up in-register, and issues a single1,024 B`` mfc_put — eliminating 30 SPE dispatches/token.
  • Compresses KV cache steps to 80 bytes (64 × uint8 +fp32 scale + 12 B pad,MAX_SEQ=512 ,7.03 MiB ), halving KV DMA on 2-head SPEs (SPE 0, 2, 4 ) via paired integerQ·K dot products and sharedV unpacking.
  1. Computes
  2. Zero-Syscall MMIO Mailboxes + PowerPC AltiVec PPE (ppe/cell_llm.c, ppe/cell_llm_web.h): - Persistent SPE contexts dispatched via direct SPE_MAP_PS memory-mappedSPU_In_Mbox /SPU_Out_Mbox registers withlwsync ordering.
  • PowerPC AltiVec (<altivec.h> ) vectorizedrmsnorm , fused residualadd_rmsnorm (for bothW_o andW_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/completions SSE server).
  1. 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)

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @sony playstation 3 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/bare-metal-c-llm-eng…] indexed:0 read:6min 2026-12-03 · —