5 ms·
To someone just hearing about SIMD, anyone care to give an experience infused introduction? Is it worth the hassle only in rare cases?
by dmos62 7y ago
To someone just hearing about SIMD, anyone care to give an experience infused introduction? Is it worth the hassle only in rare cases?
- tombert 7y agoIf you are just hearing about it, there's a good chance that you're not doing any kind of elaborate matrix math, so it's tough to say if it's useful. It's incredible useful if you're doing a lot of stuff involving matrices (graphics, image/video processing, neural-net stuff, stuff like that). If you have any interest in that topic, it's absolutely worth learning how to use SIMD (or at least learning a library that takes advantage of SIMD in your language of choice).
- augustt 7y agoCompilers are really smart, so in many cases they will vectorize without even asking - no hassle involved. Some examples here: https://llvm.org/docs/Vectorizers.html https://llvm.org/docs/Vectorizers.html
- TazeTSchnitzel 7y agoGCC and Clang will try their best to vectorise simple code, but if you try to write more complex algorithms, they will have a more difficult time and you may end up trying to massage your code to be more vectoriser-friendly. Auto-vectorisation is no substitute for a predictable SIMD programming model.
- qppo 7y agoThey tend to stumble over data dependencies and for floating point math they can't reorder instructions as well (unless you explicitly disable IEEE754 compliance). There are a number of structured approaches to rewriting code to be SIMD friendly, but you do need a degree of explicitness to get what you want out of the compiler.
- opportune 7y agoSome proprietary compilers provide tools to explicitly instruct a block of code to be vectorized via annotations
- nickysielicki 7y ago> Is it worth the hassle only in rare cases? Vectorization is not always faster. It's important to understand that modern processors can perform work on >100 instructions in a given cycle, and not all instructions take equal amounts of time. So reducing a dozen instructions to a single instruction doesn't necessarily mean that the single instruction is going to be faster.
- atq2119 7y agoThis is misleading, at least if you're looking at a single core. A single core can have >100 instructions in flight, but most of them will be waiting for their operands to arrive. The theoretical maximum throughput is gated by the instruction decoders and execution units, and is an order of magnitude lower.
- nickysielicki 7y agoThat's fair to call me out on that, what I said wasn't clear. I think the broader point still stands though: don't look at the number of ISA instructions and think that fewer instructions necessarily means performance improves. I think that we also miss a piece of the puzzle in terms of what happens once you leave ISA instructions and get into uops. There's magic inside there and it's completely opaque.
- vardump 7y ago> So reducing a dozen instructions to a single instruction doesn't necessarily mean that the single instruction is going to be faster. Are you saying dozen scalar instructions can be faster than one vector instruction? That's wrong 100% of time on modern CPUs.
- nickysielicki 7y agoYeah, I think there exists a case where this is possible. Let me play around with it this weekend and I'll comment here if I find anything.
- dahart 7y agoGPUs are SIMD machines, does that color whether it seems rare? Coming from a graphics background and working on GPUs, I am super biased, but I say it's very worth the hassle. The easiest intro IMO is check out & play around in ShaderToy. You don't have to know much about SIMD to write shaders, but once you start paying attention to how the machine works, you can make it go really fast. In general, using something like CUDA is similar to C++ you just have to make sure all your threads do as close to the same thing as possible in order to see good perf.
- xioxox 7y agoIt's certainly useful for quite a lot of mathematical science code. In my experience compilers are not very good at autovectorizing anything but the most simple loops and writing SIMD intrinsics is necessary to obtain the maximum output of the processor.
- calaphos 7y agoThe cpu just takes a bunch of numbers and applies the same operation on them in one instruction instead of a bunch single ones. E.g. if you are writing some simulations/game code where you deal with 3d vectors a lot the use case is there a lot. Is it worth writing the custom instruction intrinsics yourself? Most likely no as the compiler often (!) does a good job at auto vectorizing or the underlying library already uses them (I think c# vector types does).