GPU Programming

What does CUDA's __syncthreads() do?

  1. AIt synchronizes every thread on the GPU across all blocks
  2. BIt makes all threads of the same block wait at that point and ensures their earlier shared-memory writes are visible
  3. CIt aligns the CPU and GPU clocks
Show answer and explanation

Answer: B. It makes all threads of the same block wait at that point and ensures their earlier shared-memory writes are visible

When using shared memory, a value written by one thread must be complete before another thread reads it. __syncthreads() holds every thread in the block until all have arrived, guaranteeing, for example, that everyone has finished loading data into shared memory before computation begins. Only threads of the same block can be synchronized this way.

  • A. __syncthreads() only synchronizes threads within one block. Synchronizing across blocks needs a different method, such as a cooperative launch.
  • B. Correct. It is a barrier within a block.
  • C. It does not align clocks.