Topic

Hazy Research

All digests tagged Hazy Research

Lecture 112: Production Megakernels for Real-World Inference thumbnail

· 58:05

Lecture 112: Production Megakernels for Real-World Inference

The lecture details 'megakernels,' a novel approach for optimizing production inference by moving beyond traditional kernel-based GPU programming models. Instead of launching multiple small kernels with associated overheads (e.g., global synchronization, SRAM clearing), megakernels fuse the entire forward pass into a single, persistent kernel running on an on-device interpreter. This significantly reduces launch overhead and enables fine-grained scheduling by allowing cores to dynamically pick up slack from slower units, maximizing GPU utilization.

Key takeaways

  1. Mega Kernels vs. Traditional Kernels 2:00

    Traditional GPU programming involves launching many small, self-contained kernels (grids) sequentially, incurring overheads like global synchronization and SRAM clearing between launches. Mega kernels persist the entire forward pass into one kernel, eliminating these boundaries.

  2. Compiler Search and Optimization 5:20

    The system uses a compiler search mechanism to decide whether to mega-kernelize an operation or leave it as a traditional kernel graph (e.g., using Kublo ops). The choice is based on minimizing wall-clock runtime, especially when arithmetic intensity is low.

  3. Symbolic Representation of Work 8:00

    To handle dynamic shapes (e.g., sequence length $S$ and context length $P$), the system represents tensor shapes, extents, strides, and barriers symbolically using expressions. This allows the compiler to generate a single work queue that doesn't need rebuilding when runtime dimensions change.

  4. Dependency Tracking (Barriers) 6:20

    Fine-grained dependency tracking is managed using barriers, which are treated as tensors. The goal is to maximize the number of barriers by partitioning tensor dimensions by dependency, allowing consumers to start processing before all producers have finished.

Watch on YouTube Full article