Farzad
Farzad

Reputation: 3438

Performance of atomic operations on shared memory

How do 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?

Upvotes: 6

Views: 4103

Answers (2)

ArchaeaSoftware
ArchaeaSoftware

Reputation: 4422

UPDATE: Since Maxwell (the generation after Kepler), NVIDIA has included hardware support for atomic operations in shared memory. Contention (i.e. if multiple threads are trying to operate on the same shared memory location) will tend to degrade performance, not unlike the looping that software must perform if there's contention on the pre-Maxwell locks.

Pre-Maxwell:

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.

Upvotes: 9

axon
axon

Reputation: 1200

From section B.11 Atomic Functions in the CUDA_C_Programming_Guide.pdf (CUDA SDK v5.0): "...no other thread can access this address until the operation is complete."

Your question can be summarized as:

Does an atomic operation:

  1. stop all threads in a block, or
  2. stop all threads only when they attempt to access the memory that is being used by the atomic operation, or
  3. stop all threads (in all blocks)?

My guess is 2: threads are stopped iff they attempt to access the memory that is locked by an active atomic op.

You could investigate what is happening by writing timer values and then process them to determine the blocking behavior. Sorry I don't have the definitive answer.

Upvotes: 0

Related Questions