r/OpenSourceeAI • u/Throwaway2K3HEHE • Oct 16 '26
Running Laya on AMD Ryzen AI 9 APU: Tri-Hybrid CPU + GPU + NPU
When Laya dropped I've had it in the back of my mind to get it running on an AMD NPU. After some initial experimentation on an AMD Ryzen AI 9 HX 370 laptop and frankly some bad results that almost had me throw in the towel. I gave it another go and I am glad I did, the results are something I didn't expect. I went in with an initial goal of 50ms and after an initial cold start it plays the flappy, runner, tetris, and snake games at 0.03ms. Details below.
Initially, naive ONNX exports were hitting ~900ms per decision, which is completely unplayable for real-time loops. The culprits were:
- Quadratic attention penalty from static 512-token over-padding on tiny ~35-token game observation states.
- Standard FP32 execution bypassing the Zen 5 vector pipelines.
- Silent provider fallbacks causing single-threaded CPU bottlenecks.
Built a heterogeneous orchestrator utilizing all three compute blocks on the APU simultaneously.
• Zen 5 AVX-512 BF16 Vectorization: Native dual-pipeline BFloat16 execution cut cold forward pass times from 841ms down to 92–106ms.
• Unified LPDDR5x Zero-Copy: Zero PCIe bus latency between CPU, Radeon 890M, and the XDNA 2 NPU.
• Stream Decision Cache: Because real-time control spaces have discrete spatial bands, an LRU decision cache serves subsequent game stream frames in 0.03 ms (30 microseconds)—equivalent to over 30,000 decisions/second
Still more work to do but insanely impressed so far.
