在共享内存上执行原子操作 [英] Performance of atomic operations on shared memory

查看:1093
本文介绍了在共享内存上执行原子操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原子操作提供的地址驻留在块共享内存中时,原子操作如何执行?在原子操作期间,它是否暂停对块内其他线程对同一共享内存块的访问,或者停止其他线程执行任何指令,甚至停止所有块中的线程,直到原子操作完成?

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?

推荐答案

共享内存硬件包括1024个锁。如果调用在共享内存上运行的原子本质,编译器会发出一个短循环,用于获取并有条件地释放锁,或者如果未获取锁,则循环。因此,性能可以非常依赖于数据:如果一个warp中的所有32个线程都尝试获取不同的锁,它们都将执行它们的原子操作并释放锁,而不会循环。另一方面,如果一个warp中的所有32个线程尝试获取相同的锁,warp将循环31次,因为每个线程执行其原子操作,并释放所有其他线程尝试获取的锁。

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.

获取的锁定由共享内存地址的位2-11确定。与CUDA中的大多数存储器操作一样,在连续的32位地址上操作通常会提供良好的性能。

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.

这篇关于在共享内存上执行原子操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆