What this video shows
About this walkthrough
A tiled matrix transpose reads its shared-memory tile down a column, so a full warp asks one bank for 32 different addresses. Declaring the tile as 32 by 33 instead of 32 by 32 spreads those reads across all 32 banks. Bank serialization falls from 8.74x to 1.06x, and the largest launch drops from 310 to 227 microseconds in this pair of runs. The overall unprofiled runtime did not improve.
Read along
Transcript
Select a time to play the video from that chapter.
0:00One extra column
Why can one extra column make a CUDA transpose faster? Let's investigate this matrix transpose lab in GPUFlight.
0:10Understand the problem
The task is to swap a matrix's rows and columns. The starting kernel already uses a shared-memory tile to keep global reads and writes coalesced. Our goal is to reduce shared-memory bank conflicts while preserving correct output, including partial tiles.
0:28Measure the starting point
First, run the original code on the RTX 3090. The output is correct, but bank serialization is 8.74 times. The lab asks us to reach 1.10 or less.
0:44Explore the baseline profile
Open the session, choose Kernels, and expand the launches. For the largest launch, the hardware counters show 88.6 percent bank overhead. The 8.74 figure is average serialization, not a prediction of the entire kernel's slowdown.
1:02Read the access pattern
The code shows why this happens. Threads first write a row of the tile, then synchronize. The output reads the tile with the indices reversed. Within a warp, neighboring threads now read different rows of the same column.
1:17Why the banks conflict
Shared memory has 32 banks. For these floats, the bank is the word index modulo 32. With a 32-word row stride, column addresses zero, 32, and 64 all map to bank zero. Different addresses in the same bank must be serviced in separate steps, reducing effective bandwidth. A full warp's column read has a 32-way conflict. That access pattern comes from the code.
1:44Change the row stride
Let's change only the shared array declaration. Keep 32 rows, but make the second dimension 33. The logical tile, thread block, boundary checks, and synchronization stay the same.
1:59Why padding helps
Now the column addresses are zero, 33, and 66. They map to banks zero, one, and two, spreading a full warp across all 32 banks. The extra column adds just 128 bytes to the declared shared array per block.
2:16Run and verify
Run the padded version on the same GPU. The output still passes, and bank serialization falls to 1.06 times. That meets the lab's target and approaches conflict-free access.
2:31Inspect the new counters
Open the new profile and inspect the same launch. Bank overhead drops from 88.6 to six percent. Load conflicts fall from about 16.3 million to about 92,000. These measured counters support the access-pattern explanation.
2:50Check what did not change
Peak in flight remains 128 MiB in both runs. This view tracks device allocations, not the shared tile inside each block. Padding improves access to shared memory; it doesn't remove the input or output matrix.
3:07Compare kernel time and runtime
The comparison shows kernel time dropping from 310 to 227 microseconds, about 27% in this pair. The overall unprofiled test runtime did not improve. Repeat measurements before treating this as a reliable end-to-end speedup.
3:27Measure, explain, verify
The lesson is to match memory layout to the way threads access it. Read the code, measure the conflict, change the stride, and verify both correctness and performance. Try this matrix transpose lab in GPUFlight Performance Lab.
Measure it yourself
Run the same experiment on a real GPU
Edit the kernel in your browser, run it on managed hardware, and read the profile the video walks through.
Run the matrix transpose lab