AMD Zen 5 Tuning "Part Two" Merged For GCC Compiler

Written by Michael Larabel in AMD on 3 September 2024 at 10:30 AM EDT. 3 Comments
AMD
Merged today for the GCC 15 compiler in development and potentially for back-porting to the next GCC 14 point release is a second round of AMD Zen 5 "znver5" tuning.

GNU Compiler Collection (GCC) expert Jan Hubicka of SUSE's compiler team worked out this latest round of compiler tuning for benefiting the Ryzen AI 300 series, Ryzen 9000 series desktops, and upcoming EPYC Turin processors. As with past generations of Zen processors, AMD has largely relied on SUSE's compiler talent for working out much of the compiler enablement and tuning for this leading open-source compiler.

With this "round 2" tuning of AMD Znver5 compiler support, it's focused on disabling gather and scatter support by default. Similar to past AMD Zen tuning for GCC, disabling gather and scatter instructions by default is done in the name of overall performance.

AMD Ryzen Zen 5 CPU with GCC Git


Jan Hubicka explained with today's patch to the GCC compiler:
"We disable gathers for zen4. It seems that gather has improved a bit compared to zen4 and Zen5 optimization manual suggests "Avoid GATHER instructions when the indices are known ahead of time. Vector loads followed by shuffles result in a higher load bandwidth." however the situation seems to be more complicated.

gather is 5-10% loss on parest benchmark as well as 30% loss on sparse dot products in TSVC. Curiously enough breaking these out into microbenchmark reversed the situation and it turns out that the performance depends on how indices are distributed. gather is loss if indices are sequential, neutral if they are random and win for some strides (4, 8).

This seems to be similar to earlier zens, so I think (especially for backporting znver5 support) that it makes sense to be conistent and disable gather unless we work out a good heuristics on when to use it. Since we typically do not know the indices in advance, I don't see how that can be done."

This GCC bug report was opened today for tracking the gather instructions performance on Zen CPUs. In response to a question from another developer when the gather instructions are a win: "it is mysterious.."

Part 1 of the optimizations to Znver5 were to avoid FMA chains since they don't work well on Zen 5 processors compared to Znver4.

Hopefully we'll see more AMD Zen 5 compiler tuning soon for GCC. We are also still waiting on Znver5 enablement to come for the LLVM/Clang compiler. As of writing the Znver5 support hasn't landed in LLVM Git nor are there any open pull requests from AMD or their partners in providing that support. That's particularly unfortunate with AMD Ryzen AI 300 and Ryzen 9000 series processors already shipping and LLVM 19 being released in the coming days.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week