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. It does not synchronize across blocks.
  • B. Correct. It is a barrier within a block.
  • C. It does not align clocks.
Practice this topic Back to topic

More GPU Programming questions

  1. In CUDA, __syncthreads() is placed inside "if (threadIdx.x < 16)" so that only some threads reach it. What can happen?
  2. Which describes a bank conflict in CUDA shared memory?
  3. A 32 × 32 float tile in shared memory causes bank conflicts when a warp's 32 threads read down a column. What is the common fix?
  4. When multiplying large matrices on a GPU, why are the matrices split into small tiles loaded into shared memory?
  5. What can happen if a GPU kernel uses too many registers per thread?