GGUFC: compiling a language model to C, then booting it instead of Linux
Every time llama.cpp starts, it reads the model file, works out the tensor shapes, builds a compute graph, allocates buffers and picks kernels. That work comes out the same every time for a given model on a given machine, and it’s done by a large program that has to handle any model.
So I asked: what if all of that happened once, on the build machine, and what shipped was just the result?
That became GGUFC. You give it a GGUF file and a short description of the target CPU, and it writes a C99 project that runs that one model on that one CPU.
What it’s for
Think of any device that needs a small language model, and nothing else: no operating system to boot, no engine to install, no memory surprises.
- Robot and home assistants. A robot or a smart speaker that hears a question, answers and speaks the reply, fully offline. The voice demo below is exactly that: speech recognition, a chat model and text to speech in one image.
- Voice-controlled appliances. An oven, a washing machine or a thermostat that understands “start the delicate cycle at 40 degrees” without sending your voice to the cloud.
- Toys and companions. A talking toy or a learning companion for kids: it works without Wi-Fi and with no account, and nothing leaves the device.
- Industrial panels and kiosks. A machine on a factory floor that explains its own error codes, or an information kiosk. Either one boots into the model and has no Linux distribution to patch.
- Cars, boats and drones. An assistant that answers right after power-on, with memory use known before it ships.
- Accessibility devices. Reading aloud, voice commands or dictation on a small, cheap board that has to be reliable.
- Medical and regulated products. Static memory, fixed loops and the same output byte for byte from every build make the code much easier to review and certify.
- Air-gapped systems. No file parser, no network stack and no heap at runtime leave very little to attack.
- Many tiny virtual machines. One small VM per agent or per user, each without a guest OS to boot.
The common thread: when a device only has to run one model, a general-purpose OS and inference engine are overhead, and GGUFC removes them. (Today it all runs in QEMU. Real boards come next, see the end.)
What comes out
In the generated project:
- every tensor shape is a
#define, - every buffer has a fixed place in one static struct, and the RAM the model needs is
sizeofthat struct, printed by the compiler, - only the kernels this model uses are included, already picked for this CPU,
- the tokenizer and chat template are generated tables,
- the weights stay binary and are linked read-only, so a board can run them straight from flash.
The result is about 40 KB of code plus the weights. There’s no malloc and nothing to parse at startup, and it builds without libc or libm (GGUFC ships the handful of math functions it needs). The converter tells you exactly what you’re getting:
smollm2-135m-instruct-q4_k_m.gguf -> out/img (qemu-virt, ctx 2048, 30 layers, 4 cores)
RAM 94894144 bytes (90.50 MiB), sizeof(m_ctx): KV cache 90.00 MiB + activations 0.50 MiB
weights 105820672 bytes (100.92 MiB) in .rodata, crc32 2d9dc1c8
The model is the kernel
Because the output needs nothing from an OS, the same project also builds into an arm64 kernel Image. QEMU’s -kernel loads it, and so does a stock U-Boot with booti, exactly the way they’d load Linux. The image sets up its own page tables, starts the other cores, and answers on the serial console. Leave out the prompt and it boots straight into a chat:
/off powers the VM off.Skipping the OS shows up in boot time. In the same QEMU VM, from launch to the first byte of the answer, the GGUFC image takes 87 ms. Linux (a minimal 6.12 kernel) plus llama.cpp takes 238 ms on the same model and question.
It talks, and it listens
Then I wanted to see how far it goes. GGUFC also compiles Soprano-80M, a text-to-speech model, together with its audio decoder, and Qwen3-ASR-0.6B, a speech recognizer, together with its audio encoder. The kernel image drives a virtio-sound device by itself, in both directions.
Here are three models in one 1.7 GB kernel image. Qwen3-ASR hears a spoken question, Qwen2.5-0.5B answers it, and Soprano speaks the answer. Turn the sound on:
There’s no audio stack in that VM: the sound is what QEMU recorded from the image’s virtual sound card. A test boots the image on recorded questions and checks what it heard, what it answered and every audio sample it played against the same code built as a normal program on the Mac. They match bit for bit. All of that memory, 2.16 GB, is static and known at compile time.
A shorter one, with the chat model and the voice only:
Is it correct? Is it fast?
Correct, yes. Every build is checked position by position against a pinned llama.cpp. F32 builds match within 1e-3 on 32 prompts.
Quantized builds can’t be expected to match exactly, because llama.cpp doesn’t even agree with itself: two of its own valid kernel configurations pick a different top token at 2 to 2.6% of positions, from rounding alone. So the rule is that a GGUFC build may not disagree with llama.cpp’s default more than llama.cpp’s other configuration does, which is checked with a statistical test. All twelve Q8_0 and Q4_K_M builds pass, across SmolLM2-135M, Qwen2.5-0.5B and Llama 3.2 1B.
Fast is more nuanced. Against llama.cpp, same model, same 4 threads, on my Mac:
Time to first token is 136 ms against 258 ms, peak RAM is 119 MB against 293 MB, and code is 42 KB against 6.6 MB. Those follow from the design. Speed per token is about the same, and I’m not claiming more: decode is limited by memory bandwidth, and no compiler trick changes that.
Try it
The project site has ready-made images and how-to guides. If you have a C compiler and make, you can run a prebuilt model with no Rust and no GGUF:
git clone https://github.com/antonellof/ggufc && cd ggufc/examples/prebuilt/smollm2-135m-q4_k_m-arm64
curl -L -o weights.bin https://github.com/antonellof/ggufc/releases/download/v0.2.0/smollm2-135m-q4_k_m-weights.bin
make && ./build/model
Images for the Raspberry Pi 4 and RK3588 boards are in the v0.2.0 release. They work in QEMU, but they haven’t run on real hardware yet. When the RK3588 board arrives, I’ll measure power-on to first token against Linux and llama.cpp, and write it up.
The code is Apache-2.0 on GitHub.