Writing TPU Kernels in Pallas: Matmul on the MXU

From 12 TFLOPS to matching native XLA at 140 TFLOPS: How do you build an efficient Matrix Multiplication (Matmul) kernel for Google TPUs using JAX and Pallas?

In the second episode of the Bielik on TPU series, we leave memory-bound kernels behind and dive straight into compute-bound workloads on the TPU’s Matrix Execution Unit (MXU). We walk through mapping LLM projections (QKV, Output, LM Head), writing the reduction loops in Pallas with @pl.when guards, managing on-chip VMEM accumulator scratchpads, and building an automated grid autotuner to unlock peak hardware throughput.

Key highlights covered:

Resources: