r/cpp • • 14m ago

BetterDiffusion: A 33 MB zero-dependency C++20 + CUDA Stable Diffusion / SDXL engine (no Python, PyTorch, or cuBLAS)

I wanted a local diffusion runtime without a 6 GB Python/PyTorch environment, so I wrote BetterDiffusion in C++20 and CUDA.

Everything compiles into a single 33 MB binary: zero-copy mmap GGUF/Safetensors loader, BPE/SentencePiece tokenizers, DEFLATE/PNG encoder, embedded HTTP/WebSocket studio server, and custom CUDA kernels. Memory is managed through a deterministic single-slab arena (VramArena) with 256-byte aligned O(1) bump allocations and zero allocations inside the hot loop.

On a 4 GB RTX 3050 laptop GPU, it runs full 6.94 GB SDXL 1.0 (1024×1024) in 45.5s with TeaCache (66.09s exact) and reclaims 99.9% of VRAM on unload (4 MiB idle).

Source (MIT): https://github.com/Alakatraz1/BetterDiffusion — open to code review on the C++20 architecture and memory arena.

3 Upvotes

0 comments sorted by