Exploring GPU Algorithms with compute-sim
compute-sim started from a practical frustration. The only GPU I had was an old AMD laptop iGPU that AMD's developer tools no longer supported. So I wrote a CPU simulator to experiment with compute shaders instead. The project runs shader-like Nim code on the CPU. It supplies the GLSL pieces used by compute algorithms: invocation IDs, workgroups, subgroups, shared memory, barriers, and atomics. I don't use it to estimate GPU performance. I use it to check an algorithm and to watch a small group of invocations execute it. Reduction, scan, and matrix multiplication are the examples I return to most often. None has complicated arithmetic. All three become interesting when the arithmetic is divided among many invocations. Enough of the execution model A dispatch is split into workgroups. gl_GlobalInvocationID identifies an invocation across the whole dispatch, while gl_WorkGroupID and gl_LocalInvocationID locate it inside a workgroup. Workgroups are split again into...

