共享内存上原子操作的性能 [英] Performance of atomic operations on shared memory

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

问题描述

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

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天全站免登陆