gpt4 book ai didi

c++ - tile_static 动态索引数组;我应该打扰吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:47:46 25 4
gpt4 key购买 nike

我将竭尽全力尝试将频繁访问的数据存储在 tile_static 内存中,以利用随之而来的无限性能必杀技。

但是,我刚刚读到只有某些硬件/驱动程序实际上可以动态索引 tile_static 数组,而且该操作可能会溢出到全局内存。

在理想情况下,我会这样做并进行分析,但事实证明这是一项重大手术,我想知道我是否在浪费时间:

tile_static int staticArray[128];
int resultFast = staticArray[0]; // this is super fast

// but what about this:
i = // dynamically derived value!
int resultNotSoFast = staticArray[i]; // is this faster than getting it from global memory?

如何确定我的 GPU/驱动程序是否支持静态数组的动态索引?

最佳答案

本地内存的动态索引

所以我对此进行了一些挖掘,因为我也想了解这一点。如果您指的是本地内存的动态索引,不是tile_static(或者用 CUDA 的说法,“共享内存”)。在上面的示例中,staticArray 应声明为:

int staticArray[128]; // not tile_static

这不能动态索引,因为 int staticArray[128] 数组实际上存储为 128 个寄存器,并且不能动态访问这些寄存器。像这样分配大型数组无论如何都是有问题的,因为它会占用大量寄存器,而这些寄存器是 GPU 上的有限资源。每个线程使用太多寄存器,您的应用程序将无法使用所有可用的并行性,因为一些可用线程将停止等待寄存器变得可用。

在 C++ AMP 的情况下,我什至不确定 DX11 提供的抽象级别是否会使这有点无关紧要。我还不够了解 DX11。

这里有一个很好的解释,In a CUDA kernel, how do I store an array in "local thread memory"?

银行冲突

Tile static memory is divided into a number of modules referred to asbanks. Tile static memory typically consists of 16, 32, or 64 banks,each of which is 32 bits wide. This is specific to the particular GPUhardware and might change in the future. Tile static memory isinterleaved across these banks. This means that for a GPU with tilestatic memory implemented with 32 banks if arr is an array < float, 1>, then arr[ 1] and arr[ 33] are in the same bank because each float occupies a single 32-bit bank location. This is the key point tounderstand when it comes to dealing with bank conflicts.

Each bank canservice one address per cycle. For best performance, threads in a warpshould either access data in different banks or all read the same datain a single bank, a pattern typically optimized by the hardware. Whenthese access patterns are followed, your application can maximize theavailable tile static memory bandwidth. In the worst case, multiplethreads in the same warp access data from the same bank. This causesthese accesses to be serialized, which might result in asignificant degradation in performance.

我认为混淆的关键点可能是(基于你的其他一些问题)内存条是 32 位宽但负责访问内存条内的所有内存,这将是 1/16,总图 block 静态内存的 1/32 或 1/64。

您可以在此处阅读有关银行冲突的更多信息 What is a bank conflict? (Doing Cuda/OpenCL programming)

关于c++ - tile_static 动态索引数组;我应该打扰吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19829094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com