GPU Programming
What does CUDA's __syncthreads() do?
- AIt synchronizes every thread on the GPU across all blocks
- BIt makes all threads of the same block wait at that point and ensures their earlier shared-memory writes are visible
- 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.