What Is a GPU Memory Bank Conflict? Calculate and Reduce CUDA Shared-Memory Contention
A memory bank conflict occurs when different threads in a CUDA warp request **different addresses** in shared memory that map to the same bank. The hardware then splits the request into multiple conflict-free requests, which can reduce the effective bandwidth of that instruction. By contrast, several threads reading the same address may be served by a broadcast and need not conflict. This article covers NVIDIA CUDA shared memory; its 32-bank and 32-bit-word examples apply only to the documented 32-bit bank organization.
What Is a GPU Memory Bank Conflict? Calculate and Reduce CUDA Shared-Memory Contention
A memory bank conflict occurs when different threads in a CUDA warp request different addresses in shared memory that map to the same bank. The hardware then splits the request into multiple conflict-free requests, which can reduce the effective bandwidth of that instruction. By contrast, several threads reading the same address may be served by a broadcast and need not conflict. This article covers NVIDIA CUDA shared memory; its 32-bank and 32-bit-word examples apply only to the documented 32-bit bank organization.
Which addresses map to the same bank?
Shared memory is divided into banks so accesses to different banks can be serviced in parallel. If one memory instruction in a warp asks multiple lanes for different locations in the same bank, the hardware divides the conflicting request into several conflict-free requests. The conflict degree is a useful short description of how many serialized requests are needed. It does not mean that the whole kernel's latency necessarily grows by that factor: other instructions or computation may overlap, and the compiler may turn a source-level access into multiple machine instructions.
The CUDA Programming Guide describes an example with 32 banks, where successive 32-bit words map to successive banks. Under that condition, if w is a 32-bit word index, the bank number is w mod 32. Thirty-two consecutive words use each bank once. This calculation is a model for understanding address patterns. For other data types, access widths, bank-size settings, or GPU generations, check the target device and compiled instructions.
| Warp request | Handling in the 32-bit example | Conflict? |
|---|---|---|
| Different word per lane, each address in a different bank | Serviced in parallel by multiple banks | No conflict |
| Different words with a stride of 2 in 32-bit words | Each pair of lanes can request the same bank, causing a 2-way conflict | Yes |
| Every lane reads the same word | The word is broadcast to the requesting lanes | No conflict |
| Different words in the same bank | The requests are serialized | Yes |
Bank identity alone does not determine whether a conflict exists; first check whether the addresses are different. The CUDA guide says that reads by multiple lanes from the same shared-memory location are broadcast. For writes, it states that when multiple lanes write the same address, the writing lane is undefined, so this must not be treated as a safe reduction or deterministic result. Apply CUDA's atomic or synchronization rules when the algorithm needs an update or aggregation.
How does stride change the conflict degree?
Suppose each lane requests the 32-bit word at base + stride * lane. In the 32-bank model, lane t reaches bank (base + stride * t) mod 32. When the stride and 32 are coprime, all 32 lanes reach different banks. As the greatest common divisor grows, banks repeat. With all 32 lanes active and each lane requesting a distinct 32-bit word, the conflict degree is gcd(stride, 32).
| 32-bit word stride | Banks reached by 32 lanes | Idealized conflict degree | Why |
|---|---|---|---|
| 1 | 32 | 1-way, no conflict | Each lane reaches the next bank |
| 2 | 16 | 2-way | The bank pattern repeats every two lanes |
| 3 | 32 | 1-way, no conflict | 3 and 32 are coprime |
| 16 | 2 | 16-way | Alternates between two banks |
| 32 | 1 | 32-way | Every address maps to one bank, but the words differ |
For example, if a warp reads shared[2 * lane], consecutive pairs of lanes fold onto the same bank number, creating a 2-way conflict. For shared[32 * lane], every lane has the same bank number, but each lane requests a different word, so the request has a 32-way conflict. By contrast, shared[constantIndex] asks every lane to read one word and is the broadcast exception. This distinction corrects the common oversimplification that “same bank always means conflict.”
The gcd calculation is a quick mental model, not a complete performance prediction for every kernel. A tail warp with only some lanes active, vector accesses wider than 32 bits, subword types, or instructions split by the compiler must be analyzed using the actual active lanes and width of each machine instruction. The CUDA guide's bank example describes consecutive 32-bit words. For unusual widths or device configurations, also inspect the target GPU documentation, generated SASS, and profiler metrics.
Why can a matrix transpose create a 32-way conflict?
Assume a row-major tile[32][32] where each float is 32 bits. If a warp reads tile[row][lane], addresses are adjacent and banks are distributed from 0 through 31. But if the same warp reads tile[lane][column], it advances by 32 words between rows. The bank number (32 * lane + column) mod 32 is therefore column for every lane, even though each lane requests a different word in a different row. This is a 32-way conflict. NVIDIA's transpose explanation shows how a shared-memory tile used to make global-memory accesses contiguous can create a separate bank conflict inside the tile.
The diagram below summarizes the bank mapping for a column read. In tile[32][32], all lanes map to one bank. Increasing the row stride to 33 words rotates the bank as the column is traversed.
32 x 32 tile, tile[lane][0]:
lane 0 1 2 3 ... 30 31
bank 0 0 0 0 ... 0 0 -> 32-way conflict on different words
32 x 33 tile, tile[lane][0]:
lane 0 1 2 3 ... 30 31
bank 0 1 2 3 ... 30 31 -> each lane uses a different bankNVIDIA's classic transpose example adds one element to the last array dimension, producing a 32 x 33 tile. The word index is then row * 33 + column; for a column access, the bank index becomes (row + column) mod 32, so 32 lanes use distinct banks. The excerpt below illustrates the address relationship. It is not a complete transpose kernel or a recommended tile size for every GPU.
__shared__ float tile[32][33];
// A row-wise load gives lanes adjacent addresses and distinct banks.
tile[threadIdx.y][threadIdx.x] = input[row * width + col];
__syncthreads();
// The 33-word row stride rotates banks during the transposed read.
float value = tile[threadIdx.x][threadIdx.y];__syncthreads() is included to order the block's tile write before the later read. In a real kernel, structure control flow so every thread reaches the barrier, and check valid bounds for edge tiles. Padding increases shared-memory use, and wider accesses or a different layout can change the address mapping. Verify the same address calculation for the target data type and device instead of copying the 32×33 padding to every array.
How can you measure and fix the issue safely?
Nsight Compute's Shared Memory table reports instructions, requests, wavefronts, utilization, and bank conflicts. The guide describes a wavefront as a unit needed to service the requested data and explains that bank-conflicting requests are split into multiple conflict-free requests. Sections and metrics can vary by GPU and Nsight Compute version, so first check the installed section list and whether the target kernel supports the analysis.
ncu --section MemoryWorkloadAnalysis_Tables ./my_appDo not add padding just because a conflict appears in a table. First confirm that the conflict matters to the slow kernel and that the metric corresponds to the relevant shared-memory instruction. A change can also affect global-memory coalescing, tile size, synchronization count, and shared-memory occupancy. Compare the actual workload before and after the change:
**Fix the target and baseline.** Record the slow kernel, representative input, GPU model, CUDA and Nsight versions, and repeated-measurement conditions.
**Calculate addresses for the relevant instruction.** List active lanes and their 32-bit word indices, then map each address using the documented bank rule. Distinguish requests for the same word from requests for different words.
**Check profiler evidence.** Connect Shared Memory requests, wavefronts, and bank-conflict information to the kernel instruction and phase. Confirm that the GPU supports the reported metric.
**Change one layout choice.** If needed, change padding, tile direction, or access order. Preserve synchronization and bounds, then verify results. If increasing a tile, also calculate its effect on shared-memory resources and resident blocks.
**Confirm gains on the same path.** Compare repeated kernel time and end-to-end time including preprocessing and copies. Do not mistake profiler collection overhead for performance; roll back if gains do not reproduce or another access becomes slower.
| Observation | Possible explanation | What to check next |
|---|---|---|
| High bank conflicts and a slow tile-column access | Warp lanes repeat onto one bank, as with a 32-word stride | Calculate lane addresses and banks; evaluate padding or tile direction for this type and GPU |
| Same bank is requested but no conflict is reported | Lanes may read the same word and use broadcast, or addresses overlap within one instruction | Check whether the word addresses are actually identical and read the metric definition |
| Conflicts fall after padding but the kernel slows down | More shared memory, lower occupancy, worse global access, or more synchronization | Compare resource use and the full kernel path; revert if there is no measured gain |
| Source-level analysis predicts a conflict but the metric differs | Compiled instruction, access width, or active lanes differ from the hand calculation | Inspect SASS and the GPU/profiler documentation; recalculate at the actual instruction level |
Diagnosing bank conflicts means examining address identity, access width, and active lanes for each instruction, not merely counting how many lanes share a bank. CUDA's 32-bank mapping and 32×33 transpose tile are useful documented examples, but padding is not a performance guarantee. Keep a layout change only when profiler evidence and the full execution path show a repeatable benefit.
References
[NVIDIA CUDA Programming Guide — Shared Memory Access Patterns and Bank Conflicts](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/writing-cuda-kernels.html)
[NVIDIA CUDA C++ Best Practices Guide — Shared Memory and Memory Banks](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html)
[NVIDIA Nsight Compute Profiling Guide — Shared Memory Tables](https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html)