Unit 8 of 10 · about 5 hours · explain, measure
From CUDA source to PTX, cubin and SASS
The compiler can remove, fuse, predicate or scalarize the code you intended to measure. Binary inspection makes the experiment about the instructions that actually execute.
You'll be able to
- Explain host compilation, PTX generation, offline assembly and driver JIT without calling PTX the final machine code.
- Build and inspect explicit virtual and real architecture targets, recording toolchain and resource use.
- Connect a source-level hypothesis to retained SASS instructions and a correctness-checked timing comparison.
Covers
Read
In this order, only the parts listed
0 of 3 done
- CUDA Programming Guide 13.4.2: compiler trajectory and targetsCUDA Programming Guide
Sections 2.7.2, 2.7.3.1, 2.7.4.2 and 2.7.4.3
- CUDA Binary Utilities 13.4: resource reports and disassemblyCUDA Binary Utilities 13.4
Sections 1.1 to 1.2, 2.1.1 to 2.1.3, 3.1.1 and 3.1.4
Use command examples and line correlation only; skip control-flow graph tooling and instruction tables for architectures other than your target.
- PTX ISA 9.4: goals, state spaces and module directivesParallel Thread Execution ISA
Sections 1.2 (Goals of PTX), 5.1 to 5.1.7 (state spaces, including
.reg,.param,.global,.localand.shared) and 11.1.1 to 11.1.3 (.version,.targetand.address_size)Read these sections against your own
map.ptx. In the compute capability 8.6 example with CUDA 13.4,-arch=compute_86 -ptxemits.version 9.4and.target sm_86, kernel arguments in.paramand virtual.regregisters; your own target is the onenvidia-smi --query-gpu=compute_cap --format=csvreports. Skip the instruction reference beyond the loads, stores and FMA your kernel uses.
Focus on
- A virtual
compute_86target defines the PTX feature set; realsm_86code is assembled machine code. A fat binary can carry several cubins and PTX for eligible JIT fallback. - Save compiler version, flags, PTX, cubin resource reports and SASS together.
-lineinfoaids correlation without the optimization changes caused by device debugging with-G. - PTX registers are virtual and do not equal allocated hardware registers. Use
ptxasreports, kernel attributes and final binary resource information. - Annotate global loads/stores, bounds handling, FMA instructions and any local loads/stores in the final code. A source expression is not a guaranteed instruction sequence.
Common mistakes · 3
- Counting PTX instructions as hardware issue cost. Assembly and JIT can transform them.
- Benchmarking a
-Gbuild and generalizing its register use or time to the optimized build. - Inspecting a different architecture image or stale executable from the one measured. Keep artifact identities and commands in the evidence manifest.
Try it yourself
Closed-book, before checking anything
nvcc -O3 -lineinfo -arch=native -Xptxas=-v map.cu -o map, nvcc -O3 -arch=native -ptx map.cu -o map.ptx, and nvcc -O3 -lineinfo -arch=native -cubin map.cu -o map.cubin. Inspect with cuobjdump --dump-sass --dump-resource-usage map and nvdisasm --print-line-info map.cubin. These build for your own GPU; the sm_86 and compute_86 targets elsewhere in this unit are the example for compute capability 8.6. Locate the retained index calculation, tail handling and stores, then validate and event-time the executable. Report actual registers and spills without assuming a fixed allocation or speedup.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Does shipping only an
sm_86cubin guarantee execution on every later GPU?AnswerNo. Cubin compatibility is constrained; a different major architecture generally needs its own compatible image or eligible PTX fallback.
2.Why might source multiplication plus addition appear as one instruction?Answer
The compiler can contract it to an FMA, subject to compilation rules. Inspect SASS and account for the changed rounding when comparing references.
3.Can a kernel with many PTX register names use few physical registers?Answer
Yes. Virtual-register lifetimes can share physical registers after optimization and allocation. The final resource report is the relevant count.
You're done when
Your evidence bundle ties the validated executable to its targets, resource report and annotated final instructions, and distinguishes offline cubin execution from possible PTX JIT.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 8 more in the section
- CUDA Programming GuideNVIDIA · required
Read the Basics and Programming Model chapters plus the sections on memory, synchronization, hardware implementation and compute capabilities used by your kernels. Record the toolkit documentation version alongside every claim.
- Parallel Thread Execution ISANVIDIA · reference
Read the PTX purpose, machine model, state spaces, memory consistency and target directives. Compile two tiny kernels, map source to PTX and SASS, and explain what PTX does and does not guarantee across devices.
- CUDA Binary Utilities 13.4NVIDIA · reference
Sections 1.1 to 1.2, 2.1.1 to 2.1.3, 3.1.1 and 3.1.4 for cubin extraction, resource reports and line-correlated SASS. The existing compiler and PTX references lack a worked binary-tool workflow.
Also in this section
- Programming Massively Parallel Processors, 4th edition - Chapters 2 to 6Wen-mei Hwu, David Kirk and Izzat El Hajj · primary
Read Chapters 2 to 6: data-parallel kernels, multidimensional grids, compute architecture and scheduling, memory architecture and data locality, and performance considerations. Work the chapter exercises on warps, occupancy, memory and coalescing, and predict three altered launch or address patterns before running them.
- MIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 2 to 5 and Labs 2 and 3MIT · required
Use Lecture 2 (Throughput Processors), Lectures 3 and 4 (Memory, Parts 1 and 2) and Lecture 5 with its continuation (scratchpads, bank conflicts, register shuffles, overlap) for why the hardware looks as it does. Do Lab 2 (Massively-Parallel Mandelbrot, with its FMA-latency and warp-scheduler probes) and Lab 3 (Wave Simulation, with its coalesced-load and memory-latency probes) from the public lab repositories, built with nvcc for your own GPU instead of the course service. The labs were written for an RTX 4000 Ada, so recompute any SM count or bandwidth the questions assume.
- CUDA C++ Best Practices GuideNVIDIA · required
Study Assess, Parallelize, Optimize, Deploy; Getting the Right Answer; memory optimization; execution configuration; instruction optimization; and deployment compatibility. Convert recommendations into hypotheses, not universal rules.
- GPU MODE Foundations LecturesGPU MODE · support
Use Lectures 2, 3, 4, 5, 8, 37 and 41 for PMPP review, CUDA setup, architecture, optimization checklists, SASS and documentation reading. Reproduce only the examples that test a prediction from this stage.
- TensorTonic Language Modeling from Scratch - GPU analysis problemsTensorTonic · support
Solve GPU Occupancy Calculator, Shared-Memory Bank Conflict Analyzer and Global-Memory Coalescing Counter after the matching units, and check each answer against your own derivation.
- AI Performance Engineering - GPU FundamentalsWafer · reference
A curated index. Use Section 1 only to find a CUDA, PTX or architecture source the other entries lack.
- NVIDIA CUDA Pro Tips: grid-stride loops and vectorized memory accessNVIDIA · required
Read the grid-stride SAXPY loop and its scalability and debugging discussion (April 22, 2013), plus the scalar-copy SASS and vector-type alignment discussion in Increase Performance with Vectorized Memory Access (August 4, 2025). Skip the latter article's full vector-copy kernels: their tail-thread condition can omit remainders. These fill the pool's grid-stride and vector-width coverage gaps.
- PyTorch custom C++/CUDA operators and CUDA semanticsPyTorch · required
Custom C++ and CUDA Operators: build system, backend registration, Testing an operator and mutable schema; CUDA semantics 2.14: CUDA streams. These fill the native tensor-boundary gap in the CUDA-only pool. Stop before fake-kernel and autograd implementation; harden the tutorial's CUDA example for empty inputs, same-device checks, device guards, indexing width and launch errors.