liveBook · Manning

@triton.jit

As explained in GPU Programming with Triton

@triton.jit is a Triton decorator that marks a Python function for JIT compilation into a GPU kernel.

@triton.jit marks a Python function as a Triton GPU kernel. Triton captures the function and compiles it when it is first launched, so defining it does not execute GPU code. The compiled kernel runs across parallel program instances on the GPU, rather than executing as Python source. section 1.1.1 section 1.3.3

The triton module provides the compiler and runtime; triton.language supplies operations used inside kernels, including loads, stores, and index helpers. The compiler handles much of the low-level work of mapping the computation to the GPU. section 2.2.1 section 2.1

On the first launch, Triton lowers the kernel through intermediate representations and generates GPU code specialized for the argument types and shapes. The compiled result is cached for subsequent calls with the same types and shapes; new types or shapes incur compilation again. A first-call measurement therefore includes compilation as well as computation. section 2.2.1 section 1.4

Figure 1.9 A Triton kernel’s path from source to execution. The host defines the kernel and compiles it into a resident binary on the first call, then launches that binary across the PCIe boundary; the device receives a grid of blocks and distributes them across its Streaming Multiprocessors as each one becomes free.
Triton kernel lifecycle from definition to execution

Follow the kernel from its Python definition and first compilation to a grid launch on the GPU. section 1.4

The compiler first represents the kernel as an abstract syntax tree, then translates it into hardware-agnostic Triton IR (TTIR). Triton GPU IR (TTGIR) adds GPU-oriented details such as data layouts, memory access, and mappings to the thread structure. section 2.3.1

Figure 2.10 The Triton compiler pipeline: from user code through AST, TTIR, and TTGIR to GPU execution via LLVM-IR, PTX, and CUBIN.
CH02 F10 Fartale

Trace the compiler pipeline from Python code through intermediate representations to GPU execution. section 2.3.1

The Python package alone is not enough: the matching GPU runtime must be installed. NVIDIA hardware requires CUDA 11.8 or later; AMD hardware requires the ROCm stack. section 1.1.1

How GPU Programming with Triton covers it

How deep it goes
Traces compilation from Python parsing through TTIR and TTGIR to GPU execution, including specialization and caching.
Examples
Uses an import-and-decorator listing and compiler pipeline diagrams to illustrate kernel setup and execution.
What it assumes
Introduces Triton GPU programming without requiring prior CUDA experience.
What you can do after
Apply it via Triton to mark a Python function for GPU kernel compilation and recognize first-launch compilation overhead.
How it connects
Connects JIT compilation with GPU kernels, program instances, intermediate representations, and kernel launches.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of GPU Programming with Triton. The section links point to the parts of the book it draws on.