# 暂存器内存

暂存器内存（SPM）是一种小容量、高速的片上内存，其内容由软件、程序员或编译器显式放置和管理，而非由缓存硬件自动管理。它通常以普通 SRAM 构建，具有固定的、往往单周期的访问延迟，并且使用与主存分离的地址空间，因此除非软件将数据放入其中，否则任何数据都不会进入。<sup>[1](https://inferensys.com/glossary/neural-processing-unit-acceleration/memory-hierarchy-management/scratchpad-memory)</sup><sup> • </sup><sup>[2](https://www.sciencedirect.com/topics/computer-science/scratchpad-memory)</sup>

| 关键事实 | 详情 |
|---|---|
| 管理方式 | 软件管理：程序员或编译器显式控制数据移动，消除缓存未命中的不可预测性<sup>[1](https://inferensys.com/glossary/neural-processing-unit-acceleration/memory-hierarchy-management/scratchpad-memory)</sup> |
| 寻址方式 | 非透明，独立于后备存储的分离命名空间；缓存则是透明的，共享同一地址空间<sup>[2](https://www.sciencedirect.com/topics/computer-science/scratchpad-memory)</sup> |
| 硬件成本 | 无标签、比较逻辑或替换逻辑，因此面积和功耗开销低于同等大小的缓存<sup>[3](https://www.electronicsguide.net/systems-and-technologies/embedded-systems/memory-systems/cache-architectures/)</sup> |
| 延迟 | 固定，通常为单周期或其他确定性延迟，支持实时系统中的最坏执行时间分析<sup>[4](https://www.electronicsguide.net/foundations-and-theory/digital-electronics/real-time-digital-systems/deterministic-hardware/)</sup><sup> • </sup><sup>[5](https://arxiv.org/abs/0710.4751)</sup> |
| 典型用户 | DSP、微控制器、GPU（作为共享内存）以及 NPU、TPU 等 AI 加速器<sup>[2](https://www.sciencedirect.com/topics/computer-science/scratchpad-memory)</sup><sup> • </sup><sup>[6](https://deepwiki.com/allbilly/chip_design/6.2-memory-hierarchy%3A-cache-vs.-scratchpad)</sup> |
| 数据移动 | 显式加载、存储或 DMA 传输；IBM Cell SPE 必须通过 DMA 命令访问其局部存储之外的所有内存<sup>[7](https://research.ibm.com/publications/techniques-for-code-and-data-management-in-the-local-stores-of-the-cell-processor)</sup> |

## 与缓存的区别

硬件管理的缓存自行决定保留哪些主存内容，使用标签阵列、替换策略和一致性逻辑，应用程序完全可以对其存在一无所知。暂存器则颠倒了这一安排：应用程序掌控一切，内存使用独立的命名空间，因此数据必须在程序控制下复制进出。中间类别——软件管理的缓存——保留软件对内容的控制权，但保留缓存的透明寻址方式，使内容自动与后备存储保持一致。<sup>[2](https://www.sciencedirect.com/topics/computer-science/scratchpad-memory)</sup>

实际后果源于这种分工。由于没有标签或替换启发式，SPM 对其持有的数据具有固定访问延迟和百分之百的命中率，并且只存储程序实际需要的数据，以紧凑形式而非固定缓存行存储。<sup>[6](https://deepwiki.com/allbilly/chip_design/6.2-memory-hierarchy%3A-cache-vs.-scratchpad)</sup><sup> • </sup><sup>[8](https://rsim.cs.illinois.edu/Pubs/msinclair-thesis.pdf)</sup> 代价是编程工作量：数据必须在全局地址空间和暂存器的私有地址空间之间显式移动，脏数据必须显式写回，这排除了 GPU 上内核间的自动复用。<sup>[8](https://rsim.cs.illinois.edu/Pubs/msinclair-thesis.pdf)</sup>

## 在存储层次中的位置

在加速器中，SPM 比 HBM 等片外 DRAM 更靠近计算单元，但不同于寄存器堆；它保存频繁访问的数据、中间结果以及较大工作集的瓦片。<sup>[1](https://inferensys.com/glossary/neural-processing-unit-acceleration/memory-hierarchy-management/scratchpad-memory)</sup> DMA 引擎通常在主存和 SPM 之间移动数据，将内存访问与执行解耦，使处理单元保持忙碌。<sup>[9](https://www.mdpi.com/2079-9292/14/5/1032)</sup>

许多设计结合了两种机制。嵌入式处理器通常将缓存与暂存器配对，使可预测的热数据进入 SPM，而不规则的访问模式落入缓存，一些架构还允许将片上内存配置为两者之一。<sup>[3](https://www.electronicsguide.net/systems-and-technologies/embedded-systems/memory-systems/cache-architectures/)</sup> 从 Fermi GPU 架构开始，NVIDIA 将片上内存配置为部分缓存、部分共享内存，兼顾可预测和不太可预测的访问模式。<sup>[2](https://www.sciencedirect.com/topics/computer-science/scratchpad-memory)</sup> 研究人员还提出完全统一分区：NVIDIA 一项针对 GPU 工作负载的研究发现，寄存器、缓存和暂存器的容量需求差异很大，而按应用重新分区的统一局部内存与硬分区设计相比，性能提升高达 71%，能耗降低最多 33%。<sup>[10](https://research.nvidia.com/publication/2012-12_unifying-primary-cache-scratch-and-register-file-memories-throughput-processor)</sup>

## GPU：共享内存

NVIDIA GPU 将其暂存器暴露为*共享内存*，这是每个流式多处理器上的空间，线程块中的所有线程均可访问，物理上位于与 L1 缓存相同的统一数据缓存中。CUDA 文档将其描述为内核执行期间使用的用户管理暂存器，由于位于片上，其带宽高于全局内存，延迟更低。<sup>[11](https://docs.nvidia.com/cuda/archive/13.1.1/cuda-programming-guide/02-basics/writing-cuda-kernels.html)</sup> 分配可以是静态的，大小在编译时固定；也可以是动态的，大小在内核启动时给定。<sup>[12](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html)</sup>

[共享内存](https://www.edgepedia.org/zh/shared-memory)分为 32 个存储体，连续的 32 位字映射到连续的存储体，因此一个 warp 跨越不同存储体的访问可同时服务。当一个 warp 中的多个线程命中同一存储体中的不同地址时，访问会串行化，这种存储体冲突使有效带宽降为原带宽除以独立请求数；常见的修复方法是在数组的列维度上增加一个填充元素。<sup>[11](https://docs.nvidia.com/cuda/archive/13.1.1/cuda-programming-guide/02-basics/writing-cuda-kernels.html)</sup> 在 Volta 上，统一数据缓存为 128 KB，共享内存可配置为 0 到 96 KB；在 Turing 上为 96 KB，可选 32 或 64 KB，驱动程序在大多数情况下自动配置划分。<sup>[13](https://docs.nvidia.com/cuda/archive/10.2/cuda-c-programming-guide/)</sup> 由于暂存器以线程块粒度分配，其中一部分可能未被使用，这限制了常驻线程数，进而限制了 GPU 可维持的线程级并行度。<sup>[14](https://arxiv.org/abs/1607.03238)</sup>

## 嵌入式和实时系统

在时序和能耗比编程便利性更重要的场合，暂存器的优势最为明显。多特蒙德大学的计算机架构研究人员 Wehmeyer 和 Marwedel 比较了暂存器和缓存在最坏执行时间（WCET）分析中的表现，发现暂存器集成在保持可预测性的同时提供了与缓存相当的性能增益，因为内存状态不再依赖于执行历史。<sup>[5](https://arxiv.org/abs/0710.4751)</sup> Rajeshwari Banakar、Stefan Steinke、Bo-Sik Lee、M. Balakrishnan 和 Peter Marwedel 于 2002 年发表的基础性 CODES 论文提出 SPM 作为计算密集型嵌入式应用中缓存的设计替代方案，并使用 CACTI 工具计算了不同大小的面积和能耗。<sup>[15](https://cecs.uci.edu/~papers/compendium94-03/papers/2002/codes02/pdffiles/3_4.pdf)</sup>

实测结果证实了能耗优势。一种针对无 MMU 嵌入式系统的带按需分页的代码 SPM 管理技术，在 14 个应用上评估，在模拟器上与同等芯片面积的四路组相联缓存相比，运行时间缩短 12%，能耗降低 21%；在配备 16 KB 内存的 ARM1136JF-S 板上能耗降低 23%。<sup>[16](https://snu.elsevierpure.com/en/publications/scratchpad-memory-management-techniques-for-code-in-embedded-syst/)</sup> 一种使用运行时地址预测的编译器无关管理方案在 ARM926EJ-S 模拟器上报告称，与全缓存参考系统相比能耗降低 33.5%。<sup>[17](https://www.sciencedirect.com/science/article/abs/pii/S0141933119300183)</sup> 2023 年一种带数据布局压缩的混合缓存-SPM 架构在代表性基准集上显示平均内存动态能耗降低 43%，平均速度提升 13%。<sup>[18](https://www.sciencedirect.com/science/article/pii/S1383762123002011)</sup>

主要缺点是编译器依赖性：分配必须知道哪些数据值得占用稀缺的片上空间，传统上通过静态分析和性能剖析来实现，当访问模式在编译时不可预测时这种方法很脆弱。基于程序动态访问模式的运行时方案，例如通过 MMU 辅助地址重定向识别核心工作集，将这一决策从编译器卸载。<sup>[19](https://globals.ieice.org/en_transactions/information/10.1587/transinf.E94.D.274/_p)</sup>

## 代表性实现

**IBM Cell 宽带引擎。** [Cell](https://www.edgepedia.org/zh/cell-processor) 处理器的八个协同处理单元各包含一个 256 KB 局部存储，小、快、可直接寻址，如同暂存器，但约束是所有加载/存储和指令取指访问仅引用局部存储；所有其他内存必须通过显式编程的 DMA 命令访问。<sup>[7](https://research.ibm.com/publications/techniques-for-code-and-data-management-in-the-local-stores-of-the-cell-processor)</sup> 程序使用双缓冲，将输入分成两个缓冲区，在计算当前块的同时通过 DMA 预取下一块，以在无缓存的局部存储架构中隐藏内存延迟。<sup>[20](https://www.researchgate.net/publication/224140901_Solving_the_advection_PDE_on_the_cell_broadband_engine)</sup>

**AMD CDNA 加速器。** 在面向 Instinct MI455X 的 AMD CDNA 5 架构中，局部数据存储（LDS）——AMD 将其描述为暂存器内存——较 CDNA 4 翻倍至每 WGP 320 KB，全芯片提供 96 MB 的 LDS，是最大的 CDNA 4 实现的两倍，每时钟读写带宽更高。<sup>[21](https://www.tomshardware.com/pc-components/gpus/amd-takes-the-wraps-off-its-instinct-mi455x-ai-accelerator-cdna-5-and-helios-rack-scale-architecture-combine-to-take-the-fight-to-nvidia-in-the-data-center)</sup>

**AI 加速器总体而言。** 领域特定设计依赖暂存器实现确定性调度：因为编译器确切知道从 HBM 移入片上 SRAM 的数据何时到达，它可以调度指令在操作数可用时精确执行，这一特性对大规模并行 AI 工作负载很有价值。<sup>[6](https://deepwiki.com/allbilly/chip_design/6.2-memory-hierarchy%3A-cache-vs.-scratchpad)</sup> 研究系统进一步扩展了这一思路，从将末级缓存部分配置为暂存器并为 CNN 工作负载提供加速器优化预取的方案<sup>[9](https://www.mdpi.com/2079-9292/14/5/1032)</sup>，到末级缓存可配置为暂存器内存并配有用于加速器数据移动的 DMA 引擎的支持 Linux 的 RISC-V 主机平台<sup>[22](https://arxiv.org/abs/2305.04760)</sup>。

## References

1. [Scratchpad Memory: Definition & Use in NPUs, Inference Systems glossary](https://inferensys.com/glossary/neural-processing-unit-acceleration/memory-hierarchy-management/scratchpad-memory)
2. [Scratchpad Memory - an overview, ScienceDirect Topics](https://www.sciencedirect.com/topics/computer-science/scratchpad-memory)
3. [Cache Architectures, Electronics Guide](https://www.electronicsguide.net/systems-and-technologies/embedded-systems/memory-systems/cache-architectures/)
4. [Deterministic Hardware, Electronics Guide](https://www.electronicsguide.net/foundations-and-theory/digital-electronics/real-time-digital-systems/deterministic-hardware/)
5. [Wehmeyer, L., Marwedel, P. Influence of Memory Hierarchies on Predictability for Time Constrained Embedded Software, arXiv:0710.4751](https://arxiv.org/abs/0710.4751)
6. [Memory Hierarchy: Cache vs. Scratchpad, DeepWiki (allbilly/chip_design)](https://deepwiki.com/allbilly/chip_design/6.2-memory-hierarchy%3A-cache-vs.-scratchpad)
7. [Techniques for code and data management in the local stores of the Cell processor, IBM Research (CASES 2007)](https://research.ibm.com/publications/techniques-for-code-and-data-management-in-the-local-stores-of-the-cell-processor)
8. [Sinclair, M. D. PhD thesis, University of Illinois at Urbana-Champaign (2017)](https://rsim.cs.illinois.edu/Pubs/msinclair-thesis.pdf)
9. [Efficient Modeling and Usage of Scratchpad Memory for Artificial Intelligence Accelerators, Electronics (MDPI)](https://www.mdpi.com/2079-9292/14/5/1032)
10. [Gebhart, M. et al. Unifying Primary Cache, Scratch, and Register File Memories in a Throughput Processor, NVIDIA Research (MICRO 2012)](https://research.nvidia.com/publication/2012-12_unifying-primary-cache-scratch-and-register-file-memories-throughput-processor)
11. [Writing CUDA SIMT Kernels, CUDA Programming Guide 13.1.1](https://docs.nvidia.com/cuda/archive/13.1.1/cuda-programming-guide/02-basics/writing-cuda-kernels.html)
12. [C/C++ Language Extensions, CUDA Programming Guide](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html)
13. [CUDA Toolkit Programming Guide 10.2 archive](https://docs.nvidia.com/cuda/archive/10.2/cuda-c-programming-guide/)
14. [Scratchpad Sharing in GPUs, arXiv:1607.03238](https://arxiv.org/abs/1607.03238)
15. [Banakar, R. et al. Scratchpad Memory: A Design Alternative for Cache On-chip Memory in Embedded Systems, CODES 2002](https://cecs.uci.edu/~papers/compendium94-03/papers/2002/codes02/pdffiles/3_4.pdf)
16. [Egger, B. et al. Scratchpad memory management techniques for code in embedded systems without an MMU, IEEE Transactions on Computers 59(8), 2010](https://snu.elsevierpure.com/en/publications/scratchpad-memory-management-techniques-for-code-in-embedded-syst/)
17. [State of art innovative technique for management of scratchpad memory (scratch), Microprocessors and Microsystems 70, 2019](https://www.sciencedirect.com/science/article/abs/pii/S0141933119300183)
18. [COMPAD: A heterogeneous cache-scratchpad CPU architecture, Journal of Systems Architecture 145, 2023](https://www.sciencedirect.com/science/article/pii/S1383762123002011)
19. [Deng, N. et al. Core Working Set Based Scratchpad Memory Management, IEICE Transactions on Information E94-D(2), 2011](https://globals.ieice.org/en_transactions/information/10.1587/transinf.E94.D.274/_p)
20. [Solving the advection PDE on the Cell Broadband Engine, ResearchGate](https://www.researchgate.net/publication/224140901_Solving_the_advection_PDE_on_the_cell_broadband_engine)
21. [AMD Instinct MI455X (CDNA 5) announcement, Tom's Hardware](https://www.tomshardware.com/pc-components/gpus/amd-takes-the-wraps-off-its-instinct-mi455x-ai-accelerator-cdna-5-and-helios-rack-scale-architecture-combine-to-take-the-fight-to-nvidia-in-the-data-center)
22. [Cheshire: A Lightweight, Linux-Capable RISC-V Host Platform for Domain-Specific Accelerator Plug-In, arXiv:2305.04760](https://arxiv.org/abs/2305.04760)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Computer architecture theory › Memory hierarchy and caching

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/scratchpad-memory

English original: https://www.edgepedia.org/scratchpad-memory
