liveBook · Manning

Shared memory bank conflict

As explained in Grokking GPU Programming

A bank conflict occurs when threads in the same GPU warp access different data assigned to the same shared-memory bank, requiring serialized service.

Shared memory can serve a warp’s accesses at once when its threads use different banks. A bank conflict occurs when threads in the same warp access different addresses in the same bank; those accesses must be serialized. section 11.7

In the 32-bank model for 4-byte elements, an element maps to its index modulo 32. Consecutive accesses land in different banks, but stride-2 accesses use only 16 banks and take two rounds. If all 32 threads access different elements in one bank, service takes 32 rounds. A warp reading the same address is a broadcast, not a conflict. section 11.7 section 11.14

A common symptom is a correct kernel running unexpectedly slowly, with a profiler showing shared-memory accesses serialized. For a 32×32 tile read column-wise, the warp’s threads all hit the same bank. Padding each row to 33 elements shifts successive rows across banks and removes this 32-way conflict for 4-byte elements. Recalculate the mapping for other element sizes or index patterns. section 11.11 section 11.14

__shared__ float tile[32][33];    #A
value = tile[threadIdx.x][0];    #B

Compare the padded tile and column access with the 32×32 version to see the conflict fix. section 11.11

The same strided-access issue can arise in Blelloch scan; padding is a possible remedy, while production libraries such as CUB handle it automatically. section 7.11

How Grokking GPU Programming covers it

How deep it goes
Explains bank mapping, warp access patterns, serialized conflicts, padding, and limits of the example’s assumptions.
Examples
Uses stride-1 and stride-2 reads, a 32×32 column-access tile, and padding to 32×33 elements.
What it assumes
Explains warp grouping and bank mapping, while assuming familiarity with arrays and thread-indexed accesses.
What you can do after
Diagnose serialized shared-memory accesses and choose padding after checking the bank mapping.
How it connects
Connects shared memory and warps to CUDA thread layout, tiled matrix multiplication, and Blelloch scan.

Also explained in

Compare how 2 books explain shared memory bank conflict →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.