The compiler stack: PTX, SASS, NVRTC, torch.compile and Inductor

From a framework graph or a hand-written kernel to the machine code an NVIDIA GPU runs: what torch.compile, XLA, TVM, Triton and nvcc each decide, PTX and SASS read on real code, which binary runs on which GPU, NVRTC and inline PTX. Compiled and run here with CUDA 13.4.2 and torch 2.14.1 on a laptop with no NVIDIA GPU. A child of Topic: cuda-and-gpu-programming. Data as of October 2026. Reading: 37 min, plus 22 in closed details.

The idea in one screen

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.

What is real here
Every listing, error message, file size and log comes from the real tools: CUDA 13.4.2 (nvcc, ptxas, cuobjdump, nvdisasm, NVRTC, tileiras) and torch 2.14.1 with Triton 3.8.0, in the Docker image 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.

SASS: the machine code one GPU generation executes.
PTX: a virtual, documented assembly language for an idealised GPU.
ptxas: the assembler, really an optimising compiler, from PTX to SASS.
cubin: an ELF file holding SASS; a fat binary holds several cubins and PTX images.
compute capability (CC): a GPU's instruction-set version, 9.0 for the H100.
fusion: putting several operations in one kernel, so intermediates never go to memory.
FX graph, guard, graph break: torch.compile's capture, its reuse check, where capture stopped (section 8).
Why an ML engineer needs this
  • "no kernel image is available for execution on the device", a slow first step on a new GPU, a wheel that will not load on a B300: which images a binary carries (section 5).
  • Is my kernel using tensor cores, vector loads, no spills? Only the SASS answers; ptxas rewrites a lot (sections 3 and 4).
  • Why did torch.compile or XLA make one kernel here and two there? Fusion, and where capture stopped (sections 1 and 8).
Fig. 1 · Six front ends, one assembler: click a box for what it produces and how to see it

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.

1. What each compiler decides on the way down

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.

RoadCapturesWho decides fusionCodegen writesTo SASS via
nvccone CUDA C++ kernelyou, by handNVVM IR, then PTX (cicc)ptxas
torch.compile (Inductor)an FX graph traced from Python bytecodeInductor'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 functionfusion 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
TVMa 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
Tritonone block-level kernelyou, by hand (what goes in one @triton.jit)TTIR, TTGIR (layouts, pipelining), LLVM IRLLVM NVPTX, then Triton's own ptxas
cuTileone tile-level kernelyou, by handCUDA 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.

Fig. 2 · Seven scheduler nodes become one kernel plus a library call

Fusion, watched on the running example

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?

  1. Seven scheduler nodes. Dynamo's three operations (multiply, softmax, matmul), decomposed and rewritten: four row reductions (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.
  2. Round 1: seven nodes into four. The three reductions over the same rows merge; exp merges with the sum that consumes it. op3 with op5 is refused: "cannot fuse op3 with op5: intermediate nodes between node1 & node2" (the sum must finish before any divide).
  3. Round 2: four nodes into two. With the sum inside, everything that loops over rows becomes one outer loop over the 64 rows (OuterLoopFusedSchedulerNode). The matmul stays outside, an extern kernel.
  4. Round 3 finds nothing: code generation. One C++ kernel for the six nodes, 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 fusion log, the wrapper and the whole generated C++ kernel

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.


Codegen: what the generated kernel decides

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.

The generated Triton kernel

2. nvcc is a driver, not a compiler

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.

Predict first: you compile with 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.

  1. The host side, split from the device side (commands 1 and 2). gcc -E preprocesses the host side (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).
  2. The generic pass: compute_90 to PTX (commands 3 and 4). The device side, preprocessed with __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.
  3. ptxas only checks the generic PTX (command 5). ptxas -arch=compute_90 writes nothing, so a Hopper-only instruction fails here (section 5's trap).
  4. The specific pass: compute_90a to PTX (commands 6 and 7). A third time, also defining __CUDA_ARCH_FEAT_SM90_ALL and __CUDA_ARCH_SPECIFIC__=900: PTX that may use wgmma and setmaxnreg, compute_90a.ptx, 6.1 KB.
  5. ptxas: PTX to SASS for sm_90a (command 8). Register allocation, scheduling, encoding: the H100's machine code in a cubin, 7.8 KB.
  6. fatbinary packs three images (commands 9 and 10). PTX 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.
  7. gcc compiles the host side (command 11), stub and fat binary inside: softmax.o, 17.8 KB, the object your linker sees. With -rdc=true (device functions called across files) nvlink would join cubins first.

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.

3. PTX: an assembly language for a GPU that does not exist

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:

  • Every instruction names its type (add.f32, mul.wide.s32); there is no implicit conversion, cvt does it.
  • Every memory access names its state space: .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.
  • Registers are virtual and almost single-assignment. This kernel declares of them; the H100 code uses 18 real ones (cuobjdump -res-usage: ). ptxas decides which values share a register.
  • Control flow is predicates plus branches: setp.ge.s32 %p1, ... writes a 1-bit predicate, @%p1 bra $L__BB0_2 branches on it; any instruction can be predicated.
  • Special registers: %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.
The whole PTX of the row softmax: pick a feature to light the lines that carry it

PTX is tied to the toolkit that wrote it

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."

PTX is not what runs: what each compiler decides on the way down

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).

  1. The source: one kernel, 32 lines. Three passes over a row (maximum, sum of exponentials, normalise), each reduction a warp shuffle plus a shared-memory step. Fusion was decided here, by hand.
  2. cicc writes PTX: 245 lines, 230 virtual registers. 31 predicates (%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.
  3. ptxas -O0: 792 instruction slots, 31 registers. At -O0 ptxas assembles the PTX nearly as written.
  4. ptxas -O1 to -O3: 232 slots, 18 registers. From -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).
  5. Four generations, four machine codes. The same source compiled for 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.

4. SASS: reading the machine code

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.

Anatomy of one line

Pick a real instruction (right; softmax, sm_90a compiled here) and click any part of it.

You seeIt means
R0 to R254, RZPer-thread 32-bit registers; RZ reads zero. R6.64 is the pair R6, R7 holding a 64-bit address.
UR4, ULDC, S2URUniform 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, @!P1Predicate 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.XSpecial registers, read with S2R or S2UR.
.reuseKeep this source operand in the operand reuse cache for the next instruction (one of the control bits below).
One SASS line of the softmax, taken apart
The opcodes that matter, by family (counts across four kernels)

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.

The bits nobody prints: stall counts and scoreboards

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).

  • Stall count (0 to 15): cycles before this warp's next instruction may issue; fixed-latency arithmetic is spaced by these alone.
  • Write barrier: a variable-latency instruction (a global or shared load, a shuffle, 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.

Checked here, on real code
If the decoding is right, every register written by an instruction that sets a scoreboard is waited for before anything reads it. 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.

The 21 control bits, and a scoreboard replay of four real kernels

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.

Every instruction of the selected kernel (click a row to jump there)

Offset, guard, instruction, stall (S), yield (Y), write scoreboard (W), read scoreboard (R), wait mask, reuse flags, live registers after the instruction (nvdisasm -plr).

Registers: allocated against live

Counted from nvdisasm -plr, which marks for every instruction the registers still holding a value needed later; softmax, sm_90a compiled here.

Live registers never reach the 18 ptxas allocates

5. Which binary runs on which GPU

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 ().

What your PyTorch wheel carries, and which image each GPU runs

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.

Predict: the PyTorch 2.14 release wheel (CUDA 13, x86_64) on a B300, compute capability 10.3. There is no sm_103 image in it. What happens?

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.

  1. Six SASS images, no PTX. Machine code for sm_75, sm_80, sm_86, sm_90, sm_100 and sm_120, nothing a driver could compile.
  2. A100 and L4: the same major version. The A100 (CC 8.0) takes sm_80; the L4 (CC 8.9) has no sm_89, so takes sm_86, the highest equal-or-lower minor of its major.
  3. H100 and B200: an exact match each. CC 9.0 takes sm_90, CC 10.0 sm_100.
  4. B300: no sm_103, still runs. CC 10.3 runs sm_100 (same major, lower minor), with no compilation at load time: the answer to the prediction.
  5. RTX 5090: sm_120. CC 12.0, an exact match.
  6. A future GPU of a new major version fails. A hypothetical CC 13.0 GPU finds no SASS of major 13 and no PTX: cudaErrorNoKernelImageForDevice.

The rules the driver follows

  • SASS runs within one major version on equal or newer minors: "a cubin compiled for compute capability 8.6 (sm_86) runs on GPUs with CC 8.6 or 8.9, but not on CC 8.0", and GPUs "are not binary compatible between major compute capability versions" (CUDA Programming Guide 1.3).
  • PTX "can be JIT compiled at application runtime for any compute capability equal or higher to the compute capability of the PTX code" (same page), when no compatible SASS exists; the driver "automatically caches a copy of the generated binary code".
  • The driver must know the PTX's version (section 3). CUDA 13.x needs driver 580 or newer; a 13.0 driver runs SASS built by CUDA 13.4 (minor version compatibility) but cannot JIT its PTX (CUDA compatibility guide).
  • Nothing fits: cudaErrorNoKernelImageForDevice, "no kernel image is available for execution on the device".

The driver's search, for any binary, GPU and driver

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.

The same binary on every GPU (click a row to step through it above)

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.

What each flag puts in the binary

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:

Three kinds of target: plain, a and f

Hopper 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):

A trap: -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.

ptxas's error

The JIT cache, and when loading happens

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.

Every JIT-cache variable
VariableWhat it does
CUDA_CACHE_PATHWhere JIT results are kept; default ~/.nv/ComputeCache on Linux.
CUDA_CACHE_MAXSIZECache size in bytes: default 1 GiB on desktops and servers (256 MiB embedded), maximum 4 GiB.
CUDA_CACHE_DISABLE=1No on-disk cache: every run JIT-compiles again.
CUDA_FORCE_PTX_JIT=1Ignore every cubin and JIT the PTX.
CUDA_DISABLE_PTX_JIT=1Never JIT; use a compatible cubin or fail.
CUDA_MODULE_LOADINGLAZY by default: load at first use, not at start-up.

CUDA Programming Guide, environment variables, updated Sep 10 2026 documented.

6. NVRTC and inline PTX: compiling at run time, naming one instruction

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.

string to cubin (sm_90a)

median of 7 compiles

string to PTX (compute_90a)

no ptxas step; the driver would finish it

setting
NVRTC , 2 CPU cores

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.

Compiling late: constants the compiler can see

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:

The mistake everyone makes once
NVRTC searches no CUDA include directory by itself (only the current directory for quoted includes). Forget -I<cuda>/include and even cuda_fp16.h is missing run here:
The same kernel, compiled by NVRTC twice (sm_90a SASS)
Templates and their names

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: .

Inline PTX

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.

The PTX your asm wrote
What ptxas made of it
Fig. 7 · ex four ways: the arithmetic between the load and the store
PTX (arithmetic only)
SASS (arithmetic only)

Before and after: four ways to write ex

y[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).

  1. 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.
  2. __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.
  3. Inline asm ex2.approx.ftz: 2. With .ftz (flush denormals to zero) only the multiply and MUFU.EX2 are left.
  4. 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.

7. LLVM and MLIR: how the other front ends reach PTX

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).

cicc (nvcc), CUDA 13.4
Triton 3.8.0 (LLVM NVPTX)

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.

CUDA Tile IR, compiled here without a GPU

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.

One 703-byte Tile IR file, four machine codes
The Tile IR it became (-byte bytecode, printed by tileirdisasm)

8. torch.compile as one road: what reaches Inductor, and what it costs

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.

  1. Dynamo: the frame becomes an FX graph. From attn_like's 21 bytecode instructions Dynamo records three tensor operations: mul, softmax, matmul.
  2. Guards: when the graph may be reused. 18 guard lines are checked on every call; a failure recompiles, up to recompile_limit = 8 versions.
  3. AOTAutograd: forward, and backward when needed. Traced together on fake tensors, split by a min-cut; this call needs no gradients, so only a forward graph goes on.
  4. Inductor: seven scheduler nodes, one kernel. Fusion (Fig. 2) leaves one kernel plus the library matmul, extern_kernels.mm.
  5. Codegen: C++ here, Triton on a GPU. One C++ kernel of 115 lines on the CPU (run here); on a GPU, Triton (for the RMSNorm, triton_per_fused_add_mean_mul_pow_rsqrt_0, generated here without a device).
  6. PTX and ptxas. Triton writes PTX (.version 8.8) through LLVM's NVPTX back end and runs its own ptxas: the bottom of Fig. 4. Not run here: no GPU.

Dynamo: a graph and the guards that keep it valid

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.

The guards, as Dynamo wrote them

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.

One graph break, step by step, against fullgraph=True (real bytecode and graphs)
# 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)
  1. The call reaches Dynamo. CPython creates the frame for with_print(x) and, through the PEP 523 hook, hands it to Dynamo instead of running it. Dynamo starts reading the original bytecode.
  2. Line 12 is traced into a graph. x * 0.125 and torch.softmax are tensor operations: Dynamo records them instead of running them.
  3. Line 13: print cannot be traced. Dynamo has no graph operation for print. Its log (right) says why, and suggests fixes.
  4. Graph 1 is compiled; the bytecode is rewritten. Dynamo compiles what it has, then writes new bytecode for the frame: call the compiled graph, call print in ordinary Python, then call a generated resume function holding the rest of the original code. Highlighted: the three calls.
  5. The resume function is traced too. It is a normal Python function, so when the rewritten code calls it, the PEP 523 hook fires again and Dynamo traces it: graph 2 holds the sum.
  6. The next call: guards, then cached code. Called again with the same shape, both frames pass their guards and run their cached code. Every call still runs print in Python between two compiled graphs, and nothing is fused across the break.

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: the backward graph, and what to save

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:

The forward and backward graphs (TORCH_LOGS=aot_graphs)
Forward graph
Backward graph

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).

Modes, and the Inductor options each turns on

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.

What compiling costs, and the caches that hide it

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.

Seeing every stage yourself: TORCH_LOGS, TORCH_TRACE, the Inside torch.compile tab

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.

Depth: mistakes

Mistakes, with the evidence for each (eight)
"no kernel image is available for execution on the device"
The binary has no SASS this GPU can run and no PTX the driver could compile: for example -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.
"the provided PTX was compiled with an unsupported toolchain"
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.
The first step is slow on every run, in containers only
The binary has only PTX for this GPU, so the driver JIT-compiles every kernel at first use, and the container starts with an empty ~/.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().
An H100-tuned binary on a B200 runs, but slowly
An 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 switch
It changes every expf, 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.
A print, a .item() or an if on a tensor inside a compiled model
Each is a graph break: two smaller graphs, no fusion across them, Python in between on every call (section 8). Find them with torch._dynamo.explain or TORCH_LOGS=graph_breaks; keep them out with fullgraph=True.
Training slows down at the end of every epoch, or every few steps
Recompilation: the last batch is shorter, sequence lengths vary, or a Python number (learning rate, step) is passed as an argument and guarded by value (section 8). 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.
Timing torch.compile with the compile inside the measurement
The first call compiled for 3 to 4 seconds here, against about a millisecond afterwards (section 8). Warm up first, with every shape you will time; the profiling page covers honest timing.