0Pricing
CUDA Academy · 课时

全局内存的权衡

容量大、速度慢,并且所有线程都可访问

全局内存的权衡 是 CoddyKit 上的免费 CUDA Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 CUDA Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 CUDA Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The Biggest Space You Have

Global memory is the GPU's main DRAM, often many gigabytes. It is where your big input and output arrays naturally live during a kernel.

Visible to Everyone

Every thread in every block can read and write global memory. That shared visibility is exactly why you copy your data there before launching. 🌍

You Allocate It with cudaMalloc

You reserve global memory from the host with cudaMalloc, which hands you a device pointer to that DRAM region.

float *d_a;
cudaMalloc(&d_a, n * sizeof(float));

Large but Slow

The catch is latency. A single global memory read can cost hundreds of clock cycles, far more than a register access ever would.

Bandwidth Is the Real Limit

Many kernels are bound not by math but by how fast bytes flow from DRAM. We call these memory-bound kernels.

Hiding Latency with Threads

The GPU hides slow reads by switching to other ready warps while one waits. This latency hiding is why having many threads matters so much.

It Persists Across Launches

Data in global memory stays put between kernel launches until you free it. You can run several kernels over the same buffers.

Cached by L2

A unified L2 cache sits in front of global memory for the whole GPU. Reused addresses can be served from it instead of slow DRAM.

Access Pattern Decides Speed

How threads map to addresses hugely affects throughput. Neighboring threads touching neighboring addresses is what later lessons call coalescing.

Minimize the Trips

The core strategy is simple: touch global memory as few times as possible. Read once, reuse on-chip, then write once.

Free What You Allocate

Because global memory is a finite resource, release it with cudaFree when you are done to avoid leaking device memory.

cudaFree(d_a);

Quick Check

Which statement best captures the tradeoff of global memory?

Recap: Big, Shared, Slow

You now know global memory is the GPU's large, all-visible DRAM that trades capacity for high latency. Touch it rarely and reuse data on-chip. 🚀

常见问题解答

「全局内存的权衡」课时是免费的吗?

是的 — 「全局内存的权衡」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 CUDA Academy 课程的其余内容,请升级到 CoddyKit PRO。 CUDA Academy 课程共包含 4 节课。

「全局内存的权衡」这节课中我会学到什么?

容量大、速度慢,并且所有线程都可访问 你通过在浏览器中直接运行的动手代码来练习 CUDA Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 CUDA Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 CUDA Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「全局内存的权衡」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 CUDA Academy 课中编写并运行代码吗?

能。每节 CUDA Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 寄存器与本地内存
  2. 全局内存的权衡
  3. 常量内存及其缓存
  4. 建立层次结构的心智模型
← 返回 CUDA Academy