Skip to content

About

llama.cpp optimizations for IBM POWER8: vec_perm non-bijunctive collapse, PSE hardware entropy, DCBT prefetch. Sovereign inference. Part of the Proof of Physical AI stack.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

124 stars

Watchers

11 watching

Forks

llama.cpp for IBM POWER8

License Stars Issues

BCOS Certified AltiVec/VSX Optimized LLM Inference for POWER8

Run your own models on your own hardware. This provides POWER8-specific optimizations for llama.cpp, enabling efficient LLM inference on IBM POWER8 servers using vec_perm non-bijunctive collapse and PSE hardware entropy — techniques built around POWER8's single-instruction two-source vec_perm (AArch64 TBL can do the same in one instruction; x86 needs several below AVX-512 VBMI).

What's Included

  • power8-compat.h - POWER9 intrinsics compatibility layer for POWER8
  • ggml-dcbt-resident.h - Full L2/L3 cache-resident prefetch hints
  • ggml-intelligent-collapse.h, ggml-topk-collapse-vsx.h - vec_perm collapse kernels (from ram-coffers)
  • ggml-top4-vsx.h - exact VSX top-4 threshold used by the collapse (POWER8 and POWER9)
  • ggml-p9-collapse.h - POWER9 (ISA 3.0) path for the collapse kernels, falls back to the POWER8 headers elsewhere
  • altivec_benchmark.c - AltiVec/VSX performance benchmark

Performance

Tested on IBM Power System S824 (dual 8-core POWER8, 576GB RAM):

Model pp128 (tokens/s) tg32 (tokens/s)
TinyLlama 1.1B Q4 ~85 ~15
Llama-7B Q4 ~20 ~5
DeepSeek-33B Q4 ~5 ~1
Gemma 4 26B-A4B MoE Q4 (2026-06) ~16.6 ~6.4

Speedup on TinyLlama 1.1B Q4, prompt processing (pp128), same S824:

Build pp128 (tokens/s) vs scalar vs stock VSX
Stock llama.cpp, scalar (no vector code) 16.7 1.0x —
Stock llama.cpp with POWER8 VSX 66.5 4.0x 1.0x
This patch set (PSE + resident prefetch) 147.5 8.8x 2.2x

2026-06 update: the PSE patch set ported cleanly onto Gemma 4-era llama.cpp (master ac4cdde) and delivered 1.7x generation / 3.1x prompt processing on the Gemma 4 26B-A4B mixture-of-experts vs the same master without PSE (10.7x vs stock-unbound). Details + the PSE-2 "Expert Coffers" direction in PSE_IMPLEMENTATION_LOG.md.

Building llama.cpp for POWER8

Prerequisites

  • Ubuntu 20.04 LTS (last POWER8-supported release)
  • GCC with POWER8 support
  • CMake 3.14+

Build Commands

# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp

# Copy POWER8 headers
cp /path/to/powerpc/* ggml/src/ggml-cpu/arch/powerpc/

# Configure for POWER8
mkdir build-power8 && cd build-power8
cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DGGML_OPENMP=ON \
    -DCMAKE_C_FLAGS="-mcpu=power8 -mvsx -maltivec -O3 -mtune=power8 -funroll-loops" \
    -DCMAKE_CXX_FLAGS="-mcpu=power8 -mvsx -maltivec -O3 -mtune=power8 -funroll-loops"

# Build
make -j$(nproc)

With IBM MASS Library (Optional)

IBM Mathematical Acceleration Subsystem (MASS) provides optimized math functions:

cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DGGML_OPENMP=ON \
    -DCMAKE_C_FLAGS="-mcpu=power8 -mvsx -maltivec -O3 -mtune=power8 -funroll-loops -DGGML_USE_MASS=1 -DGGML_USE_IBM_MASS=1 -I/opt/ibm/mass/include" \
    -DCMAKE_CXX_FLAGS="-mcpu=power8 -mvsx -maltivec -O3 -mtune=power8 -funroll-loops -DGGML_USE_MASS=1 -DGGML_USE_IBM_MASS=1 -I/opt/ibm/mass/include" \
    -DCMAKE_EXE_LINKER_FLAGS="-L/opt/ibm/mass/lib -lmassvp8 -lmass"

The ggml-mass-integration.h wrappers in this repo are gated on GGML_USE_IBM_MASS, which is why the flags above pass -DGGML_USE_IBM_MASS=1. -DGGML_USE_MASS=1 alone leaves them disabled (GGML_MASS_AVAILABLE 0).

Fallback Behavior (Without VSX Acceleration)

When building or running on targets where POWER8 VSX vector extensions are unavailable (or when compiling with generic PowerPC flags without -mvsx -maltivec), llama.cpp automatically falls back to scalar floating-point and integer routines. This ensures functional compatibility across all generic PowerPC environments while maintaining optimal vectorized paths when VSX hardware acceleration is present.

POWER9 Collapse Path and the Faster Top-4 Threshold

ggml-pse-integration.h now includes ggml-p9-collapse.h. On a -mcpu=power9 (or later) build it selects POWER9 versions of the collapse kernels; on any other build it includes ggml-intelligent-collapse.h and ggml-topk-collapse-vsx.h unchanged. Selection keys on the compiler-set _ARCH_PWR9, not on __POWER9_VECTOR__, because power8-compat.h defines __POWER9_VECTOR__ on POWER8 builds.

approx_top4_threshold() in the POWER8 header now uses an exact VSX top-4 network (ggml-top4-vsx.h) for n >= 96. It uses only ISA 2.06 VSX, so it applies to POWER8 builds too.

How these numbers were measured: all on one POWER9 (Raptor Talos II, 2x 8-core, 3.49 GHz, gcc 14.2), comparing the POWER8 code built with -mcpu=power8 against the same or new code built with -mcpu=power9. They measure the instruction-set and code change, not POWER8 vs POWER9 hardware. Nothing here was run on a real POWER8. Cycles from the perf cycle counter, median of 9 runs, single thread, data in L1/L2.

Kernel -mcpu=power8 build POWER9 path or new code Speedup
top-4 threshold, n=4096: old scalar scan vs VSX network, both built -mcpu=power8 12,954 cycles 7,967 1.63x
top-4 threshold, n=1024 (same comparison) 3,194 2,148 1.49x
intelligent_collapse_scores, n=1024: original P8 header vs POWER9 path 4,905 3,234 1.52x
intelligent_collapse_scores, n=4096: original P8 header vs POWER9 path 19,243 12,362 1.56x
intelligent_collapse_scores, n=1024 / 4096: P8 header WITH the top-4 backport vs POWER9 path 3,603 / 13,685 3,228 / 12,383 1.11-1.12x
intelligent_collapse_scores, n <= 64 ~1.1x (within noise)
apply_topk_mask_vsx, n=1024-4096 1,574 / 6,224 665 / 2,570 2.37-2.42x
permute stream, new control vector every 16 bytes 8,557 1,721 4.97x
16 patterns live at once 4,616 3,504 1.32x

Most of the collapse speedup is the top-4 backport, which POWER8 builds get as well; what POWER9 adds on top is about 1.1x for that kernel. Below n=96 the VSX threshold is slower, so it is used only from n=96. Small-n timings varied by up to 15-20% between runs of identical code.

vperm, vpermr, xxperm and xxpermr all measured 3 cycles latency and about 2 per cycle throughput on this POWER9. The POWER9 gains come from removing the little-endian control complement and load/store swaps, and from xxpermr reaching all 64 VSX registers, not from a faster permute.

Outputs are bit-identical to the POWER8 kernels (1,000,000 random trials per kernel, including +-0, +-inf, NaN, denormals and ties; built and checked with both -mcpu=power8 and -mcpu=power9). The harness is in bench/p9-collapse/ (make && ./p9bench check; needs a POWER9 or later host). The one intended difference: for a misaligned scores pointer the POWER8 vec_ld/vec_st code rounds the address down and processes the wrong floats; the POWER9 path uses unaligned loads. All callers pass 16-byte-aligned buffers.

The optional p9c_vec_dot_q4_0_q8_0 in ggml-p9-collapse.h (vmsummbm with a bias correction) measured 1.33x on the q4_0 x q8_0 dot product, but only with the fp16 lookup table for the block scales. On this POWER9 a dependent xscvhpdp costs about 40-46 cycles, and using it made the dot product 2.5x slower than the table.

Running Inference

# Basic inference
./bin/llama-cli -m ~/models/llama-7b-q4.gguf -p "Hello world" -n 64

# With optimal thread count (64 threads is usually best on POWER8)
OMP_NUM_THREADS=64 ./bin/llama-cli -m ~/models/llama-7b-q4.gguf -p "Hello" -n 64

# NUMA-aware (for dual-socket systems)
numactl --interleave=all ./bin/llama-cli -m ~/models/large-model.gguf -p "Test" -n 32

# Benchmark
./bin/llama-bench -m ~/models/tinyllama-1.1b-q4.gguf -t 64 -p 128 -n 32

POWER8 Optimization Notes

Thread Scaling

64 threads is typically optimal on POWER8 (NOT 128):

  • 16 threads: ~40 t/s
  • 32 threads: ~65 t/s
  • 64 threads: ~85 t/s (optimal)
  • 96 threads: ~75 t/s
  • 128 threads: ~65 t/s

Cache Prefetch

The ggml-dcbt-resident.h header provides cache-resident prefetch hints:

  • DCBT_RESIDENT_FULL() - Keeps data in L2/L3 until explicit eviction
  • Critical for weight reuse in attention/matmul

Memory Alignment

POWER8 prefers 128-byte aligned data for optimal VSX performance. power8-compat.h does not align data for you. It leaves vec_xl/vec_xst as the compiler's native unaligned VSX loads/stores (correct at any address), so 128-byte alignment is a performance choice for the caller, not a correctness requirement.

Files

powerpc/
├── power8-compat.h       # POWER9 → POWER8 intrinsic compatibility
└── ggml-dcbt-resident.h  # Cache-resident prefetch hints

altivec_benchmark.c       # VSX/AltiVec performance test

Hardware Tested

  • System: IBM Power System S824 (8286-42A)
  • CPUs: Dual 8-core POWER8, 128 threads (SMT8)
  • RAM: 576 GB DDR3
  • OS: Ubuntu 20.04 LTS

Video Demos

DeepSeek on POWER8

DeepSeek Running on POWER8 - LLM inference on IBM POWER8 S824

Claude Code on POWER8

Claude Code on POWER8 - Proving Claude Code works on POWER8!

Community

Join the RustChain Discord for PowerPC/POWER8 AI discussion:

Discord

The Proof of Physical AI Stack

This repo is one piece of a vertically integrated system where the hardware that runs inference also earns tokens:

Layer Project What It Does
Inference llama-cpp-power8 (this repo) vec_perm collapse, PSE entropy, DCBT prefetch
Memory RAM Coffers NUMA-distributed weight banking, 147 t/s on POWER8
Consensus RustChain Proof of Antiquity — 1 CPU = 1 Vote, vintage hardware earns more
DePIN RustChain Network 2 live attestation nodes (volunteer nodes come and go), hardware fingerprinting, RTC token rewards

The same POWER8 S824 (2.2x over stock VSX llama.cpp on pp128) also mines RTC via Proof of Antiquity at a 1.5x POWER8 multiplier ("power8": 1.5 in node/rip_200_round_robin_1cpu1vote.py; base value before the ~15%/year antiquity decay). Sovereign inference, sovereign earnings.

Related Projects

Attribution

Months of research, tuning, and testing on real POWER8 hardware went into this.

If you use this project, please give credit:

llama.cpp POWER8 Optimizations by Scott (Scottcjn)
https://github.com/Scottcjn/llama-cpp-power8

If this helped you, please:

  • ⭐ Star this repo - It helps others find it
  • 📝 Credit in your project - Keep the attribution
  • 🔗 Link back - Share the love

Credits

  • ggerganov/llama.cpp - Original project
  • Scott (Scottcjn) - Creator, architect, hardware lab, POWER8 optimizations
  • Claude (Opus 4.1/4.5) - Implementation assistance

Designed by Scott, coded with Claude

License

Apache License 2.0. See LICENSE.

ggml/src/ggml-cpu/arch/powerpc/quants.c and ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp are modified copies of files from llama.cpp/ggml, which are MIT-licensed (Copyright (c) 2023-2026 The ggml authors). Those two files keep their MIT terms.


"576GB RAM. 128 threads. Your POWER8 was built for AI - it just didn't know it yet."




Elyan Labs · 1,882 commits · 97 repos · 1,334 stars · $0 raised

⭐ Star RustChain · 📊 Q1 2026 Traction Report · Follow @Scottcjn


Part of the Elyan Labs Ecosystem

  • RustChain — Proof-of-Antiquity blockchain rewarding vintage hardware
  • BoTTube — AI video platform where 119+ agents create content
  • GitHub

About

llama.cpp optimizations for IBM POWER8: vec_perm non-bijunctive collapse, PSE hardware entropy, DCBT prefetch. Sovereign inference. Part of the Proof of Physical AI stack.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

124 stars

Watchers

11 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages