Every road to an NVIDIA GPU ends the same way: PTX, assembled by ptxas into SASS for one GPU generation. The compilers above it differ only in what they capture (one hand-written kernel, or a whole traced graph) and what they decide on the way down (which operations share a kernel, how a tile is split over threads); ptxas then decides registers and instruction order, and the driver decides which image in the binary runs.
Running examples (the parent topic's): the row softmax kernel of its Compiler explorer tab down the nvcc road, softmax(x * 0.125) @ w down the torch.compile road.
kb-gpu-lab:1 on an Apple M1 Pro laptop. With no NVIDIA GPU, nothing here ran on one: compiling needs no GPU, running does. torch.compile ran on the CPU, where Inductor writes C++; its Triton GPU code was generated without a device as on the Triton and Gluon page. Labels: compiled here run here (CPU) documented derived.You need kernels, threads and blocks (The CUDA programming model); the root's section 8 defines PTX, SASS and the fat binary in one paragraph.
Top row: what you write; middle rows: where fusion and tiling are decided; blue: PTX and ptxas, shared by almost every road. cuTile is the exception: its Tile IR goes to SASS through its own assembler, tileiras. Sources per road in section 1.
Every GPU compiler makes three kinds of decision. Fusion: which operations become one kernel, so intermediates stay in registers. Codegen: how a kernel's work is split over blocks, warps and threads, how wide each load is, which library to call instead (a matmul usually goes to cuBLAS). Assembly: which physical registers hold what and in which order instructions issue; on NVIDIA always ptxas (or tileiras), never the framework.
| Road | Captures | Who decides fusion | Codegen writes | To SASS via |
|---|---|---|---|---|
| nvcc | one CUDA C++ kernel | you, by hand | NVVM IR, then PTX (cicc) | ptxas |
| torch.compile (Inductor) | an FX graph traced from Python bytecode | Inductor's scheduler (below) | Triton on GPUs, C++ with OpenMP on CPUs; matmuls to libraries unless autotuned (Ansel et al. 2024, section 4) | Triton, then ptxas |
| XLA (JAX, TensorFlow) | StableHLO from a traced function | fusion passes ranked by a cost model on GPUs; "A fusion is always compiled to exactly one GPU kernel" | "a combination of “native” (PTX, via LLVM) emitters and TritonIR emitters", plus cuBLAS, cuDNN and NCCL calls (XLA GPU architecture) | LLVM NVPTX or Triton, then ptxas |
| TVM | a Relax graph (imported or written) | graph-level passes "such as operator fusion, and layout rewrites" (TVM overview) | TensorIR functions, scheduled by hand or by MetaSchedule's search; for CUDA, TVM 0.11 printed CUDA C and compiled it with NVRTC (build_cuda_on.cc, v0.11.0) | NVRTC, then ptxas |
| Triton | one block-level kernel | you, by hand (what goes in one @triton.jit) | TTIR, TTGIR (layouts, pipelining), LLVM IR | LLVM NVPTX, then Triton's own ptxas |
| cuTile | one tile-level kernel | you, by hand | CUDA Tile IR (threads not yet chosen) | tileiras, straight to SASS |
Documented, from the source in each row; TVM's CUDA path is from its 0.11 source and may differ later. XLA's own passes, refusal reasons and cost model are taught on XLA and compilation; Triton's stages on Triton and Gluon; torch.compile from the user's side on torch.compile from the user's side.
Graph compilers fuse in rounds: try every pair of nodes that may share a loop, merge the legal ones, repeat until nothing changes. Inductor on softmax(x * 0.125) @ w, x 64 x 256 run here, torch 2.14.1, CPU, TORCH_LOGS=fusion. Predict: a scale, a max, a subtract, an exp, a sum and a divide make how many kernels?
op0 is every scaled value finite?, op1 and op2 two row maxima, op4 the sum of the exps), two full-size pointwise nodes (op3 subtract, scale, exp; op5 divide) and the external matmul op6. Unfused, every arrow is a tensor written to memory and read back.op3 with op5 is refused: "cannot fuse op3 with op5: intermediate nodes between node1 & node2" (the sum must finish before any divide).OuterLoopFusedSchedulerNode). The matmul stays outside, an extern kernel.cpp_fused__softmax_abs_all_amax_eq_mul_ne_sub_0, then extern_kernels.mm; the wrapper allocates the buffers. The intermediates never leave the kernel's row loop.Nodes and log lines (under the figure) are Inductor's own (torch/_inductor/scheduler.py in 2.14.1).
The rule: a node fuses with another only when they share a loop over the same rows and nothing between them has to finish first. The extra row reductions are an algebraic rewrite: Inductor takes the maximum of the unscaled input and applies the scale after subtracting, guarded by a check that every scaled value is finite; the same rewrite appears in its GPU code for this graph on the Triton page.
The wrapper that runs the result: one fused kernel, then the library matmul.
The C++ kernel ( lines), as Inductor wrote it. Read it as a hand-written softmax: one OpenMP loop over the 64 rows; inside, a vectorised pass computing the row maximum (of x * 0.125 and of x, plus the finite check), a pass computing exp and the sum, and a pass dividing.
For a GPU Inductor writes Triton instead. For an RMSNorm forward, x * rsqrt(mean(x2) + eps) * w on 64 rows of 256 (generated without a device by the Triton page's stand-in driver), it is a triton_per_ kernel: a persistent reduction, each program keeping a whole row (r0_numel = 256) in registers, reducing it and writing the normalised row in one pass generated here, not runnable. Codegen also chose cache hints: the input row with evict_first (read once), w with evict_last (every row reuses it), which become load modifiers like those of section 4. Block sizes are left to the launcher, steered by size_hints; on a real GPU the autotuner times candidates. Below that, Triton's compiler and ptxas decide.
A .cu file holds two programs, host code for the CPU and device code for the GPU. nvcc splits them, compiles the device code once per target, packs the results into a fat binary embedded in the host object as data, and hands the host code to your C++ compiler. nvcc --dryrun prints every command without running it.
nvcc -arch=sm_90a. How many GPU code images end up inside the object file?Fig. 3 runs the real commands for the row softmax compiled here, CUDA 13.4.2: each program a box, each file it writes a slab (height on a log scale, sizes from the build with --keep). Blue is the host side, purple the generic compute_90 pass, teal the Hopper-specific compute_90a pass, orange SASS.
softmax.cpp4.ii, 1.23 MB; __CUDA_ARCH_LIST__=900 tells headers the targets). cudafe++, NVIDIA's C++ front end, separates host from device and replaces each kernel<<<grid, block>>>(args) with a launch stub, a host function that packs the arguments and calls the runtime: .cudafe1.cpp (1.16 MB) and .stub.c (1.6 KB).__CUDA_ARCH__=900 (how one file holds code for several generations behind #if __CUDA_ARCH__ >= 900), is 1.4 MB for a 32-line kernel, almost all CUDA headers. cicc lowers it to NVVM IR (NVIDIA's dialect of LLVM IR; NVVM IR specification), optimises it with LLVM (inlining, unrolling, which pointer points into which memory) and prints PTX per virtual target: compute_90.ptx, 6.1 KB.ptxas -arch=compute_90 writes nothing, so a Hopper-only instruction fails here (section 5's trap).__CUDA_ARCH_FEAT_SM90_ALL and __CUDA_ARCH_SPECIFIC__=900: PTX that may use wgmma and setmaxnreg, compute_90a.ptx, 6.1 KB.compute_90, SASS sm_90a and PTX compute_90a go into softmax.fatbin (11.0 KB), written out as a C array for the host compiler (softmax.fatbin.c, 30.2 KB); rm deletes the binary form.softmax.o, 17.8 KB, the object your linker sees. With -rdc=true (device functions called across files) nvlink would join cubins first.sm_90a.sm_90 and PTX compute_90.From nvcc --dryrun -O3 -arch=sm_90a -c softmax.cu (and -arch=sm_90), temporary paths shortened to <tmp>; file sizes from the sm_90a build with --keep. Script: src/code/nvcc_stages.sh.
The answer: three images (step 6), where -arch=sm_90 puts two. Section 5 explains the extra PTX copy and the trap it sets.
PTX (Parallel Thread Execution) is what cicc, LLVM's NVPTX back end and Triton write, and what ptxas reads: "a low-level parallel thread execution virtual machine and instruction set architecture", whose first goal is to "provide a stable ISA that spans multiple GPU generations" (PTX ISA 9.4, introduction) documented. No chip executes it: it describes an idealised GPU with unlimited registers, and each generation's assembler maps it onto real hardware. So PTX is the portable form of a kernel: H100 SASS cannot run on a B200, but PTX compiles for either. On the right, the whole PTX cicc wrote for the row softmax (sm_90a, -O3) compiled here:
add.f32, mul.wide.s32); there is no implicit conversion, cvt does it..global (device memory), .shared (the block's on-chip scratchpad), .local (per-thread, in device memory: where spills go), .const, .param (kernel arguments); in SASS LDG, LDS, LDL, LDC.cuobjdump -res-usage: ). ptxas decides which values share a register.setp.ge.s32 %p1, ... writes a 1-bit predicate, @%p1 bra $L__BB0_2 branches on it; any instruction can be predicated.%tid.x is threadIdx.x, %ctaid.x is blockIdx.x (a CTA, cooperative thread array, is PTX's word for a block), %ntid.x is blockDim.x.Every PTX file starts with its language version: CUDA 13.4 writes .version 9.4, and an assembler accepts only versions it knows. Triton 3.8.0 ships its own ptxas from CUDA 12.9 (recorded in the image), so the PTX above fails there run here:
Edit it to .version 8.8 and the old ptxas accepts the file (this kernel uses nothing newer); Triton writes .version 8.8 itself (). This one error is driver JIT compatibility: the driver's own ptxas compiles only PTX whose version it knows. "Applications that compile device code to PTX will not work on older drivers" (CUDA minor version compatibility) documented; the runtime reports cudaErrorUnsupportedPtxVersion, whose comment in the CUDA 13.4.2 headers reads "The most common reason for this, is the PTX was generated by a compiler newer than what is supported by the CUDA driver and PTX JIT compiler."
Fig. 4 follows the row softmax down the nvcc road, one plate per form of the kernel compiled here. Cubes are registers, the column the SASS instruction slots cuobjdump -sass lists (with the padding NOPs at the end).
%p), 74 floats (%f), 89 32-bit (%r) and 36 64-bit (%rd) values, almost each written once. cicc decided inlining (the warp reductions are gone as functions), the loops (rolled by #pragma unroll 1, the shuffles unrolled) and which pointer points into which memory, not registers.-O0 ptxas assembles the PTX nearly as written.-O1 up (same counts at all three) it removes redundant work, allocates registers and schedules: under a third of the instructions, 18 real registers for 230 virtual (1056 bytes of shared memory, no local memory, so no spills).sm_80, sm_90a, sm_100a and sm_120 (each from its own PTX): 224, 232, 240 and 224 instruction slots, 19, 18, 18 and 17 registers, and the third argument (ncols) read from c[0x0][0x170], 0x220, 0x390 and 0x390. Same PTX semantics, different SASS.So PTX shows what the front end asked for (which loads, which shuffles, whether a loop was unrolled); judge registers, spills, vector widths and instruction counts from SASS and the ptxas -v report, never from PTX.
ptxas turns PTX into SASS, the instruction set one GPU generation executes. NVIDIA does not publish its encoding, only the opcodes with one-line meanings (CUDA Binary Utilities, instruction set reference) and tools that print it: cuobjdump -sass for a binary, nvdisasm for a cubin. The parent's Compiler explorer tab lines SASS up against source; here, the grammar of one line, then the part nobody prints.
Pick a real instruction (right; softmax, sm_90a compiled here) and click any part of it.
| You see | It means |
|---|---|
R0 to R254, RZ | Per-thread 32-bit registers; RZ reads zero. R6.64 is the pair R6, R7 holding a 64-bit address. |
UR4, ULDC, S2UR | Uniform registers: one value for the whole warp, computed once on a separate datapath. The compiler moves whatever every thread would compute identically (block index, arguments, base addresses) into them. |
P0 to P6, PT, @!P1 | Predicate registers (one bit per thread); PT is always true. @!P1 STS ... stores only where P1 is false: divergence, as SASS shows it. |
c[0x0][0x220] | Constant bank 0, which holds the kernel's arguments; their offsets change between generations (Fig. 4, step 5). |
desc[UR6][R6.64] | A global address with a memory descriptor in a uniform register; in our sm_90a, sm_100a and sm_120 code, not in the sm_80 code ([R4.64]). |
SR_TID.X, SR_CTAID.X | Special registers, read with S2R or S2UR. |
.reuse | Keep this source operand in the operand reuse cache for the next instruction (one of the control bits below). |
Counts across the four kernels of the scoreboard replay below (the softmax on sm_90a and sm_100a, the tiled matmul and the Hopper wgmma tile on sm_90a); meanings from NVIDIA's tables.
The memory opcodes and their modifiers (.E, .128, .EF, .CONSTANT, LDGSTS) have a whole tab, Memory instructions, on GPU memory hierarchy; the tensor-core instructions (HMMA, HGMMA, UTCHMMA) belong to Libraries and tensor cores.
Since Volta every SASS instruction is one 128-bit word, part of which is control information ptxas writes for the warp scheduler. A GPU issues each warp's instructions in order and, unlike a CPU core, does not track register dependencies itself; ptxas, which knows each latency, writes the waits into the code. Jia et al. worked out the layout (Dissecting the NVIDIA Volta GPU Architecture via Microbenchmarking, section 2.1, 2018) independent reverse engineering, not documented by NVIDIA: 21 bits, from the top, of reuse flags (4), a wait mask (6), a read barrier (3), a write barrier (3), a yield bit (1) and a stall count (4).
MUFU.EX2) gets one of six scoreboards (SB0 to SB5; 7 means none), released when its result arrives; a consumer waits on that bit in its wait mask. Read barrier: the same for "do not overwrite this register until the store has read it". Yield: set, prefer to keep issuing from this warp.The replay on the right steps through a whole kernel: each instruction issues after its stall count, or first waits for the scoreboards in its mask; the six boxes show the register each scoreboard guards and the instruction that set it compiled here, decoded with Jia et al.'s layout. Try the softmax from the first LDG.E to the FMNMX that waits for it, or HGMMA and the WARPGROUP instructions in the wgmma tile.
src/code/sass_decode.py checks that on every instruction of six kernels for sm_80, sm_90a, sm_100a and sm_120: ; reading the 21 bits one or two positions off finds violations. So the 2018 Volta layout still describes ptxas's output for Ampere, Hopper and both Blackwells derived.Nsight Compute's stall reasons name these waits: "long scoreboard" is one set by a memory operation through L1 (global, local, texture), "short scoreboard" one set by shared memory or a special function (Nsight Compute profiling guide, warp stall reasons). The bits show, without a profiler, which loads the compiler expects you to wait on and how far apart it put them.
Bits 127 down to 105 of the instruction word. RB and WB: read and write barrier (scoreboard) indices; Y: yield.
"Issue cycles" adds the stall counts so far: the time one warp would take if no scoreboard ever made it wait and the scheduler never switched warps. A lower bound from the encoding, not a measurement.
Offset, guard, instruction, stall (S), yield (Y), write scoreboard (W), read scoreboard (R), wait mask, reuse flags, live registers after the instruction (nvdisasm -plr).
Counted from nvdisasm -plr, which marks for every instruction the registers still holding a value needed later; softmax, sm_90a compiled here.
Every NVIDIA GPU has a compute capability (CC): 8.0 for the A100, 8.9 for the L4 and RTX 4090, 9.0 for the H100 and H200, 10.0 for the B200 and GB200, 10.3 for the B300 and GB300, 12.0 for the RTX 5090 (NVIDIA, CUDA GPU compute capability) documented. compute_90 is a virtual architecture (PTX for CC 9.0's feature set), sm_90 a real architecture (SASS for CC 9.0 chips). CUDA 13.4's nvcc knows these real targets recorded here: . Nothing older than Turing (7.5) is left, and with no -arch nvcc builds for sm_75 ().
PyTorch 2.14 with CUDA 13.x ships SASS on x86_64 for ; on aarch64 (Grace, DGX Spark, Jetson Thor): . "Release/RC wheels ship SASS-only to keep libtorch_cuda.so size down"; nightlies add PTX for 12.0 (PyTorch v2.14.0, .ci/manywheel/build_env_setup.py) source code.
When a kernel is first used, the driver looks in the fat binary for a SASS image this GPU can run, then for a PTX image it can compile. Fig. 5 runs that search for the release wheel on seven GPUs derived from the documented rules below: SASS orange, PTX purple, a failed launch red.
sm_75, sm_80, sm_86, sm_90, sm_100 and sm_120, nothing a driver could compile.sm_80; the L4 (CC 8.9) has no sm_89, so takes sm_86, the highest equal-or-lower minor of its major.sm_90, CC 10.0 sm_100.sm_100 (same major, lower minor), with no compilation at load time: the answer to the prediction.cudaErrorNoKernelImageForDevice.compute_120.compute_120 PTX for CC 13.0: a slow first use of each kernel, then the driver's cache.cudaErrorNoKernelImageForDevice, "no kernel image is available for execution on the device".The tool on the right runs the same search for any binary (the objects compiled on this page, PyTorch 2.14's wheels, or your own mix), GPU and driver; the toggle removes the PTX, the usual difference between a binary that survives a new GPU and one that does not.
A model of NVIDIA's documented rules (beside Fig. 5), checked against a Python reference (src/code/compat.py) on all combinations: the logic agrees on 660 cases. The binaries' contents are real (cuobjdump on objects compiled here, and PyTorch's build table); nothing was loaded on a GPU.
Green: a SASS image runs. Blue: the driver JIT-compiles PTX (slow first use, then cached). Yellow: the launch fails. "A future CC 13.0 GPU" is hypothetical, any GPU of a new major version. Jetson Thor is aarch64, so it would in practice get the aarch64 wheel, which includes 11.0.
In -gencode arch=compute_XY,code=..., arch chooses the PTX to compile from and code lists what to embed (sm_XY SASS, compute_XY the PTX). -arch=sm_XY is shorthand: "nvcc --gpu-architecture=sm_100 is equivalent to nvcc --gpu-architecture=compute_100 --gpu-code=sm_100,compute_100" (nvcc manual). What cuobjdump -lelf -lptx finds in the softmax object for each choice compiled here:
a and fHopper added instructions NVIDIA does not promise to keep (wgmma, setmaxnreg), Blackwell more (tcgen05). They need an architecture-specific target with an a suffix, whose code "only runs on GPUs of that specific CC and no others". CUDA 12.9 added family-specific f targets for features "supported by devices of more than one minor compute capability": sm_100f code runs on CC 10.0, 10.3 and any later 10.x (NVIDIA technical blog, May 1 2025) documented. The parent's kernels compiled for fourteen targets compiled here (hover a cross for ptxas's message):
-arch=sm_90a on a wgmma kernel fails-arch=sm_90a also emits generic compute_90 PTX (section 2), so the generic pass reaches ptxas with Hopper-only instructions and fails compiled here. Two fixes, both compiled here: the specific target only (-gencode arch=compute_90a,code=sm_90a, no PTX), or guard the Hopper-only code with #if defined(__CUDA_ARCH_FEAT_SM90_ALL), the macro nvcc defines only in the a pass (section 2's dryrun). CUTLASS guards this way.
Kernels load lazily by default (CUDA_MODULE_LOADING=LAZY): loaded, and JIT-compiled if there is only PTX for this GPU, at first use. So the first training step is slow once per cache directory (~/.nv/ComputeCache on Linux), and in a container with a fresh home directory every time, unless CUDA_CACHE_PATH points at a persistent volume. CUDA_FORCE_PTX_JIT=1 ignores every cubin: the standard test that a binary would survive a future GPU.
| Variable | What it does |
|---|---|
CUDA_CACHE_PATH | Where JIT results are kept; default ~/.nv/ComputeCache on Linux. |
CUDA_CACHE_MAXSIZE | Cache size in bytes: default 1 GiB on desktops and servers (256 MiB embedded), maximum 4 GiB. |
CUDA_CACHE_DISABLE=1 | No on-disk cache: every run JIT-compiles again. |
CUDA_FORCE_PTX_JIT=1 | Ignore every cubin and JIT the PTX. |
CUDA_DISABLE_PTX_JIT=1 | Never JIT; use a compatible cubin or fail. |
CUDA_MODULE_LOADING | LAZY by default: load at first use, not at start-up. |
CUDA Programming Guide, environment variables, updated Sep 10 2026 documented.
Sometimes a kernel's shapes, data types or operation are known only at run time. NVRTC "accepts CUDA C++ source code in character string form and creates handles that can be used to obtain the GPU executable code", with no nvcc installed (NVRTC 13.4 documentation) documented. --gpu-architecture=sm_90a gives a cubin, compute_90a PTX for the driver to finish; either is loaded with cuModuleLoadData or cuLibraryLoadData and launched (needs a GPU; not run here). PyTorch's jiterator compiles elementwise expressions with it (jit_utils.cpp); CuPy's RawKernel uses it by default and caches under $HOME/.cupy/kernel_cache/ (CuPy RawKernel). Triton does not: it writes PTX itself and runs the ptxas it ships.
median of 7 compiles
no ptxas step; the driver would finish it
src/code/nvrtc_demo.cpp, a row-scaling kernel compiled from a string run here, CPU only. Tens of milliseconds per kernel is why runtime-compiling libraries cache, in memory and on disk.
The same kernel twice (right), with the row length as an argument and with -DNCOLS=4096 on the NVRTC command line compiled here, sm_90a:
-I<cuda>/include and even cuda_fp16.h is missing run here: A template kernel exists only once instantiated, and its symbol is a mangled name. nvcc compiling scale<float, 256> and scale<double, 128> gives these symbols, demangled by cu++filt compiled here:
With NVRTC you do not guess them: nvrtcAddNameExpression("axpy<float, 4>") before compiling and nvrtcGetLoweredName after gives the symbol. Here: .
asm("instruction %0, %1;" : "=r"(out) : "r"(in)); puts one PTX instruction into CUDA C++. The constraint letter gives the register type (h .u16, r .u32, l .u64, q .u128, f .f32, d .f64; n an immediate; "=" an output); asm volatile stops the compiler deleting or moving it, a "memory" clobber moving memory accesses across it (Inline PTX Assembly in CUDA) documented. It is for instructions C++ has no function for (wgmma and tcgen05, why the parent's Hopper and Blackwell kernels are mostly asm), registers C++ cannot name, and forcing one variant of an instruction; examples on the right compiled here, sm_90a:
%smid becomes SR_VIRTUALSMID; the PTX manual says it "may change during execution, e.g. due to rescheduling of threads following preemption" and is "intended mainly to enable profiling and diagnostic code": never use it for correctness. ld.global.cs (cache streaming) becomes LDG.E.EF, the instruction the __ldcs intrinsic gives on GPU memory hierarchy.
asm wrotey[i] = exp(x[i]) four ways compiled here, sm_90a (Fig. 7). The hardware has one fast exponential, MUFU.EX2 (2x on the special function unit).
expf(x): 8 arithmetic instructions. The accurate library function, 2 ulp (units in the last place): range reduction (FFMA.SAT, FFMA.RM, the magic constants), the exponent built separately (SHF), MUFU.EX2 for the fraction, a final multiply.__expf(x): 5. The intrinsic, error 2 + floor(|1.173 x|) ulp (CUDA Programming Guide, mathematical functions) documented: multiply by log2e, then MUFU.EX2. The FSETP and the two predicated FMULs halve and square around the EX2 for inputs below 2-126, keeping results out of the denormal range; the PTX says ex2.approx.f32 without .ftz.asm ex2.approx.ftz: 2. With .ftz (flush denormals to zero) only the multiply and MUFU.EX2 are left.expf(x) with -use_fast_math: 2. The flag rewrites every expf in the file to the fast form and adds .ftz: the inline PTX's two instructions, from unchanged source.FlashAttention-style kernels use the fast form and fold log2e into the softmax scale, so the multiply disappears too.
PTX has a published specification, so any compiler can target it and leave the rest to ptxas. Most do so through LLVM, whose NVPTX back end turns LLVM IR into PTX (LLVM, User Guide for NVPTX): clang compiles CUDA C++ with it (Compiling CUDA with clang), Rust's nvptx64-nvidia-cuda target uses it (rustc platform support), and so do Triton and XLA's native emitters. NVIDIA's cicc is LLVM-based too but closed. The first lines of the PTX tell them apart (right).
MLIR is LLVM's framework for compilers built from dialects, small intermediate languages each at its own level, lowered one into the next (mlir.llvm.org). The newer front ends are built on it, at different levels: StableHLO (JAX's input to XLA), Triton's TTIR and TTGIR, the CuTe DSL of CUTLASS 4 (Python with CuTe layouts, lowered through "the CUTLASS Python compiler stack and NVIDIA CUDA toolchain", CuTe DSL overview; it belongs to Libraries and tensor cores), and CUDA Tile IR, the newest road, shown end to end below.
NVIDIA calls Tile IR "a portable, low-level tile virtual machine and instruction set that models the GPU as a tile-based processor" (CUDA Tile IR documentation), "an MLIR-based intermediate representation" released with CUDA 13.1 (NVIDIA/cuda-tile) documented. It plays PTX's role for tiles, turned into SASS by tileiras. A cuTile Python vector add (pip package cuda-tile), exported to Tile IR bytecode and to cubins for four targets in the CUDA 13.4.2 image compiled here:
# cuTile: one block adds one tile of 1024 numbers; no thread index anywhere
@ct.kernel
def vector_add(a, b, out):
i = ct.bid(0)
x = ct.load(a, index=(i,), shape=(TILE,))
y = ct.load(b, index=(i,), shape=(TILE,))
ct.store(out, index=(i,), tile=x + y)
The same 703-byte file became four machine codes with no thread, warp or layout in the source: tileiras decided how many threads, how each walks the tile and how wide each load is, the promise Triton makes one level up. An incubator back end sends Triton through Tile IR (triton-lang/Triton-to-tile-IR; not in Triton 3.8.0). Running these cubins needs driver r580 or later (cuTile's README); not run here.
tileirdisasm)What each stage hands to the next; how to use torch.compile well (every graph-break kind, dynamic shapes, regional compilation, export) is on torch.compile from the user's side. Fig. 6 follows softmax(x * 0.125) @ w stage by stage run here, torch 2.14.1, CPU, each stage a plate with what it hands on after it; the second view puts a print mid-function.
attn_like's 21 bytecode instructions Dynamo records three tensor operations: mul, softmax, matmul.recompile_limit = 8 versions.extern_kernels.mm.triton_per_fused_add_mean_mul_pow_rsqrt_0, generated here without a device)..version 8.8) through LLVM's NVPTX back end and runs its own ptxas: the bottom of Fig. 4. Not run here: no GPU.mul, softmax).sum.CPython lets a library replace the function that evaluates every Python frame (PEP 523); TorchDynamo installs itself there and reads each function's bytecode symbolically: tensor operations are recorded into an FX graph, everything else (Python arithmetic on ints, loops over lists, attribute lookups) runs at trace time and its result is baked in (Ansel et al., PyTorch 2, ASPLOS 2024, section 3) documented. The graph recorded for the running example run here, torch 2.14.1, CPU:
Baking values in is safe only if the next call looks the same, so Dynamo writes guards, cheap checks run before cached code is reused: here lines, chiefly each input's dtype, device, requires_grad, sizes and strides, and global state (grad mode, autocast, default dtype, thread count). A failed guard means a recompilation; past torch._dynamo.config.recompile_limit = versions, the function runs eagerly.
Where Dynamo meets something it cannot record (a print, by default a .item(), an if on a tensor's value), it compiles the graph so far, lets CPython run that part and resumes tracing after it: a graph break. Nothing fuses across it, and every call pays Python in between; fullgraph=True turns a break into an error. Every kind of break and its fix (nine lines, twelve fixes) is section 3 of torch.compile from the user's side; the block below shows what Dynamo does to the bytecode.
# src/code/tc_programs.py, lines 11 to 14
def with_print(x):
y = torch.softmax(x * 0.125, dim=-1)
print("max prob", "(printed from Python)")
return y.sum(dim=-1)
with_print(x) and, through the PEP 523 hook, hands it to Dynamo instead of running it. Dynamo starts reading the original bytecode.x * 0.125 and torch.softmax are tensor operations: Dynamo records them instead of running them.print. Its log (right) says why, and suggests fixes.print in ordinary Python, then call a generated resume function holding the rest of the original code. Highlighted: the three calls.sum.print in Python between two compiled graphs, and nothing is fused across the break.with_print(x) goes to Dynamo.fullgraph=True nothing is split: the first thing Dynamo cannot trace raises. The exception is on the right run here.reorderable_logging_functions); replace data-dependent if on tensors with torch.where or torch.cond. With no break, one graph covers the whole function, and the compiler can fuse across what used to be the break. fullgraph=True is how you keep it that way: a new break becomes a test failure, not a silent slowdown.torch._dynamo.explain(fn)(*args) counts breaks without reading logs; on four small functions run here:
Under fullgraph=True the print and the data-dependent if are errors, but .item() is not: Dynamo captures the scalar as a symbolic value instead (torch 2.14.1: allow_scalar_outputs=one_graph or config.capture_scalar_outputs, torch/_dynamo/output_graph.py) run here.
A failed size guard recompiles with the changed dimension as a symbol (automatic dynamic shapes), so later sizes reuse it; where recompiles come from in training, measured, is section 4 of torch.compile from the user's side.
AOTAutograd runs autograd on fake tensors (shapes and dtypes, no data) to record one joint forward-and-backward graph, then "uses a min-cut algorithm to split this joint graph into separate forward and backward graphs in a way that optimizes for memory usage" (Ansel et al., section 3.9): save or recompute, decided before Inductor fuses anything. On the RMSNorm of section 1 run here:
Inductor then lowers each graph to its loop-level IR (a "define-by-run" IR whose loop bodies are Python functions; paper section 4.3), fuses (section 1), and writes one kernel per fused group plus a Python wrapper that allocates buffers and launches them: "TorchInductor generates both Triton and C++ as output code" (paper section 4).
CUDA graphs record a sequence of kernel launches once and replay it with one call, removing per-launch CPU overhead; they need static shapes and addresses and keep a private memory pool. They belong to Streams, CUDA graphs and multi-GPU, whose section 4 covers mode="reduce-overhead" (CUDAGraph Trees) and Inductor's graph partitions, on by default in PyTorch 2.14.1. Autotuning times candidate kernels on the real GPU; neither could run here.
The RMSNorm forward and backward compiled in a fresh process, three times with an empty cache directory and three times warm run here, CPU, 2 threads:
A cold compile is mostly Python (Dynamo, AOTAutograd, Inductor) plus the C++ or Triton compiler: 3 to 4 seconds for the first call here, about a millisecond afterwards. A warm start finds the result in Inductor's on-disk caches (TORCHINDUCTOR_CACHE_DIR; the FX graph cache is on by default) and Triton's. On a real model a cold compile is minutes, hence torch.compiler.save_cache_artifacts() and load_cache_artifacts() (torch 2.14.1): build the caches once, ship them to every node. These CPU numbers say nothing about GPU speed-ups; the PyTorch 2 paper reports 2.27x for inference and 1.41x for training (geometric mean over 180+ models, A100) published.
TORCH_LOGS takes a comma-separated list (graph_code, guards, graph_breaks, recompiles, dynamic, bytecode, aot_graphs, fusion, output_code; a + prefix such as TORCH_LOGS=+dynamo adds debug detail); for a whole run, TORCH_TRACE=<dir> plus tlparse makes an HTML report per compiled frame. The Inside torch.compile tab holds every log used here.
-gencode arch=compute_90,code=sm_90 (SASS only) on a B200, or a SASS-only release wheel on a GPU of a newer major version. Check with cuobjdump -lelf -lptx on the binary or library (section 5 lists what each flag embeds); fix by adding the GPU's target or a PTX image (code=[sm_90,compute_90]). The driver stepper of section 5 reproduces the rule.cudaErrorUnsupportedPtxVersion: the binary carries only PTX for this GPU and that PTX is newer than the driver's JIT compiler (section 3 shows the same failure offline: ptxas 12.9 refusing .version 9.4). Update the driver, or ship SASS for the GPUs you run on so that no JIT is needed.~/.nv/ComputeCache each time. Point CUDA_CACHE_PATH at a persistent volume, or build SASS for the GPU. For torch.compile the same applies one level up: keep TORCHINDUCTOR_CACHE_DIR and Triton's cache, or ship them with torch.compiler.save_cache_artifacts().sm_90a cubin runs only on CC 9.0, so on a B200 the driver JIT-compiles the generic compute_90 PTX that -arch=sm_90a also embedded, which by construction contains no wgmma (section 5). The kernel works with the slower generic path. Build sm_100a or sm_100f for Blackwell.-use_fast_math as a speed switchexpf, division and square root in the file and flushes denormals to zero (section 6). Use the intrinsic (__expf) or inline ex2.approx exactly where the accuracy loss is acceptable, and test against a reference..item() or an if on a tensor inside a compiled modeltorch._dynamo.explain or TORCH_LOGS=graph_breaks; keep them out with fullgraph=True.TORCH_LOGS=recompiles names the failing guard. Pass changing scalars as tensors, mark dimensions dynamic (torch._dynamo.mark_dynamic), or pad to a few bucket sizes. Past recompile_limit recompilations, Dynamo stops compiling that function and runs it eagerly.The raw material of sections 1 and 8: six small programs compiled by torch 2.14.1 on the CPU in this page's Docker image, with what each stage of torch.compile wrote about them (TORCH_LOGS output, prefixes removed and long lines cut). Pick a program, then a stage; stages a program did not produce are greyed out. Scripts: src/code/tc_programs.py and run_tc.sh; the full logs are in src/out/tc/.
The tabs of this page, the knowledge base pages around it, and the best outside resources, each with an approximate time. Links checked on 2026-10-05; XLA and TVM links on 2026-10-23.
Six programs, every stage's log: bytecode, FX graphs, guards, breaks, recompiles, AOTAutograd graphs, generated C++ and Triton, compile cost. 15 min
The root: the map of the topic and every lever with its owner; its section 8 defines PTX, SASS and the fat binary in one paragraph; its Compiler explorer tab puts source, PTX and SASS side by side for eleven CUDA and three Triton kernels on four GPUs, with the occupancy each implies.
Triton's own compiler from the inside: every stage and pass (TTIR, TTGIR layouts, LLVM, PTX), autotuning, Gluon; the source of this page's stand-in method for Inductor's GPU code.
Its Memory instructions tab: every load and store modifier in SASS (cache hints, vector widths, async copies), compiled.
Kernels and launches from zero, error handling, and the same kernels from Numba, CuPy and torch.utils.cpp_extension.
Reductions, softmax, the matmul ladder, fusion and FlashAttention, with what nvcc made of each.
cuBLAS, CUTLASS, CuTe and the CuTe DSL; mma, wgmma, TMA and tcgen05 as instructions.
Nsight Compute's stall reasons (the scoreboards of section 4, measured), honest timing of compiled code.
CUDA graphs, which mode="reduce-overhead" turns on, and launch overhead.
What happens below the loaded module: the driver, its ioctls, one CUDA call through the stack. OS child
The hardware the scoreboards and register files of section 3 describe, per generation.
Compilers, object files and linking on the CPU side. 17 min, plus 9
Building llama.cpp: its CMake options, GGML_CUDA among them. 33 min, plus 36
Floating point, ulps and denormals behind section 6's four ways to write ex. math child
Owns torch.compile in depth: every graph-break kind and its fix, guards, dynamic shapes, the partitioner, compiled autograd, regional compilation, caches, export. pytorch-ecosystem child
Owns XLA in depth: lowering to StableHLO, the pass pipeline, fusion decisions and refusal reasons, buffer assignment, recompiles. jax-and-tpu child
PyTorch from the user's side. 30 min
Where compiled models, CUDA graphs and kernel caches meet start-up time. 34 min, plus 3
The compilation phases, -arch/-code/-gencode, virtual and real architectures, the feature lists. Read chapters 2 to 5. 1 h
Chapters 1 to 5 (the machine model, syntax, state spaces) once; the instruction chapters as a reference. 2 h for the first part
cuobjdump, nvdisasm (including -plr and -json) and the SASS opcode tables per generation. 40 min
Chapter 2: the instruction encoding and control bits decoded on this page. 45 min
The API, name expressions, LTO-IR with nvJitLink. 30 min
Constraints, volatile and clobbers, with examples. 20 min
Driver versions, minor version and forward compatibility. 30 min
Dynamo, guards, continuation functions, AOTAutograd and Inductor, by their authors. Sections 3 to 6. 1 h 30 min
The programming model, troubleshooting graph breaks and recompilations, dynamic shapes, caching. 1 h
The newest road to SASS; samples and the MLIR dialect. 45 min
XLA:GPU from HLO to kernels: fusion, native and Triton emitters, library calls, runtime. 25 min
Relax, TensorIR and the composable pass pipeline. 15 min
How open compilers (clang, Triton, Rust) write PTX. 30 min