Nice - I wrote our SIMD C++ classes (also quant finance but less low latency, more pricing and risk, still lots of CPU load) nearly 10 years ago and I'll be keeping an eye on this to see how closely it maps to our wrappers.
Ours is focused almost entirely on 64bit doubles, and with a particular focus on ensuring numerically consistent results whether 128bit, 256bit or 512bit vectors are used. So for example we prefer to do 8-way summing of a vector of doubles with a routine that knows to use 1 accumculator register for 512bit, 2 registers for 256bit or 4 registers for 128, and then to the sum the final 8 accumulations in a consistent manner.
Any while the compilers are better at autovectorising simple loops, they're subject to use not allowed then to apply optimisations that can change numerical consistency. We can choose to explicitly call the 8 way sum above, but we can't have a sum function that, depending on the hardware and the whim of the compiler's mood at the time, could generate code for 1, 2, 4, 8 (or more) summing from compile to compile.
And we then [... uh oh.. secret sauce here ... ] which is where it really starts to win.
Also worth noting that, admittedly not so much these days, but the AVX (256bit) bit registers on early CPU generations had half the register width powered down (and the ALU upper halves etc) and would only power up on demand, and this came with power and heat penalties that, back then, forced a CPU clock penalty, and even today is still likely to reduce the overhead for the CPU clock to boost to higher speeds when thermals etc allow. For a long time AVX simply wasn't worth it for general purpose work... if you weren't going to doing intensive simd loops for 10s of milliseconds or longer at a time (and we're not a supercompute / HPC style workload) then it was slower to use AVX than to use SSE2
Anyway, nice write up, I'll try to come back to it from time to time
Good point, and yet genuine AVX512 cpus need so much physical room for those register files that an AVX512 processor has its own cost (moves L1 cache further away etc).
Does the AMD implementation have genuine 512bit registers or are they implementing it at the hardware level by double pumping 256bit registers (in the same way that they first provided AVX support by double pumping 128bit registers, and "genuine" early generation AVX processors would execute AVX instructions while waiting the 70 microseconds or so that was required for the circuitry for the upper half to power up)?
I was hoping that AVX10/256 would be a nice compromise (the increased number of addressable registers but taking less die space than 512) but my understanding of AVX10 is that 512 bits is now mandatory, although I very quickly admit that I don't follow all the latest comings and goings and we focus on maximising h/w that's already several generations old by the time we first get access to it.
AMD has genuine 512 bit registers in Zen5 and the upcoming Zen6.
Zen4, Zen4c, and Zen5c are 256bit double pumped.
Intels upcoming Nova lake also supports AVX512 but I've seen no information on how it is implemented so far.
The problem with AVX10 is it created a bifurcation by not requiring support for 512 bit(even if double pumped), increasing the # of targets devs had to care about, do you really want to compile 512 wide for AMD and then 256 wide for Intel? So they wisely gave up that idea, and now require 512.
The reality is that x86 CPUs basically need 512-bit SIMD to compete against modern AArch64 CPUs as they can use as many as you want decoders in parallel, and here x86 will always be limited and pretty hungry.
512 SIMD isn't really used in any common benchmarks(geekbench/spec/cinebench etc).
x86 relies more on SMT to get the extra decode, at least that is how AMD does it. Intel just tries to decode 8 at a time(how well it works.. only Intel can say).
These benchmarks are useless when it comes to industry workloads. When you decode JSON you use simdjson, which takes advantage of AVX-512. Basically any non-trivial workload can benefit from it, it only depends on whether you need to improve the performance/latency or not. On servers of course you do.
Advice for the article writer: Explain your acronyms.
Nowhere in theintroduction do you mention what SIMD stands for, nor in the "What is SIMD" paragraph.
As the name suggests, there are sort of “parallelism” in SIMD
It only suggests that to people who already know what "SIMD" stands for. For a reader who doesn't and seees a "What is SIMD" chapter trying to understand, those words are nonsense.
You keep saying "as the name suggests" this, "as the name suggests" that, never once have you even said what the name is to the reader.
It's nice to have an article about std::simd that was actually voted in. Most others use the old std::experimental::simd reference implementation which is problematic.
My only complain is the minmax example where you could have chosen a better set of numbers. As it is it's not possible to know if std::simd::minmax return the highest numbers horizontally or vertically.
Thank you for the nice writeup! I have a codebase (open source, but I am the only dev, don't want to self-dox) that uses SIMD instructions via intrinsics extensively. The syntax here looks nicer than intrinsics, but I don't think that is enough to make me switch from C++17 to 26.
Are there other considerations I should have when considering adopting std::SIMD over a working intrinsics implementation?
My feeling has always been that by the time you're handcrafting SIMD code, you really REALLY care about performance on a particular CPU, and SIMDe lets you target that directly so you can solve the fun puzzle with all the very specific shuffles and etc to squeeze out the last drop of performance on the one you care about.
But at the same time, it'll (a) most likely be faster than scalar code on a different architecture and (b) remains testable on all platforms, so you can test your ARM specific NEON code on your x86 CI servers.
Hm, that is surprising:) With SIMDe you are tying yourself to one platform in the sense that other platforms will have to do extra work to match the exact instruction semantics. This is especially painful for integer dot products, which differ in ways that Highway can bridge, but raw NEON or x86 have to do extra work. It is also possible to specialize your Highway implementations for some targets.
The mask section clicked for me. Framing it as the if-else of the SIMD world, instead of branching in the hot path, made the control flow part a lot clearer than the usual register talk. Also noted the warning about keeping std::simd out of a public interface because of ABI problems. Is that still the main blocker for using it in a library, or is compiler support the bigger one right now?
37
u/Icy_Neighborhood2100 23d ago
Nice spelling mistakes.
Good sign in this day and age!
33
u/James20k P2005R0 23d ago
uhhhhhhhh ducks
6
u/schmerg-uk 23d ago
Nice - I wrote our SIMD C++ classes (also quant finance but less low latency, more pricing and risk, still lots of CPU load) nearly 10 years ago and I'll be keeping an eye on this to see how closely it maps to our wrappers.
Ours is focused almost entirely on 64bit doubles, and with a particular focus on ensuring numerically consistent results whether 128bit, 256bit or 512bit vectors are used. So for example we prefer to do 8-way summing of a vector of doubles with a routine that knows to use 1 accumculator register for 512bit, 2 registers for 256bit or 4 registers for 128, and then to the sum the final 8 accumulations in a consistent manner.
Any while the compilers are better at autovectorising simple loops, they're subject to use not allowed then to apply optimisations that can change numerical consistency. We can choose to explicitly call the 8 way sum above, but we can't have a sum function that, depending on the hardware and the whim of the compiler's mood at the time, could generate code for 1, 2, 4, 8 (or more) summing from compile to compile.
And we then [... uh oh.. secret sauce here ... ] which is where it really starts to win.
Also worth noting that, admittedly not so much these days, but the AVX (256bit) bit registers on early CPU generations had half the register width powered down (and the ALU upper halves etc) and would only power up on demand, and this came with power and heat penalties that, back then, forced a CPU clock penalty, and even today is still likely to reduce the overhead for the CPU clock to boost to higher speeds when thermals etc allow. For a long time AVX simply wasn't worth it for general purpose work... if you weren't going to doing intensive simd loops for 10s of milliseconds or longer at a time (and we're not a supercompute / HPC style workload) then it was slower to use AVX than to use SSE2
Anyway, nice write up, I'll try to come back to it from time to time
11
u/sephirothbahamut 23d ago
Advice for the article writer: Explain your acronyms.
Nowhere in theintroduction do you mention what SIMD stands for, nor in the "What is SIMD" paragraph.
It only suggests that to people who already know what "SIMD" stands for. For a reader who doesn't and seees a "What is SIMD" chapter trying to understand, those words are nonsense.
You keep saying "as the name suggests" this, "as the name suggests" that, never once have you even said what the name is to the reader.
2
u/FckXFckMusk 23d ago
Bookmarked, thanks for this.
2
u/StudentTraditional64 22d ago
Thank you for this!
It's nice to have an article about
std::simdthat was actually voted in. Most others use the oldstd::experimental::simdreference implementation which is problematic.My only complain is the minmax example where you could have chosen a better set of numbers. As it is it's not possible to know if
std::simd::minmaxreturn the highest numbers horizontally or vertically.I changed the numbers https://godbolt.org/z/P13nnGdjr.
Now we can see that 4 is part of
min_valdespite being bigger than other numbers inmax_val.1
u/IMJorose 23d ago
Thank you for the nice writeup! I have a codebase (open source, but I am the only dev, don't want to self-dox) that uses SIMD instructions via intrinsics extensively. The syntax here looks nicer than intrinsics, but I don't think that is enough to make me switch from C++17 to 26.
Are there other considerations I should have when considering adopting std::SIMD over a working intrinsics implementation?
1
u/Sachu_James 23d ago
The mask section clicked for me. Framing it as the if-else of the SIMD world, instead of branching in the hot path, made the control flow part a lot clearer than the usual register talk. Also noted the warning about keeping std::simd out of a public interface because of ABI problems. Is that still the main blocker for using it in a library, or is compiler support the bigger one right now?
1
u/angryduck01 20d ago
it's still fast then -03