KatInterview

Cache Set Collisions, False Sharing, and GPU Bank Conflicts

System DesignModel answer
MediumModel answerSystem Designcpu-cachefalse-sharinggpu-bank-conflicts

Last updated

Work through how addresses map to cache sets to show conflict misses, then separate them from false sharing and GPU shared-memory bank conflicts, with the right fix for each.

Three different performance problems are often lumped together under the vague label "cache-line conflict". Your task is to pull them apart.

Part 1: Set conflicts. Assume a set-associative cache with line size L bytes, S sets and A ways. An address maps to set floor(address / L) mod S. Using concrete numbers, show how a program can repeatedly evict its own data even though the working set is much smaller than the cache.

Part 2: Related problems. Explain how each of the following differs from a set conflict, and how you would diagnose and fix it:

  • False sharing between threads running on different CPU cores.
  • Bank conflicts in GPU shared memory (scratchpad).

What to cover

  • Before answering, state which mechanism you think the interviewer means, and which questions you would ask (hardware, access pattern, alignment, thread-to-data mapping).
  • A worked address example with actual numbers.
  • For each of the three problems: the cause, the symptom, how to confirm it, and a fix that targets that cause specifically.
  • Explain why a fix for one problem (for example, padding) can be useless or harmful for another.

Hints

Hint 1

Start by writing the address as tag | set index | line offset, and pick numbers where the stride between accesses is a multiple of S * L.

Hint 2

A set conflict is about one core's data fighting for ways in a set. False sharing is about different cores writing different variables that live in the same line. Ask which of those is happening.

Hint 3

On a GPU, shared memory is split into banks (typically 32, each 4 bytes wide). Threads in the same warp hitting different addresses in the same bank are serialized; think about what stride across a 2D tile causes this.

Hint 4

Match each fix to its cause: change stride or layout for set conflicts, align or pad per-thread data to line size for false sharing, add a column of padding or swizzle indices for bank conflicts.