共享内存上原子操作的性能

编程入门 行业动态 更新时间:2024-10-27 12:28:50
本文介绍了共享内存上原子操作的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当提供的地址驻留在块共享内存中时,原子操作如何执行?在原子操作过程中,是暂停块内其他线程对同一个共享内存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.

更多推荐

共享内存上原子操作的性能

本文发布于:2023-06-02 14:18:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/447343.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原子   内存   性能   操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!