arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.20399cs.LGcs.AI
收藏

ThunderKittens:简单、快速且可爱的 AI 内核

ThunderKittens: Simple, Fast, and Adorable AI Kernels

Stanford University(斯坦福大学)

Benjamin F. Spector, Simran Arora, Aaryan Singhal, Daniel Y. Fu, Christopher Ré

AI总结:

本文提出 ThunderKittens 框架,用对应 warp、thread-block 和 grid 三层 GPU 层次结构的少量抽象简化高性能 AI 内核开发,并在 GEMM、注意力、状态空间模型和线性注意力上取得追平或显著超越现有内核的性能。

摘要:

将 AI 架构映射到 GPU 硬件所面临的挑战,正在成为 AI 进展中的一个关键瓶颈。尽管已经付出了大量努力,但即使在线性注意力等成熟算子上,手写定制内核也无法达到其理论性能阈值。GPU 多样化的硬件能力或许表明,我们需要种类繁多的技术才能实现高性能。然而,我们的工作探索了是否可以用少量关键抽象来显著简化这一过程。我们提出 ThunderKittens(TK),这是一个用于编写高性能 AI 内核,同时保持易于使用和维护的框架。我们的抽象对应 GPU 层次结构的三个层级:(1)在线程束(warp)层级,我们提供 16×16 矩阵分块作为基本数据结构,以及类似 PyTorch 的、作用于分块的并行计算操作;(2)在线程块(thread-block)层级,我们提供一种模板,用于在并行线程束之间重叠异步操作;(3)在网格(grid)层级,我们提供支持以帮助隐藏块的启动、拆除以及内存开销。我们通过给出一系列 AI 算子的内核来展示 TK 的价值:这些内核在性能上追平或超过以往内核。我们在 GEMM 和注意力推理性能上追平 CuBLAS 与 FlashAttention-3,并在注意力反向传播上超过最强基线 10–40%,在状态空间模型上达到 8 倍,在线性注意力上达到 14 倍。

英文摘要:

The challenge of mapping AI architectures to GPU hardware is creating a critical bottleneck in AI progress. Despite substantial efforts, hand-written custom kernels fail to meet their theoretical performance thresholds, even on well-established operations like linear attention. The diverse hardware capabilities of GPUs might suggest that we need a wide variety of techniques to achieve high performance. However, our work explores whether a small number of key abstractions can drastically simplify the process. We present ThunderKittens (TK), a framework for writing performant AI kernels while remaining easy to use and maintain. Our abstractions map to the three levels of the GPU hierarchy: (1) at the warp-level, we provide 16x16 matrix tiles as basic data structures and PyTorch-like parallel compute operations over tiles, (2) at the thread-block level, we provide a template for overlapping asynchronous operations across parallel warps, and (3) at the grid-level, we provide support to help hide the block launch and tear-down, and memory costs. We show the value of TK by providing kernels that match or outperform prior kernels for a range of AI operations. We match CuBLAS and FlashAttention-3 on GEMM and attention inference performance and outperform the strongest baselines by $10-40\%$ on attention backwards, $8\times$ on state space models, and $14\times$ on linear attention.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑