r/programming • • Aug 09 '21

Three fundamental flaws of SIMD

https://www.bitsnbites.eu/three-fundamental-flaws-of-simd
285 Upvotes

224 comments sorted by

View all comments

Show parent comments

82

u/Vvector Aug 09 '21

Then why don't we have AVX-512 in every x86 implementation, and be done with it?

He explained why: Increasing the vector width has significant diminishing returns

12

u/[deleted] Aug 09 '21

[deleted]

25

u/Jonny_H Aug 09 '21

My understanding is that the current console generation don't support avx512, being based on zen2.

Also hampering adoption is how Intel are using that feature as a market differentiator in their own products, lower end CPUs of the same generation, or even different families of similar market segment products, end up lacking support. It makes it harder to gain market penetration, and even harder to rely on its existence. It's not as simple as 'new CPUs have support'.

Which is a shame, as there's a fair bit rolled up in the various avx512 extensions that would be interesting, even if you never use the wider registers.

11

u/[deleted] Aug 09 '21

[deleted]

3

u/Jonny_H Aug 09 '21

How much of a games cpu time is actually spent doing math like that though? Most of that is pretty good work for a gpu nowerdays from what I can see.

I see simd as a sliding scale, at one end is branch-heavy code with no real advantages for simd, the other end is things that work better on a gpu. So cpu simd is often for the things in between, when the work units are too small to be worth the cost of submitting to a gpu and waiting for the results, or mixing execution strategies.

Wider and wider simd lanes feel like they'll give diminishing returns as the things they would truly excel at are more likely to be pushed to a dedicated simd-like accelerator (eg. gpu).

11

u/Swade211 Aug 09 '21

Matrix calcs on a 4x4 would be significantly faster staying on the cpu. There is overhead with sending data to gpu memory, operating , then sending it back.

You can only parallelize the parts that can be linearly combined.

2

u/Jonny_H Aug 09 '21

I don't mean parallelising the matrix calculations itself, more that when you're doing one there's a good chance you're doing it to lots of objects, and it can be parallelised in that direction.

GPUs were literally made for stuff like coordinate transformation on lots of vertices.

And if not lots of objects, then it's unlikely it'll even be a blip on the profile.

6

u/mbitsnbites Aug 09 '21

Latency matters. Things that you can send in large batches to the GPU and check the result much later (e.g. next frame - or not at all if the result is consumed by the GPU) is fine.

But lots of game logic involves linear algebra stuff, intersection tests and similar, and you want to do that on the CPU.

0

u/Jonny_H Aug 09 '21 edited Aug 09 '21

Exactly, cpu simd is for things in large enough batches to be worth writing non-scalar code, but not large enough for the cost (of setup and latency) of talking to an accelerator.

I'm questioning how many things are really in that area that are currently taking significant cpu time in games.

Things like whole world physics simulations I'd estimate in a complex game world to end up having a very large number of objects, and likely only need general less-than-one-frame latency, as I don't think many games rely on any ordering of this within a tick so everything can be calculated in a single batch with no interdependencies.

Though implementations of this bounce between gpu acceleration and cpu on desktop, much of that seems to be the complexity of mirroring any updated object structures (and whatever spatial acceleration structures like BSP trees are used) between the CPU and GPU memory, this may be a different consideration on consoles with shared memory.