Unit 5 of 10 · about 3 hours · derive
Shared-memory banks, conflicts, padding and the constant cache
On-chip storage does not make every access pattern efficient. Bank mapping and the number of distinct constant addresses within a warp matter as much as placement.
You'll be able to
- Predict shared-memory bank IDs and conflict degree for scalar word accesses, including broadcasts.
- Derive when padding a row stride removes column-access conflicts.
- Choose between shared memory, constant memory and read-only global loads for a stated access pattern.
Covers
Read
In this order, only the parts listed
0 of 4 done
- PMPP, 4th edition: memory typesProgramming Massively Parallel Processors, 4th edition - Chapters 2 to 6
Section 5.2
- CUDA Programming Guide 13.4.2: banks, broadcast and paddingCUDA Programming Guide
Section 2.3.4.2 before the transpose example; Section 2.3.4.2.2, Shared Memory Bank Conflicts, Figures 17 and 18
Skip the full transpose implementation in 2.3.4.2.1 here. Derive the bank map before implementing a transpose in the primitives section.
- CUDA C++ Best Practices Guide 13.4: constant-cache accessCUDA C++ Best Practices Guide
Section 10.2.6
- CUDA Programming Guide 13.4.2: read-only global loadsCUDA Programming Guide
Section 5.4.8.3, the
__ldgdescriptionRead only the read-only-load contract, not the list of cache-control intrinsics.
Focus on
- For aligned scalar 32-bit accesses on the 32-bank model, the bank is , with byte address . Count distinct words per bank, not just requesting lanes.
- Same-word reads can broadcast. Different words in the same bank conflict; same-address competing writes are not a safe broadcast-based algorithm.
- A row-major tile with 32 columns gives column accesses a 32-word stride. Padding to 33 columns changes the bank stride to one modulo 32.
- Constant memory favors few distinct addresses per warp. A read-only global pointer is not a
__constant__allocation, and a read-only cache is not coherent with writes to that data during the kernel.
Common mistakes · 3
- Applying the scalar bank-conflict rule across separate hardware transactions of a wide instruction. Analyze the actual instruction's transaction groups.
- Adding padding without recalculating addresses and shared-memory capacity. A changed stride can fix one access and alter another.
- Choosing constant memory just because the data never changes. Many distinct addresses in one warp serialize constant-cache requests.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why does word stride 3 avoid conflicts in this 32-bank scalar model?Answer
Three is coprime to 32, so multiplication by three modulo 32 visits every bank once across the 32 lanes.
2.Four lanes read byte addresses 0, 128, 256 and 384. Is this a broadcast?Answer
No. They read four different words in bank 0, making a four-way conflict in the stated model.
3.Would a small lookup table with one distinct lookup per lane necessarily favor constant memory?Answer
No. Constant requests serialize by distinct address within a warp. Read-only global access may be a better hypothesis, which still needs measurement.
Practice
- TensorTonic: Shared-Memory Bank Conflict Analyzer
Implement
bank_conflict_analysis; work all three public cases: adjacent words, four-way conflict and same-address broadcastThis free problem counts distinct addresses per bank and returns a degree for each lane. Treat it as a scalar-read model. Add your own full-warp stride and padded-tile cases; the section mini-project covers paired conflicting and conflict-free kernels.
You're done when
Your analyzer passes the public examples and your five stride cases, and you can defend a memory-space choice from the warp's addresses without calling all read-only data constant memory.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 8 more in the 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.
- 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
- 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.