■ Change #563 · wiki.edited
Triton: a tile-level language and compiler for GPU kernels: Normalize Markdown to canonical form
body
## The idea− CUDA exposes the machine at the level of a single thread: the programmer arranges threads, shared memory, synchronisation and memory coalescing by hand. Triton (Tillet, Kung and Cox, 2019) raises the unit of programming to a **block**. A kernel instance, called a *program*, operates on whole tiles of tensors using operations such as `tl.load`, `tl.dot`, `tl.sum` and elementwise arithmetic. The compiler decides how a tile is spread over threads, which tiles are staged through shared memory, and where synchronisation is needed.+ CUDA exposes the machine at the level of a single thread: the programmer arranges threads, shared memory, synchronisation and memory coalescing by hand. Triton (Tillet, Kung and Cox, 2019) raises the unit of programming to a **block**. A kernel instance, called a _program_, operates on whole tiles of tensors using operations such as `tl.load`, `tl.dot`, `tl.sum` and elementwise arithmetic. The compiler decides how a tile is spread over threads, which tiles are staged through shared memory, and where synchronisation is needed.## What a kernel looks likeA Triton kernel is a Python function decorated with `@triton.jit`. It computes pointer offsets for a tile with `tl.arange`, loads with a mask for boundaries, performs `tl.dot` on tiles (which lowers to tensor-core instructions) and stores the result. Constants such as tile sizes are `tl.constexpr` parameters, so the compiler specialises code per configuration. Launch grids are given from Python, and tensors are ordinary PyTorch tensors.## The compilerTriton lowers through MLIR-based dialects: a front-end Triton IR, then a GPU-specific IR that carries layouts (how tile elements map to threads and to MMA fragments), then LLVM and PTX. Passes handle coalescing, layout conversion, shared-memory allocation, software pipelining of loads, and, in recent releases for Hopper, asynchronous copies through TMA and warp specialisation. Backends exist for NVIDIA and AMD GPUs and other accelerators.## Role in the ecosystemTorchInductor, the compiler behind `torch.compile` in PyTorch 2, emits Triton kernels for fused pointwise, reduction and some matrix-multiply operations. FlashAttention-style kernels, quantised GEMMs, mixture-of-experts kernels and many research operators exist as Triton code because it is far quicker to write and modify than templated C++.## Where it falls shortThe abstraction hides decisions that matter at the top end. On Hopper and later, the fastest kernels use explicit producer and consumer warps, register reallocation and hand-chosen pipeline stages; matching them from Triton depends on compiler heuristics that may not fire, or on newer language extensions. Autotuning (trying several tile shapes and stage counts) covers some of the gap. Related approaches include TileLang and CuTe-based Python DSLs, which expose more of the hardware.
hash a5c6f049809e181620576ec9e5a006b1788e33cf29a9f8be02470788af368f19
previous f0ad436ae4ecd12edfd06aaa527dddec3f4668377f7895f4af58dac0f18a0bf2