什么是内存事务
了解缓存行以及 32/128 字节的内存段
什么是内存事务 是 CoddyKit 上的免费 CUDA Academy 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 CUDA Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 CUDA Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Memory Comes in Chunks
The GPU never fetches a single byte by itself. It moves memory in fixed-size blocks called a memory transaction, even if you only asked for one value.
The Warp Asks Together
A warp of 32 threads issues its loads at the same time. The hardware gathers all 32 requests and tries to serve them with as few transactions as possible.
Cache Lines and Segments
Global memory is carved into aligned segments, commonly 32 or 128 bytes wide. Each transaction pulls in one whole segment, never a partial slice.
Why 128 Bytes Matters
A 128-byte line holds exactly 32 four-byte floats. That is one value for every thread in a warp, so a tidy warp can be served by a single transaction.
// 32 threads x 4-byte float = 128 bytes = one lineAlignment Is Key
Segments start at fixed, aligned addresses. If your data begins mid-segment, a single warp can spill across two lines and force an extra transaction.
Paying for Bytes You Skip
If a warp touches only a few bytes of a 128-byte line, the GPU still moves all 128. The unused bytes are wasted bandwidth you paid for anyway.
Counting Transactions
Performance often comes down to one number: how many transactions a warp needs. Fewer transactions means you read less and finish faster.
The Best Case
When 32 threads read 32 neighboring floats from an aligned address, the GPU answers with one clean 128-byte line. That is the ideal single transaction.
float v = data[blockIdx.x * blockDim.x + threadIdx.x];The Worst Case
If each thread grabs a value far from its neighbors, the warp may trigger up to 32 separate transactions, dragging in 32 full lines for tiny use.
Bandwidth Is the Limit
Most kernels are bound by how fast they move memory, not by math. Shrinking transaction count directly raises your effective bandwidth. 🚀
Set the Stage
Now you know the unit of cost: the segment-sized transaction. Every coalescing trick ahead is really about packing warps into as few of these as you can.
Quick Check
Test your grasp of transaction size.
Recap
You learned that the GPU moves memory in fixed segments, and a warp is served by as few transactions as it can manage. Fewer transactions, faster kernel. 🎉
常见问题解答
「什么是内存事务」课时是免费的吗?
是的 — 「什么是内存事务」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 CUDA Academy 课程的其余内容,请升级到 CoddyKit PRO。 CUDA Academy 课程共包含 4 节课。
「什么是内存事务」这节课中我会学到什么?
了解缓存行以及 32/128 字节的内存段 你通过在浏览器中直接运行的动手代码来练习 CUDA Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 CUDA Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 CUDA Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「什么是内存事务」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 CUDA Academy 课中编写并运行代码吗?
能。每节 CUDA Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 什么是内存事务
- 合并读取与跨步读取
- 数组结构与结构体数组
- 测量有效带宽