r/rust • u/New-Value8006 • 3h ago
๐ ๏ธ project Built a native Vulkan inference engine from scratch using Rust (FFI + OnceLock) to run AI models locally without CUDA.
Hi fellow Rustaceans ๐ฆ,
I was tired of the heavy reliance on NVIDIA/CUDA for local AI generation, especially since I run an AMD RX 580. To solve this, I decided to build my own inference engine from scratch using Rust as the core orchestrator.
How Rust made this possible: The backend is a heavily modified C++ Vulkan environment, but the entire lifecycle, memory management, and routing are handled safely in Rust.
FFI & libloading: I used libloading to dynamically bind the Vulkan .dll.OnceLock for VRAM Safety: To prevent massive VRAM leaks and crashes when switching between image generation (Flux) and video generation (Wan 2.1 I2V), I wrapped the dynamic library load in a
OnceLock. This ensures the .dll is statically loaded into memory only once, allowing Rust to safely spin up and tear down the Vulkan context (sd_ctx) per thread without ever reloading the binary.Concurrency: Rust's fearless concurrency handles the background NLP processing (via a local LLM acting as a router) and safely passes the extracted directives directly to the Vulkan C-pointers.
It's completely open-source. You can check out the repo here:https://github.com/Yanko0615/Xyron_Vulkan_Core
I would love to hear your thoughts on my FFI implementation or any tips on optimizing the unsafe blocks!