Author explains how CPU parallelism lessons carry over to GPU kernels
In the second installment of a free GPU kernel engineering series, the author uses pure CPU code to explain several performance principles that carry over to GPUs. A single-accumulator loop such as `sum += a[i] * b[i]` forms a dependency chain and needs multiple independent accumulators (roughly latency times throughput) to fill the pipeline. Floating-point addition is not associative, so compilers keep the order unless `-ffast-math` is enabled or `#pragma omp simd reduction(+:sum)` is used per loop; GPU reductions have the same non-determinism. Branch cost depends on predictability: the author says a sorted versus random-access loop differs by [X] times at -O0 and largely disappears at -O2 because the compiler removes the branch. Per-thread partial sums placed in one small array cause false sharing on a shared 64-byte cache line, and padding gave an [X]-fold speedup. The author also notes the dot product is memory-bound, with only 2 floating-point operations per 8 bytes, so bandwidth sets the ceiling, and states the data comes from a single machine, intrinsics assume AVX2, and latency/throughput are typical Intel figures.
This is the second installment of the series, and the author states explicitly that it contains no GPU code; the aim is to explain CPU parallelism concepts first, because most GPU performance ideas are scaled-up versions of CPU ideas. At the end, the author asks readers whether the false-sharing explanation is wrong or oversimplified, and which CPU lessons are best suited to carrying over to GPUs.
For developers doing kernel optimization, the directly reusable checks include: using multiple accumulators to break dependency chains; isolating a single effect when measuring by using `-fno-tree-vectorize` and cache-sized arrays; looking at compiler-generated code before attributing results to hardware; and using padding to keep per-thread partial sums off the same cache line. The author also cautions that these numbers come from only one machine and should not be treated as a general benchmark.