什么是银行冲突? (进行Cuda/OpenCL编程)
我一直在阅读 CUDA 和 OpenCL 的编程指南,但我无法弄清楚银行冲突是什么。他们只是深入研究如何解决问题,而不详细说明主题本身。有人能帮我理解吗?如果帮助是在 CUDA/OpenCL 的背景下,或者只是计算机科学中一般的银行冲突,我没有偏好。
I have been reading the programming guide for CUDA and OpenCL, and I cannot figure out what a bank conflict is. They just sort of dive into how to solve the problem without elaborating on the subject itself. Can anybody help me understand it? I have no preference if the help is in the context of CUDA/OpenCL or just bank conflicts in general in computer science.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于 Nvidia(以及 AMD)GPU,本地内存被分为多个内存库。每个存储体一次只能寻址一个数据集,因此如果半扭曲尝试从同一存储体加载/存储数据,则必须对访问进行序列化(这是存储体冲突)。对于 GT200 GPU,有 16 个库(Fermi 有 32 个库),AMD GPU 有 16 或 32 个库(57xx 或更高版本:32,以下所有内容:16),它们以 32 位的粒度交错(因此字节 0-3 是在银行 1 中,银行 2 中为 4-7,...,银行 1 中为 64-69,依此类推)。为了更好的可视化,它基本上看起来像这样:
因此,如果半扭曲中的每个线程访问连续的 32 位值,则不会出现存储体冲突。
此规则的一个例外(每个线程必须访问自己的存储体)是广播:如果所有线程访问相同的地址,则该值仅读取一次并广播到所有线程(对于 GT200,必须是半扭曲中的所有线程访问相同的地址,IIRC Fermi 和 AMD GPU 可以为任意数量的访问相同值的线程执行此操作)。
For Nvidia (and AMD for that matter) GPUs the local memory is divided into memory banks. Each bank can only address one dataset at a time, so if a half warp tries to load/store data from/to the same bank the access has to be serialized (this is a bank conflict). For GT200 GPUs there are 16 banks (32 banks for Fermi), 16 or 32 banks for AMD GPUs (57xx or higher: 32, everything below: 16), which are interleaved with a granularity of 32 bit (so bytes 0-3 are in bank 1, 4-7 in bank 2, ..., 64-69 in bank 1 and so on). For a better visualization it basically looks like this:
So if each thread in a half warp accesses successive 32-bit values there are no bank conflicts.
An exception from this rule (every thread must access its own bank) is broadcasting: if all threads access the same address, the value is only read once and broadcasted to all threads (for GT200 it has to be all threads in the half warp accessing the same address, IIRC Fermi and AMD GPUs can do this for any number of threads accessing the same value).
可以并行访问的共享内存被分为模块(也称为存储体)。如果两个内存位置(地址)出现在同一个存储体中,则会发生存储体冲突,在此期间访问是串行完成的,从而失去了并行访问的优势。
The shared memory that can be accessed in parallel is divided into modules (also called banks). If two memory locations (addresses) occur in the same bank, then you get a bank conflict during which the access is done serially, losing the advantages of parallel access.
简而言之,存储体冲突是指任何内存访问模式都无法在内存系统中可用的存储体之间分配 IO 的情况。以下示例详细阐述了这个概念:-
假设我们有二维 512x512 整数数组,并且我们的 DRAM 或内存系统中有 512 个存储体。默认情况下,数组数据的布局方式为:arr[0][0] 到bank 0,arr[0][1] 到bank 1,arr[0][2] 到bank 2 .... arr[0][511] 转到存储体 511。概括而言,arr[x][y] 占用存储体编号 y。现在一些代码(如下所示)开始以列主要方式访问数据,即。改变 x 同时保持 y 不变,那么最终结果将是所有连续的内存访问都将访问同一个存储体 - 因此出现存储体冲突。
通常,编译器可以通过缓冲数组或使用数组中的素数元素来避免此类问题。
In simple words, bank conflict is a case when any memory access pattern fails to distribute IO across banks available in the memory system. The following examples elaborates the concept:-
Let us suppose we have two dimensional 512x512 array of integers and our DRAM or memory system has 512 banks in it. By default the array data will be layout in a way that arr[0][0] goes to bank 0, arr[0][1] goes to bank 1, arr[0][2] to bank 2 ....arr[0][511] goes to bank 511. To generalize arr[x][y] occupies bank number y. Now some code (as shown below) start accessing data in column major fashion ie. changing x while keeping y constant, then the end result will be that all consecutive memory access will hit the same bank--hence bank conflict.
Such problems, usually, are avoided by compilers by buffering the array or using prime number of elements in the array.
(CUDA 银行冲突)
我希望这会有所帮助..
这是非常好的解释...
http://www.youtube.com/watch?v=CZgM3DEBplE
(CUDA Bank Conflict)
I hope this will help..
this is very good explaination ...
http://www.youtube.com/watch?v=CZgM3DEBplE
http://en.wikipedia.org/wiki/Memory_bank
和
http://mprc.pku.cn/mentors /training/ISCAreading/1989/p380-weiss/p380-weiss.pdf
从这个页面,您可以找到有关内存库的详细信息。
但这与@Grizzly所说的有点不同。
在这个页面中,银行就像这个
银行 1 2 3
地址|0, 3, 6...| |1、4、7...| | 2, 5,8...|
希望这会有所帮助
http://en.wikipedia.org/wiki/Memory_bank
and
http://mprc.pku.cn/mentors/training/ISCAreading/1989/p380-weiss/p380-weiss.pdf
from this page, you can find the detail about memory bank.
but it is a little different from what is said by @Grizzly.
in this page, the bank is like this
bank 1 2 3
address|0, 3, 6...| |1, 4, 7...| | 2, 5,8...|
hope this would help