by bee_rider · 2w ago · 0 comments
I try to push the computations involve in the critical path up as high as possible, and then just hope that between the compiler and hardware somebody’ll take advantage of that.
I haven’t tuned a ton of kernels though, I mostly do linear algebra stuff and good BLAS implementations do better than I could hope to.
Modern x86 CPUs have multiple execution ports, with duplicated hardware for the same operations, and the exact same operation can be performed in different ways.
As a toy example, multiplying a number by 2 can be done using multiplication, a bit shift, addition (adding the value to itself), or the pointer calculator. On x86 CPUs, these instructions can execute simultaneously on different ports, allowing you to perform six or more operations in parallel. This means you can achieve higher throughput by using different implementations of the same operation instead of relying on a single instruction.
You can't leave this to the compiler. It chooses only one implementation, leaving other execution ports unused.