by llm_nerd · 1y ago · 0 comments
It is interesting how often SIMD stuff is discussed on here. Are people really directly dealing with SIMD calls a lot?
I get the draw -- this sort of to-the-metal hyper-optimization is legitimately fun and intellectually rewarding -- but I suspect that in the overwhelming majority of cases simply using the appropriate library, ideally one that is cross-platform and utilizes what SIMD a given target hosts, is a far better choice than bothering with the esoterica or every platform and generation of SIMD offerings.
Point being, while not everyone is in a position this stuff is relevant (and not everyone who sometimes finds this stuff relevant can say it's relevant often), it's more widely applicable than you're suggesting.
If someone is an average developer building a game or a corporate information or financial system or even a neural network implementation, if you are touching SIMD code directly you're probably approaching things in a less than optimal fashion and there are much better ways to utilize whatever features your hardware, or hardware in the future, may offer up.
Now of course, many of these transformations can be wrapped in a higher-level API (think of sums over an array, reductions, string length, string encoding, etc.) but not all of them.
Of course, multithreading also exists to improve performance, but for many tasks, it's more worth it to run it on one core without the sync overhead, especially with data-parallel algorithms where you're doing the exact same thing on all of the data and you have a fairly large dataset. Or even better, you can combine the two, partition the data between multiple cores into a few small sets then use a SIMD "kernel" to process it. With extremely embarrassingly parallel problems, you can achieve 1000x speedups this way, not exaggerating. A typical speedup is much smaller but still, using your machine well can easily produce an order-of-magnitude difference in performance. If you read up on ISPC benchmarks, you'll find that for even any kind of existing, very branchy and not SIMD-friendly code, they regularly had a free 4x speedup without changing the behaviour or the result of the program.
Seriously, it's not that if you use SIMD-powered libraries then you're set for performance, if you have a holistic view of your system's performance, you can do really amazing things.
The point is that the average developers job in achieving this is not knowing every SIMD primitive for every platform. It is almost always folly to ever touch a platform's SIMD instructions unless you're one of the aforementioned library/compiler developers.
Instead the ordinary developer is usually best served by using equipped libraries and understand how to structure code where it can enable vectorization. Whether it's Eigen, or even the C++ compiler (which, in my experience, is often excellent at vectorizing code), or the Accelerate library on Apple platforms. These things mean that your code can adapt and exploit every possible platform they're deployed to, versus Jimmy SIMD who carefully made his SSE 3.2 instructions and his code was then lost in time.