5 ms·
> The conventional wisdom is that it is difficult to achieve real gains from SIMD. This has been my experience often times I misunderstood how much can be gain
by a1o 2y ago
> The conventional wisdom is that it is difficult to achieve real gains from SIMD.
This has been my experience often times I misunderstood how much can be gained by using SIMD, and preparing the data to be "eaten" by SIMD instructions is not trivial. I have many times attempted to use just to profile and see it didn't improve things at all and made the code really hard to understand.
Kudos for Erin here this is really hard work and it's great it paid off well and gave good results here!
- bob1029 2y ago> preparing the data to be "eaten" by SIMD instructions is not trivial I've always found my best experiences with SIMD to be one level removed from the actual scary bits. I.e., using primitives from libraries which are inherently optimized. My favorite SIMD abstraction right now is Vector<T> in .NET: https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector-1 https://learn.microsoft.com/en-us/dotnet/api/system.numerics... If you're worried you'd get that one wrong too, you can go up another level of abstraction and use something like Matrix4x4 and its members which are also optimized.
- neonsunset 2y agoInterestingly enough, Vector<T> itself is a bit limited and has smaller API than Vector128/256/512<T>. It is being improved to match those and then expand further, but it happens incrementally, in 8, now in 9 and more changes after - after all, compiler treats it pretty much the same as vector of respective width under the hood. The main problem with writing SIMD code for the first time is it's a learning curve to understand that the performance improvement doesn't come from just performing n element operations per single instruction but also reducing the book-keeping that usually comes per element per loop iteration like conditional branches to terminate the loop, branchy element selects over branchless shuffles in vectors, loading more data at a time, etc. Which is why many first time attempts lead to wrong impression that vectorization is hard, while the truth is they just stumble into known "don't do that, also do less" traps like needlessly spilling vectors or writing to intermediate buffers instead of directly, modifying individual vector elements or even iterating them, avoiding actual vector operations. There's a new-ish guide on vectorization if you're interested: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/vectorization-guidelines.md https://github.com/dotnet/runtime/blob/main/docs/coding-guid...