Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
753 views
in Technique[技术] by (71.8m points)

cuda - Performance of atomic operations on shared memory

How atomic operations perform when the address they are provided with resides in block shared memory? During atomic operation, does it pause accesses to the same shared memory bank by other threads inside block, or stops other threads from doing any instructions, or even stops threads across all blocks until the atomic operation is done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The shared memory hardware includes 1024 locks. If you call an atomic intrinsic that operates on shared memory, the compiler emits a short loop that acquires and conditionally releases the lock, or loops if the lock was not acquired. As a result, performance can be extremely data-dependent: if all 32 threads in a warp try to acquire different locks, they will all perform their atomic operation and release the locks without looping at all. On the other hand, if all 32 threads in a warp try to acquire the same lock, the warp will loop 31 times as each thread performs its atomic operation and releases the lock that all of the other threads are trying to acquire.

The lock acquired is determined by bits 2-11 of the shared memory address. So as with most memory operations in CUDA, operating on consecutive 32-bit addresses usually gives good performance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...