Exercises — GPU memory bandwidth optimization
This page tests everything the parent note 6.2.14 built: coalescing, banks, AoS vs SoA, tiling, arithmetic intensity, and the Roofline picture. Work each problem before opening its solution.
Before we begin, one shared vocabulary reminder in plain words, so no symbol is used unexplained:
Related tools you may lean on: Roofline-Model, CUDA-Shared-Memory, Cache-Hierarchy, GPU-Warp-Scheduling, Memory-Latency-Hiding, Parallel-Algorithm-Design.
Level 1 — Recognition
Exercise 1.1 — Count the transactions (coalesced)
A warp of 32 threads each reads one 4-byte float from consecutive addresses starting at address A. Transaction size bytes. How many transactions does the warp need, and what is the efficiency ?
Recall Solution
What the addresses span: thread reads , for . The lowest byte touched is , the highest is . So the whole warp touches bytes through — exactly 128 bytes.
Transactions: transaction.
Efficiency: useful bytes ; hauled bytes . This is the ideal "fully coalesced" case — one truck, one full crate, nothing wasted.
Exercise 1.2 — Which bank?
Shared memory has banks and a word size of 4 bytes. A thread accesses byte address A = 260. Which bank does it land in?
Recall Solution
Why divide by word size first: banks are assigned per word, not per byte. Word index . Apply the bank rule : Word 65 = 2 full sweeps of 32 banks (words 0–63) plus 1, landing on bank 1.
Level 2 — Application
Exercise 2.1 — Strided access
Thread in a 32-thread warp reads a 4-byte float at address — i.e. a stride of 32 floats between threads. . Find transactions and efficiency.
Recall Solution
Span: thread 0 at , thread 31 at ; add the 4 bytes read bytes … . Each thread's float sits in its own 128-byte crate (spacing B = exactly one crate apart). Transactions: each of the 32 threads forces a separate crate transactions. Efficiency: This is the worst case in the parent note: 96.875% of hauled bytes are thrown away.
Exercise 2.2 — AoS field read
A particle struct is {float x,y,z,vx,vy,vz;} = 24 bytes per element. A warp reads the .x field: thread reads base + 24i. . How many transactions per field, and ?
Recall Solution
Span of the wanted bytes: thread 0 at offset 0, thread 31 at offset ; +4 bytes 748 bytes of span. Crates covering that: . Aligning to the parent's count, the address range spans bytes of stride: Efficiency: useful B; hauled B. AoS partially coalesces — 6 trips, not 32 — but wastes 5/6 of the bandwidth.
Level 3 — Analysis
Exercise 3.1 — AoS vs SoA over all six fields
Using Ex 2.2, a kernel reads all 6 fields (x,y,z,vx,vy,vz) once per warp. Compute total transactions for AoS and for SoA, and the reduction factor.
Recall Solution
AoS: each field costs 6 transactions (Ex 2.2) transactions.
SoA: each field is its own contiguous array, thread reads base + 4i 1 transaction/field (Ex 1.1) transactions.
Reduction:
Exercise 3.2 — Tiling traffic and arithmetic intensity
For matrix multiply tiled with tiles (, 4-byte floats), derive (a) global-memory reduction factor vs naive, (b) bytes moved, (c) arithmetic intensity .
Recall Solution
(a) Reduction factor. Naive: global element-reads per output element. Tiled: each element enters shared memory once per tile, and there are tiles along , giving global reads per output element. (b) Bytes moved (tiled). outputs reads bytes: (c) Arithmetic intensity. FLOPs (one multiply + one add per inner term). See the picture below for how this point sits on the roofline.

Level 4 — Synthesis
Exercise 4.1 — Roofline verdict
The machine has 20 TFLOP/s peak compute and 1 TB/s peak bandwidth. Find the machine balance , then classify: naive multiply (), tiled (), and a register-blocked kernel with .
Recall Solution
Machine balance — the intensity where the two ceilings cross: Rule: bandwidth-bound (memory is the ceiling); compute-bound.
- Naive → bandwidth-bound (heavily).
- Tiled → still bandwidth-bound, but with 32× less traffic than naive.
- Register-blocked → compute-bound — memory is no longer the bottleneck. See Roofline-Model for the full graph.
Exercise 4.2 — Attainable throughput
For the tiled kernel () on this machine, what is the attainable performance (FLOP/s)? For the register-blocked one ()?
Recall Solution
The roofline formula: attainable . Tiled (, bandwidth-bound): Since , the memory slope wins — 8 TFLOP/s, i.e. 40% of peak. Register-blocked (): , but capped by peak TFLOP/s (full peak).
Level 5 — Mastery
Exercise 5.1 — Diagnose and fix a bank conflict
A tile __shared__ float tile[32][32] is stored, then read column-wise: thread (a whole warp varying the row) reads tile[i][col] for fixed col. Word size 4 B, 32 banks. (a) Which bank does thread hit? (b) How many cycles does the warp take? (c) Propose a one-line fix and give the new cycle count.
Recall Solution
(a) Bank of tile[i][col]. In a [32][32] array the linear word index is .
Every thread hits the same bank = , because the term is a multiple of 32 and vanishes under the modulo.
(b) Cycles. 32 threads, one bank, all different addresses (different rows) a full 32-way conflict cycles (vs 1 ideal). Not a broadcast: broadcast needs the same address, here rows differ.
(c) Fix — pad the row. Declare tile[32][33]. Now the linear index is :
which is distinct for each 32 different banks cycle. One wasted padding column removes the 32× serialization.

Exercise 5.2 — End-to-end throughput budget
Machine: TB/s, peak 20 TFLOP/s. A kernel is fully coalesced (), cache hit rate , occupancy . (a) Effective throughput . (b) If its arithmetic intensity is FLOP/byte, what compute rate does that support, and is it compute- or bandwidth-bound?
Recall Solution
(a) Combine the efficiencies (they multiply, since each independently trims usable bandwidth): (b) Compute rate from that memory feed = TFLOP/s. Compare to peak 20 TFLOP/s: bandwidth-bound — the memory feed, not the ALUs, limits us.
Recall Self-test one-liners
Fully coalesced warp of 32 floats needs how many transactions? ::: 1 AoS 24-byte struct, reading one field, transactions per warp? ::: 6 (efficiency 16.67%) Reduction in global traffic from tiling? ::: A factor of Arithmetic intensity of tiled matmul, , floats? ::: 8 FLOPs/byte Machine balance for 20 TFLOP/s and 1 TB/s? ::: 20 FLOPs/byte Fix for a 32-way shared-memory column conflict? ::: Pad the tile row to width 33