Repository navigation
Replies: 7 comments 21 replies
|
I hadn't seen this before I had spent some time today exploring this on a whim. I was about to post a discussion item on a much smaller scoped suggestion: image decoding and the disk cache. I had only played around with the image decoding so far since it was the easiest to prove out viability. Luckily, both myself and @mduka ended up using the same crates so I have validated their viability independently. I'm suggesting these two layers (image decoding and disk cache) because
What I BuiltI have a branch (https://github.com/sdwilsh/gufo/tree/sdwilsh/rust-image-decode, compare), that only moves PNG and WebP decoding to a small, static library. It exposes a C ABI that has two decode functions and a free function. PNG and WebP output is byte-identical to main on 230 test images, and EmbeddingGemma 2's image suite passes on gfx1151. I measured this on my Zen 5 Ryzen AI 7 350 machine that I do my dev work on.
Yes, PNG decoding is actually faster, and by a lot. That would actually improve our embeddings performance for PNG by ~4% estimated with a 12 MP PNG. I had an agent run some quick experiments to speed up lossy webp, and I think we can get it close to It might be worth doing the Rust decoder just for PNG given the wins, but I won't burden this project with the PR without sign-off on the idea first. |
|
Hello, I'm happy to see a discussion like this starting 😄 I'll begin by saying I'm a Rust dev myself, and I use it professionally at work on a daily basis. While we were still thinking about Gufo I originally suggested Rust over C++, but ultimately @francescobozzo convinced me that C++ was the way. I don't regret that decision for two main motivations:
We have built Gufo organically. We started from pure chaos, and over time, we saw where the codebase was going and how it should be organized. A clear example is the cache. It was originally contained inside the HTTP server as a single file, and through refactoring, we created a separate package. That package is extremely well defined in terms of scopes and responsibilities, and it allowed us to fix all the cache issues in one shot. But this was only possible after the initial chaos of the cache, where we learned a lot and were able to iterate quickly. I truly believe that Rust can be a good fit for Gufo in several places. There are several aspects of Rust that could improve the readability of our codebase, both for humans and LLMs. The maintainability, in terms of less code or more organized code, and maybe even some efficiency, and more importantly, some compatibility over different systems and architectures. So we think that Gufo could be a good fit, but a full port scares us. Ports never come for free. Even if all tests are green, there is still space for sneaky errors/bugs. I'm a fan of the Linux kernel approach in this sense, where Rust is not seen as a competitor to C, but rather as a companion that coevolves with the kernel. And who knows, maybe one day it will replace C completely. So I'd probably start with a small set of features or refactors that are built using Rust and then called by C++ or viceversa. A clear example is the image encoder mentioned above, or some refactoring that we are planning to do but haven't had time for yet. Similarly to the cache, there are already some parts of our codebase that have evolved into a mess, and we probably want to refactor them into a dedicated module that is easy to maintain, easy to bisect, and allows users to contribute easily to the project. This small steps would also allows us to validate how to operate in the future, and proves the merits (or not) of Rust over C++. What do you think? If you agree with the vision and the plan we can start discussing on what could be the next step |
|
First of all, I'm really happy to see that this has sparked some interest! Thanks for the thoughtful feedback and the open discussion. @fedeizzo, I agree with the vision and the plan. Starting with well-defined components that coevolve with the C++ code is a sensible way to find out whether Rust pays off for Gufo, and @sdwilsh's #913 is a good first test case. One small note on agents, where my experience has been a little different: coding agents tend to find problems by running tests, and once something fails, they can spend quite some time working out what went wrong. With Rust, the compiler catches some mistakes much earlier, which shortens that feedback loop. But the first components will show that better than any argument. ;-) @sdwilsh, one data point from my port, which uses the same crates: in my tests, zune-jpeg differs from libjpeg-turbo by up to 6 levels per color channel, so unlike PNG, switching JPEG decoding wouldn't be pixel-identical. For a next step, I'd be happy to take on one of the parts you mentioned. Which refactors or modules did you have in mind? I'd aim to follow the pattern in #913 where practical: a small static library behind a narrow C ABI, compatibility tests, and measured performance against main. If there's broader interest later, we can still revisit whether the full Rust implementation has a place under |
|
Small update: #913 is about to be merged and CI now handles the Rust toolchain, so we can start picking the next pieces. These are the ones I think could move today, all behind a small C ABI like the PNG decoder:
About the disk cache: I had a look after @sdwilsh's suggestion. std covers the plain file ops, but the parts that make the cache durable (dir-relative open/stat, rename without replace, directory fsync, fadvise, file locking) aren't in std, and the interface is wide (manifests, durable entries, streaming restore). So I'd keep it in C++ for now. The manifest encode/decode + CRC-64 is self-contained if someone wants a smaller piece of it. Layout-wise I'd use a Cargo workspace: one small crate per component, plus a thin crate that builds the single static library C++ links, so std and shared deps are only built once. I'd start with WebP and WAV, since they have exact outputs and reuse what we built for PNG. @mduka you offered to take one, does any of these sound good? Just comment here before starting so we don't overlap. |
|
Status update now that #1159 is merged: Most of the list from my last comment is done, so here are the rules for what comes next and the follow-ups we found along the way. What can be written in Rust
CandidatesIn the order I'd like to see them:
WebP and JPEG stay open for whoever wants them, with the constraints already discussed above: lossy WebP speed against libwebp, and a quality check on every vision model for JPEG. As before, comment here before starting so we don't overlap. Follow-ups
Help on any of these is welcome too. |
|
The previous list is done, thanks @mduka and @sdwilsh! Multipart, GGUF headers (#1261), the cache manifest and CRC-64 (#1305), the JSON parser (#1294), the JSON Schema compiler (#1304) and JPEG (#1312) are all on Here is what comes next, including a change to the rules. What changesThe rules said the HTTP server loop and handlers stay in C++. I'd like to change that: the network edge (transport, protocol decoding and encoding) is now a Rust candidate, and The thing I like most about the Rust code we have is that it is made of small modules that are easy to read, review and update. Every new port should keep it that way. Porting a tangled C++ file one to one into a single large Rust file keeps the tangle, so for the big candidates below we agree on the module split in the issue before anyone writes code. Small candidatesThese are independent of each other and of the big work:
Big candidatesIn this order:
Every new dependency follows Staying in C++Some of the most tangled code isn't on this list: As before, comment in an issue to be assigned. |
|
Status update: the big list from my last comment is almost done, thanks @mduka and @sdwilsh! Safetensors headers (#1393), Before picking the next pieces, I measured what these ports cost, so here are the numbers, then the next candidates. What the ports cost
The review side keeps paying off: the crates are small modules, and ports arrive with differential tests against the C++ they replace, so they come already verified. Small candidatesIndependent of each other:
Measure firstThese only go ahead if a measurement says so. The issue asks for the numbers before any port:
The CLIThe CLI is the next area I'd like to open up, tracked in #1511. The order:
The settings types ( Staying in C++Unchanged from last time: the engine, the cache, the scheduler, the model drivers and As before, comment in an issue to be assigned. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
In August 2026, I started developing my own inference engine in Rust for ASR, LLM and TTS on Strix Halo. My main motivation was GPU resource arbitration: letting different inference workloads share the GPU, so that LLM inference and TTS can run concurrently while speech output stays real-time. I chose Rust for its performance, memory safety and modern tooling.
While I was working on it, Gufo was released, quickly gained traction in the community and caught my interest as well. Rather than continue building another competing engine, I decided to build on Gufo and redirect my work toward a Rust implementation of its host layer. Gufo already had substantial work behind its GPU kernels and performance tuning, and I wanted to preserve that rather than reinvent it.
I'd now like to offer this work back to the Gufo project and community, if it is useful. This is an invitation to evaluate the approach, not a request to merge a rewrite of this size as is.
What I've built
The port replaces Gufo's C++ host layer with Rust while preserving the existing HIP/C++ GPU kernels.
It is a substantial implementation: about 200k lines of Rust replace about 230k lines of C++ host code and tests, organized in a Cargo workspace. It is not a line-by-line translation, but it follows the upstream structure and order of operations so that C++ changes have identifiable counterparts in Rust.
The GPU kernels remain HIP/C++. Built with the same ROCm toolchain, device functions shared with the Gufo v0.23.0 C++ build have identical instructions and resource usage, apart from the bounds fix I proposed in gufo-org/gufo#849.
Rust handles engines, weights, sessions, caches, scheduling, server, CLI and HIP resource management.
The current reference is v0.23.0. Every model from that release except MiniMax H3 runs in Rust: Qwen3.8, Qwen3.5, Flash-Next, DeepSeek V4 Flash, ASR, TTS, image generation and embeddings. The goal is to preserve upstream's CLI, HTTP APIs, numerics and performance. Some less commonly used options, diagnostics and model configurations are not yet ported, and certain caching and request-handling behaviors differ. These are documented rather than silently changed.
Why Rust?
My main motivation is to make correctness properties of GPU host code explicit and enforceable.
Gufo already uses coding agents and includes repository guidance for them. I believe Rust can be particularly valuable in this workflow: ownership, lifetime and concurrency mistakes that might surface much later as memory corruption or hangs in C++ are often caught at compile time, with diagnostics an agent can act on directly.
The port applies this in three concrete ways:
gufo-hip, apart from narrow build-time exceptions. Kernel crates permit it only in generated launchers, and CI enforces the policy.launch.toml, including buffer extents, stream ownership, index bounds and aliasing. Generated wrappers validate these contracts before launching kernels, while probe tests exercise launchers against guard regions. Defining these contracts helped identify three potential out-of-bounds indexing issues in Flash-Next (gufo-org/gufo#848).This does not eliminate the need to review the HIP boundary or the correctness of its contracts. It does, however, reduce the amount of host code whose safety depends on manual reasoning. A checked launch costs the same host time as a direct C++ launch (about 1.9 µs).
Beyond memory safety, I see potential value in making host-code changes easier to validate and review, particularly in a fast-moving project that uses coding agents. Whether these benefits outweigh the migration and maintenance costs is something I would like to explore with the maintainers.
Rust might also simplify some aspects of cross-platform maintenance in the long term, although this remains unproven. Windows support is currently a gap in the port, while upstream already supports it.
Validation and current status
I compared the Rust build against Gufo v0.23.0 (C++) on the same Strix Halo system using ROCm 10.1.
The A/B runner checks request and stage timings, load time and total memory against strict regression thresholds, using bootstrapped 95% confidence intervals.
The current results:
These results are encouraging, but I would not claim that full performance and compatibility parity has been established yet. Independent validation on additional hardware and further benchmark runs would be valuable.
The complete methodology, per-workload results and known differences are documented in docs/development/PARITY.md.
There is also remaining work on:
The port also includes an optional
gufo arbiter, originating from my initial engine's motivation. It coordinates GPU sharing between server processes, letting LLM inference yield when streamed TTS needs resources to maintain real-time playback. It is disabled by default and does not affect the upstream performance comparisons.How could we evaluate this?
I recognize that adopting a rewrite of this size would be a significant long-term maintenance commitment.
The safety improvements are only valuable if the resulting codebase is also understandable, reviewable and maintainable by existing and future contributors. Rust alone does not guarantee that.
There is also a practical challenge: Gufo evolves extremely quickly.
I currently have only one Strix Halo machine, and complete validation and A/B testing take longer than the interval between many upstream commits. Keeping the port synchronized with a moving
mainis therefore not something I can realistically manage alone.For that reason, I think it would be useful to separate two decisions:
The first could start with a focused architecture review, particularly around
gufo-hip, kernel launch contracts and resource ownership, alongside identifying the compatibility and validation requirements that matter most to upstream.Only if that evaluation is positive would it make sense to discuss a possible transition.
A staged migration might introduce additional FFI and integration complexity, so a coordinated transition may ultimately be simpler. However, I don't want to assume that this is the right approach for Gufo.
Possible paths could include community-assisted synchronization and validation, or selecting an agreed upstream release as a reference for a fully validated Rust implementation. I'm open to other approaches the maintainers might prefer.
My intention is not to ask upstream to pause development or commit resources before there is agreement that the direction is worthwhile.
Questions
If the answer is no, I completely understand.
My motivation is to contribute what I've built to the project the community has already gathered around, rather than maintain another competing Strix Halo engine.
Whatever the outcome, I'll continue contributing improvements that benefit the C++ engine through ordinary PRs, as with the recently merged gufo-org/gufo#849.
Disclosure: I developed the port with the help of AI coding agents. I take responsibility for the contribution. Tests, benchmarks and known differences are documented, and I'm happy to answer questions or walk through the implementation.
All reactions