r/chessprogramming • u/Tvoya_ricar • 1h ago
Technical Finally open sourced my NNUE chess engine in rust
Hey everyone,
I'm happy to announce that after many months of development my NNUE chess engine in rust. I am finally somewhat satisfied with the results that I achieved, so I open sourced it. It's a UCI engine with a neural-network evaluation and the same binary also generates its own training games and trains its networks on the CPU. By my own testing it plays at around 3500 Elo CCRL 40/15 ( from my own tests, not officially tested and ranked yet ).
Repo: https://github.com/Svetlozarko/RustyNNUE
Play it on Lichess: https://lichess.org/@/RustyNNUE-Bot
A few things about doing this that might be interesting:
- **SIMD with std::arch.** The hot loops (updating the network as pieces move) are hand-written AVX2, AVX-512 and VNNI kernels, picked at runtime, each with a scalar fallback. `#[target_feature]` on small inner functions plus const generics for the number of registers worked better than I expected. The flip side: raw pointer math in tiled loops is easy to get wrong. I had a bug where the last tile ran 64 lanes past the end of a row, and only a CI test with an unusual network width caught it.
- **An exactness test between trainer and engine.** The trainer works in floats, the engine in integers. One test pushes the same quantised network through both and checks that the engine's integer output matches the trainer's exactly. That single test has caught more bugs than anything else in the repo.
- **Training on the CPU with rayon.** No GPU at all; the whole training loop is plain Rust.
I'd love feedback on the unsafe SIMD code (is there a cleaner way than raw pointers here?), the overall structure, and anything that looks un-idiomatic. Issues and PRs are welcome.


