6.2.9 · D3GPU Architecture

Worked examples — Bank conflicts in shared memory

2,710 words12 min readBack to topic

This page is the drill floor for Bank conflicts in shared memory. We take the one master tool — the bank formula and its conflict degree — and throw every kind of access pattern at it until nothing can surprise you.

Before we compute anything, let us re-earn the two tools we will lean on the whole way.

The offset never changes the conflict degree — it only slides every thread by the same amount, shifting which banks are used, not how many threads share a bank. Keep that in your pocket.


The scenario matrix

Every access pattern this topic can throw at you falls into one of these cells. The worked examples that follow are each tagged with the cell they cover.

Cell What makes it distinct Covered by
A. Stride-1 (degenerate, best case) , gcd Ex 1
B. Odd stride ≠ 1 odd, coprime to 32, still conflict-free Ex 2
C. Even stride, partial conflict shares a factor with 32 Ex 3
D. Worst case (fully serialized) a multiple of 32, gcd Ex 4
E. Nonzero offset (sign/shift check) offset present — does it change the answer? Ex 5
F. Column walk in a 2-D array + padding fix derived stride from array shape Ex 6 (figure)
G. AoS struct-size trap stride implied by sizeof(struct) Ex 7
H. Sub-word / broadcast (zero effective stride) all threads → one address (special, NOT a conflict) Ex 8
I. Real-world word problem histogram / reduction access Ex 9
J. Exam twist (multi-word / double, ≥32 threads) 8-byte type, reason in 4-byte banks Ex 10

We will also hit the limiting behaviour: as climbs through powers of two, watch the conflict degree double at each step (Ex 3 → Ex 4), and as becomes odd again the conflicts vanish (Ex 2). The visual for that is below.

Figure — Bank conflicts in shared memory

Worked examples

Figure — Bank conflicts in shared memory

This is exactly the pattern behind matrix transpose optimization, and it lives right next to memory coalescing in your kernel-tuning toolkit.


Recall Quick self-test (reveal after guessing)

Stride 12 — conflict degree? ::: → 4-way conflict. Stride 15 — conflict degree? ::: (15 is odd) → conflict-free. Does adding offset change any conflict degree? ::: No — offset shifts which banks, never the pile-up count. All 32 threads read the same word — how many cycles? ::: 1 (broadcast), because it's the same address, not different ones. Padding [32][32][32][33] fixes a column walk because 33 mod 32 = ? ::: , so each row shifts by exactly one bank.

Where to go next: conflict-free shared memory feeds directly into occupancy and resource limits (shared memory per block caps how many warps fit), and the column-walk fix is the heart of matrix transpose optimization. Beware combining these lessons with warp divergence, which serializes for a different reason (branches, not banks), and with memory coalescing, which is the global-memory cousin of this same "make accesses line up" idea. The layout rules trace back to shared memory architecture.