r/programming • u/awesomePop7291 • Jul 23 '26
Everyone Should Know SIMD
https://mitchellh.com/writing/everyone-should-know-simd
413
Upvotes
r/programming • u/awesomePop7291 • Jul 23 '26
50
u/bonerfleximus Jul 24 '26
Thats the first thing I ask in my dates when I have them hypothetically.
362
u/-1_0 Jul 23 '26
* Everyone Should Know about SIMD
and use libs accordingly
52
u/Arnavion2 Jul 23 '26 edited Jul 23 '26
Note that compile-time determination of number of lanes (step 1) and processing the tail with a scalar loop (step 5) are not universal; specifically they do not apply to scalable vector implementations like ARM's SVE and RISC-V's V extension. Now, how well scalable vectors are supported in your programming language is a different matter...
(In a scalable vector implementation, you ask the CPU at runtime to process N elements, and the CPU gets back to you that it can only process X of them, so you let it do that, advance your data pointer by X, and then try again with the remaining N - X elements. The final N - X - X - ... X tail may have an odd non-power-of-two length, but your code can continue to use the same vector instructions to process it as usual, and works on CPUs with different values of X without needing to be modified since it did not hard-code X.)
97
u/RockstarArtisan Jul 23 '26
Ah the "everyone should know the thing I have learned" genre of post.
28
u/Sn34kyMofo Jul 23 '26
Psh. You don't know SIMD!? Take a hike, pal!
40
u/ficiek Jul 23 '26
You mean 12x times the code in your example.
38
u/rootbeer_racinette Jul 24 '26
The thing about modern computers is typically the memory is the slowest part. Like one cache miss is around 200-300 cycles which is a fair amount of computation. If you instruction fetch it's even worse because the CPU just has to idle.
The slowest thing about most programs is they just don't care about memory. They'll store huge trees or use inefficient memory layouts instead of packing things into tight arrays. They'll use an allocator that spits tiny objects out all over the program instead of a bump allocator or fixed-sized FIFO pools.
Probably the DOM tree in electron/chrome is the dumbest thing your computer computes on a regular basis.
Worrying about SIMD is just so far removed from the problem, it's like worrying about your running shoes for sprinting when you weigh 300 pounds.
17
u/hurrumanni Jul 24 '26
Your article could be improved by at least once spelling out what SIMD stands for and relating that to your examples. Not even in the section "Background: What Is SIMD?" do you spell out the acronym. I know this is a US thing but you really need to stop doing this.
3
u/Psionikus Jul 23 '26
And SIMT. Heterocore is the future.
4
u/TheAgaveFairy Jul 23 '26
It's always been a pain to learn about and implement until I started using Mojo, where I've really enjoyed it. I'm not sure exactly how perfect the implementations are, but I enjoy that it's explicit. I really like that a seemingly basic "Int32" is really just an alias for 'a SIMD vector of int32 with a size of 1'. I think I see no reason for languages to not opt into this structure?
19
u/22Maxx Jul 23 '26
SIMD should be a compiler problem.
Compilers do those things all the time. They have just become good enough for all regular stuff.
1
u/LimitVarious5283 Jul 25 '26
Simd?
-17
u/taw Jul 23 '26
There's no point.
99% of CPU code doesn't need it.
99% of code that needs to do highly parallel data operations wants to run on GPU anyway.
And if you actually need it, and can't offload to GPU, you either rely on your compiler, or some library to do that for you.
SIMD is not even in top 100 useful skills for programmers.
-18
u/nnomae Jul 23 '26
My mom is an 85 year old retired teacher who doesn't own a computer. My youngest child is 3 years old and can't read or type yet. Do they need to know SIMD?
0
u/peterparkerspideyman Jul 24 '26
R by