MegaOps:一种兼具PyTorch式模块化与Megakernel性能的内核重叠框架
MegaOps: A Kernel Overlapping Framework with PyTorch-like Modularity and Megakernel Performance
AI总结:
本研究提出MegaOps框架,通过在独立CUDA流上部署依赖内核并以数据块同步替代内核融合,在复用现有内核的同时,达到与Megakernel相当的性能,且解码、预填充吞吐量优于基线。
摘要:
现代机器学习框架采用按算子划分内核的范式执行模型,该范式将每个算子作为独立的GPU内核运行,具备模块化特性,开发者可组合各类内核实现并单独对每个内核进行性能分析。但该范式以整个内核为粒度施加依赖关系,在依赖内核间形成屏障,导致流式多处理器闲置、计算与通信串行化,且无法在前序内核运行时预取权重。Megakernel通过将整个层或模型的算子融合为单个内核消除内核屏障,却放弃了按算子划分内核范式的模块化特性。本研究探讨按算子划分内核的机器学习框架能否达到Megakernel的性能。核心见解是消除内核屏障无需融合内核,据此开发MegaOps框架,该框架将依赖内核部署在独立的CUDA流上,并在中间张量的独立数据块上强制执行每个依赖关系,生产者内核写入、消费者内核读取该中间张量。由于内核在数据块而非线程块上同步,采用相同数据分块的任意两个内核无需修改即可组合。在单H100、A100、L40 GPU及4×A100、8×H100的多GPU服务器上,针对稠密Llama3和Qwen3模型评估MegaOps,结果显示其吞吐量与手动调优的ThunderKittens Megakernel相当,解码吞吐量为最佳基线的1.09倍-1.10倍,预填充吞吐量为最佳基线的0.98倍-1.10倍,同时可复用现有Triton、cuBLAS和cuDNN内核。
英文摘要:
Modern ML frameworks execute models using the kernel-per-operator paradigm, which runs each operator as a separate GPU kernel. This paradigm is modular, since developers can compose various kernel implementations and profile each kernel in isolation. However, this paradigm enforces dependencies at the granularity of entire kernels, which places a barrier between dependent kernels. These barriers cause streaming multiprocessors to idle, serialize computation and communication, and prevent a kernel from prefetching its weights while the preceding kernel runs. Megakernels remove kernel barriers by fusing the operators of an entire layer or model into a single kernel, but they give up the modularity of the kernel-per-operator paradigm. In this work, we ask whether a kernel-per-operator ML framework can perform on par with megakernels. Our key insight is that removing kernel barriers does not require fusing kernels. We develop MegaOps, a framework that launches dependent kernels on separate CUDA streams and enforces each dependency on individual tiles of the intermediate tensor that the producer kernel writes and the consumer kernel reads. Since kernels synchronize on data tiles instead of on each other's thread blocks, any two kernels that adopt the same data tiling can be composed without modifying either kernel. We evaluate MegaOps on dense Llama3 and Qwen3 models on single H100, A100, and L40 GPUs and on multi-GPU servers with 4$\times$A100 and 8$\times$H100. Our MegaOps framework matches the throughput of hand-tuned ThunderKittens megakernels, and achieves 1.09$\times$-1.10$\times$ the decode throughput and 0.98$\times$-1.10$\times$ the prefill throughput of the best-performing baseline, while reusing existing Triton, cuBLAS, and cuDNN kernels.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。