Why a GEMM is tiled
GPT-2's MLP up-projection multiplies the block's 128 × 768 activations by a 768 × 3072 weight . Computed naively, each output walks a row of and a column of ; each weight is used by all 128 rows, but by the time a row comes back to it the weight has long left the cache, so 's 9.4 MB is read from memory over and over. Tiling reorders the loops so that a small block of each matrix is loaded once and reused many times while it sits in a fast level of the memory hierarchy: registers, L1, L2.
The scheme the Tiling tab records is the one high-performance BLAS libraries use (Goto and van de Geijn, 2008; BLIS): an innermost micro-kernel keeps an tile of in registers and adds one outer product per step of ; around it, cache blocks keep a panel of in L1 and an block of in L2; and the outermost loop splits among the threads.
The loops Inductor writes
With weights frozen and max-autotune on, Inductor writes this GEMM itself, as a C++ template instantiated for the exact shapes (its other option is a library call; the Autotuning tab shows which it keeps). The loop nest panel is the generated code, and its first lines fix every tile size as a constexpr: here , , register blocks (all 128 rows) and , and each of the 10 OpenMP threads takes a 128 × 312 share of . The output, cut into tiles picture draws the three levels from those numbers; switch tile level to highlight each one and its loop.
The micro-kernel is because NEON registers hold four floats: 4 rows × 24 columns is 24 vector accumulators, which with the six vectors of B and the broadcast value of A fill nearly all of the 32 vector registers an ARM core has. Each step loads one row of the panel and broadcasts 4 values of , then does 24 vector fused multiply-adds.
Inductor's rule for the cache blocks
Inductor picks the cache blocks with a short analytical rule, shown in the rule table with this CPU's cache sizes as PyTorch reports them: a panel of must fit in 80 % of the L1 data cache, so unless all of K fits; and as many rows of as fit in half of L2 form , with . This is the analytical approach of Low et al. (2016), who derived BLIS's block sizes from cache parameters instead of searching for them.
What the sweeps show
Each sweep overrides one knob through Inductor's own settings (cpp.gemm_cache_blocking, cpp.gemm_thread_factors, or keeping one micro-kernel), compiles again and reads the tile sizes back from the new kernel, so the picture redraws for any row you click. All configurations, plus eager and the ATen version, were timed together in 25 interleaved rounds, so a busy spell on the machine slows them alike.
At this size the knobs hardly matter: every configuration's median lies between 0.96 and 1.07 ms, a narrower range than one configuration's spread from its fastest round to its median. Each thread's share of A and B (about 1.3 MB) fits in the L2 cache PyTorch reports anyway, so the blocks have little to win. The template, with the GELU computed inside its loops, also ties ATen's GEMM followed by a separate generated GELU kernel, and eager. The Autotuning tab searches the same knobs on the plain GEMM, where the register tile does separate: every 4 × 24 configuration beat every 8 × 8 one.
Where it came from
Blocking for the memory hierarchy goes back to the loop-tiling work of the early 1990s (Wolf and Lam, 1991; Lam, Rothberg and Wolf, 1991, who showed how cache conflicts make the best tile size hard to predict). Goto's GEMM and BLIS fixed the layered structure used here. Halide and TVM made tiling a schedule a compiler can choose per operator, and Triton (Tillet et al., 2019) a block-level programming model for GPUs, which is what Inductor emits there. The Autotuning tab times the choices instead of predicting them.
Papers
- Anatomy of high-performance matrix multiplication The layered GEMM: a register micro-kernel inside L1- and L2-resident blocks of B and A, as Inductor's template does.
- BLIS: A Framework for Rapidly Instantiating BLAS Functionality The five loops around a micro-kernel, with only the micro-kernel written per machine.
- Analytical Modeling Is Enough for High-Performance BLIS Deriving the block sizes from cache sizes, the kind of rule Inductor uses instead of a search.
- A data locality optimizing algorithm Loop tiling as a compiler transformation for reuse in the cache.
- The cache performance and optimizations of blocked algorithms Why blocked code is so sensitive to the block size: cache interference.
- Triton: an intermediate language and compiler for tiled neural network computations Tiles as the unit of GPU programming; what Inductor writes on NVIDIA and AMD GPUs.