KatInterview

GPU GEMM Speedup Limits and Tiled Memory Strategies

System DesignModel answer
MediumModel answerSystem Designamdahls-lawgpumatmul

Last updated

Apply Amdahl's law to a partially accelerated simulation, then explain GPU tiled matmul and the cost of virtual dispatch.

A C++ simulation library spends 80% of its wall-clock time in a CPU matrix-multiply (GEMM) routine and 20% in serial bookkeeping that resists parallelization. You are asked to move the GEMM onto a GPU.

Address three things:

  1. Quantitative ceiling. With the GEMM portion accelerated 50x on the GPU, what overall speedup do you get? What if the kernel were instead 500x faster? What is the absolute limit, and what does that imply about where to invest engineering effort next?

  2. Why naive GPU GEMM underperforms, and how tiling fixes it. Explain the memory-access behavior of a straightforward one-thread-per-output kernel. Then describe a tiled implementation: what gets staged where, why shared memory helps, how the load pattern changes, and what synchronization and hazards you must handle. Mention edge cases (dimensions not divisible by the tile size, bank conflicts).

  3. Virtual dispatch. Your library exposes an abstract kernel interface so the caller can pick a CPU or GPU backend at runtime. Explain what a virtual call costs in terms of branch prediction, pipelining and inlining — and at what call granularity that cost stops mattering.

Hints

Hint 1

Before computing anything, ask which fraction of the runtime can even be touched, and bound the answer by that fraction alone.

Hint 2

A 10x better kernel on a portion that's already small barely moves the total — compute the fraction after the first port before proposing more kernel work.

Hint 3

Arithmetic intensity (FLOP per byte moved) is the number you want: compare the naive kernel's value against the machine's FLOP/byte ratio to see whether it is compute- or memory-bound.

Hint 4

Shared memory buys reuse; the second barrier is what prevents a block from overwriting a tile another warp is still reading.