什么是GPU上的相干内存? [英] What is coherent memory on GPU?

查看:146
本文介绍了什么是GPU上的相干内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一次也没有迷失在

与图形编程有关的技术论文.我一直在寻找简单明了的解释,但是发现大部分此类的硬核"论文.我很高兴收到外行的关于GPU架构上实际上是什么一致性内存以及如何将其与其他(可能是非一致性)内存类型进行比较的风格答案.

tech papers related to graphics programming.I have been searching for a simple and clear explanation,but found mostly 'hardcore' papers of this type.I would be glad to receive layman's style answer on what coherent memory actually is on GPU architectures and how it is compared to other (probably not-coherent) memory types.

推荐答案

内存就是内存.但是不同的事物可以访问该内存. GPU可以访问内存,CPU可以访问内存,也许还可以访问其他硬件位.

Memory is memory. But different things can access that memory. The GPU can access memory, the CPU can access memory, maybe other hardware bits, whatever.

如果其他人对该存储器所做的更改对于读者来说可见,则特定事物可以连贯"地访问存储器.现在,您可能会认为这是愚蠢的.毕竟,如果内存已更改,那么可能怎么可能看不到它?

A particular thing has "coherent" access to memory if changes made by others to that memory are visible to the reader. Now, you might think this is foolishness. After all, if the memory has been changed, how could someone possibly be unable to see it?

简单地说,就是缓存.

事实证明,更改内存非常昂贵.因此,除非绝对必要,否则我们将尽一切可能避免更改内存.当您将一个字节从CPU写入内存中的指针时,CPU尚未将该字节写入.或者至少,不是为了记忆.它将其写入该内存的本地副本,称为缓存".

It turns out that changing memory is expensive. So we do everything possible to avoid changing memory unless we absolutely have to. When you write a single byte from the CPU to a pointer in memory, the CPU doesn't write that byte yet. Or at least, not to memory. It writes it to a local copy of that memory called a "cache."

其原因是,通常来说,应用程序不写入(或读取)单个字节.它们更有可能以小块形式写入(和读取)大量字节.因此,如果您要执行昂贵的操作,例如加载或存储内存,则应加载或存储大量内存.因此,您将要对内存块进行的所有更改都存储在缓存中,然后在将来的某个时刻将该缓存块一次写入实际内存中.

The reason for this is that, generally speaking, applications do not write (or read) single bytes. They are more likely to write (and read) lots of bytes, in small chunks. So if you're going to perform an expensive operation like a memory load or store, you should load or store a large chunk of memory. So you store all of the changes you're going to make to a chunk of memory in a cache, then make a single write of that cached chunk to actual memory at some point in the future.

但是,如果您有两个使用相同内存的独立设备,则需要某种方式来确保写入一个设备使其他设备可见.大多数GPU无法读取CPU缓存.而且大多数CPU语言都没有语言级别的支持来表示嘿,我写到内存的东西了吗?我真的是想让您现在将其写到内存中."因此,您通常需要一些东西来确保更改的可见性.

But if you have two separate devices that use the same memory, you need some way to be certain that writes one device makes are visible to other devices. Most GPUs can't read the CPU cache. And most CPU languages don't have language-level support to say "hey, that stuff I wrote to memory? I really mean for you to write it to memory now." So you usually need something to ensure visibility of changes.

在Vulkan中,标记为"HOST_COHERENT"的内存意味着,如果您通过映射指针写入该内存(因为这是Vulkan允许您直接写入内存的唯一方法),则不要需要使用特殊功能来确保GPU可以看到这些更改.保证了GPU对任何更改的可见性.如果该标志在内存中不可用,则必须使用Vulkan API来确保要访问的特定数据区域的一致性.

In Vulkan, memory which is labeled "HOST_COHERENT" means that, if you write to that memory (via a mapped pointer, since that's the only way Vulkan lets you directly write to memory), you don't need to use special features to make sure the GPU can see those changes. The GPU's visibility of any changes is guaranteed. If that flag isn't available on the memory, then you must use Vulkan APIs to ensure the coherency of the specific regions of data you want to access.

有了连贯的内存,就硬件而言,正在发生两件事之一. CPU对内存的访问未缓存在任何CPU的高速缓存中,或者GPU可以直接访问CPU的高速缓存(可能是由于与CPU处于相同的管芯).您通常可以说后者正在发生,因为Vulkan的裸机GPU实现不必费心提供非一致性内存选项.

With coherent memory, one of two things is going on in terms of hardware. Either CPU access to the memory is not cached in any of the CPU's caches, or the GPU has direct access to the CPU's caches (perhaps due to being on the same die as the CPU(s)). You can usually tell that the latter is happening, because on-die GPU implementations of Vulkan don't bother to offer non-coherent memory options.

这篇关于什么是GPU上的相干内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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