Loading editor...

Kernel visualization: efficient matrix transpose

Two things:

  • This is a visualization of the following statement from an NVIDIA blog on efficient matrix transpose kernel.
    • "All kernels in this study launch blocks of 32×8 threads (TILE_DIM=32, BLOCK_ROWS=8 in the code), and each thread block transposes (or copies) a tile of size 32×32."
  • The trick to avoid bank conflicts during transposing a tile and storing it in SRAM.

The tile in HBM and the threads in a block are .

  • TILE_DIM and blockDim.x are both 32
  • blockDim.y is 8 Use the sliders below to see which elements are read by which thread:


Transposing when writing back from SRAM to HBM

When writing back to HBM, values from columns of SRAM are read, then transposed and written back to HBM row-wise. Note that reading values from the same column can lead to worst-case bank conflicts. This is avoided by adding an extra column to SRAM.

This shows the first few rows of the SRAM layout where each word shows the bank it belongs to. Note how the banks of each column are unique now.


Adapted from An Efficient Matrix Transpose in CUDA C/C++ (Mark Harris, NVIDIA).