GPU Programming

When transposing a large matrix on a GPU (b[j][i] = a[i][j]), what is the main purpose of going through shared memory?

  1. ATo halve the number of transpose computations
  2. BTo sort matrix values into ascending order in shared memory
  3. CTo read a tile row-wise with coalesced accesses, reorient it in shared memory and make the writes coalesced too
Show answer and explanation

Answer: C. To read a tile row-wise with coalesced accesses, reorient it in shared memory and make the writes coalesced too

Written naively, reading a row-wise is coalesced, but writing b goes column-wise with strided addresses and is slow. Loading a tile into shared memory and then reading it out with threads reassigned makes both the global reads and writes contiguous. This is combined with an extra padding column so the column-wise reads from shared memory avoid bank conflicts.

  • A. A transpose only moves values; computation count is not the issue.
  • B. It does not sort the values.
  • C. Correct. Both reads and writes use consecutive addresses.
Practice this topic Back to topic

More GPU Programming questions

  1. In CUDA, what generally happens right after the CPU-side program launches a kernel?
  2. How do the design philosophies of CPUs and GPUs differ?
  3. Which characteristic best describes work that GPUs process quickly?
  4. Which processing tends to run inefficiently on a GPU?
  5. In GPU programming such as CUDA, what is a "kernel"?