Unit 10 of 10 · about 3 hours · implement
Compute capability, feature detection and fallback paths
Compilation for a new target does not make a feature available on an older device. A portable library needs an observable decision and a baseline whose correctness does not depend on the optimization.
You'll be able to
- Query device and kernel limits and distinguish feature support from launch legality and binary compatibility.
- Implement a deterministic dispatch decision with a validated baseline fallback and an explicit unsupported reason.
- Exercise both dispatch branches without claiming that an unavailable hardware feature was executed.
Covers
Read
In this order, only the parts listed
0 of 4 done
- CUDA C++ Best Practices Guide 13.4: availability, errors and compatible buildsCUDA C++ Best Practices Guide
Sections 17.1 to 17.3
- CUDA Programming Guide 13.4.2: queried resource limitsCUDA Programming Guide
Section 2.3.7, device properties, kernel attributes and occupancy APIs
- CUDA Programming Guide 13.4.2: an architecture-gated featureCUDA Programming Guide
Section 1.2.2.1.1, Thread Block Clusters
Explain eligibility only. Do not implement a cluster kernel in this unit.
Focus on
- Check device availability and every query's return status before reading fields. Record compute capability, SM count, thread limits, shared-memory limits and compiled-kernel attributes.
- A capability predicate, per-launch resource check and compatible code image are separate requirements. Device names and toolkit versions are not substitutes for those checks.
- Build dispatch as a pure decision over queried facts and boundary facts, then launch only the selected legal path. Include an override that forces the baseline for differential testing.
- Do not treat all CUDA errors as permission to retry another kernel. Invalid input or a failed execution can require reporting the error rather than continuing in a damaged context.
Common mistakes · 3
- Hard-coding a product-name whitelist. Similar names can have different limits and future devices are unknown to the list.
- Forcing a synthetic supported capability into a real launch. Mocking tests the decision function, not hardware execution.
- Equating PTX forward compatibility with unrestricted driver compatibility. The installed driver must understand the shipped PTX version and support the device.
Try it yourself
Closed-book, before checking anything
cudaGetDeviceProperties, cudaFuncGetAttributes and the occupancy API for the baseline. Record clusterLaunch from the device properties as a feature-eligibility observation, not a cluster execution test. Implement a vector-copy selector requiring 16-byte-aligned pointers, compatible element type, a correctly handled tail and legal launch resources; otherwise choose the scalar grid-stride copy. Unit-test synthetic dispatch facts on the CPU, but launch only paths actually supported by the current device. Compare automatic dispatch and forced baseline on lengths 0, 1, 31, 32, 33 and 1025 and on offset views. Log the selected path and failed precondition. An unavailable device produces an explicit unsupported result, not a fabricated successful GPU run.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Does a legal thread count prove a kernel launch is legal?Answer
No. Registers, static plus dynamic shared memory, kernel-specific limits and other launch requirements also matter.
2.How do you test an unavailable optimized branch honestly?Answer
Test its decision logic with synthetic facts and report execution as untested on this device. Run the baseline and any genuinely supported optimized paths against the reference.
3.Does a feature-support query prove that the optimized path is faster?Answer
No. It proves eligibility for that feature, not performance. Choose a default only after representative correctness-checked measurements.
You're done when
Your dispatch report explains every tested selection, both supported copy paths match the reference, and unavailable hardware paths are clearly separated from mocked decision tests.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 9 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.
- 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.
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.
- 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.
- 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.
- 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.
- 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.