Inferensys

Glossary

Scratchpad Memory

Scratchpad memory is a small, high-speed, software-managed on-chip memory used in accelerators like NPUs for explicit, low-latency storage of frequently accessed data.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
MEMORY HIERARCHY MANAGEMENT

What is Scratchpad Memory?

A definition of scratchpad memory (SPM), a software-managed on-chip memory used in hardware accelerators like Neural Processing Units (NPUs).

Scratchpad memory (SPM) is a small, high-speed, software-managed on-chip memory block in hardware accelerators like NPUs and GPUs, designed for explicit, low-latency storage of frequently accessed data. Unlike hardware-managed caches, which use automatic policies to decide what data to keep, SPM requires the programmer or compiler to explicitly control data movement, eliminating the performance unpredictability of cache misses. This makes it a deterministic, high-bandwidth resource for critical data structures, kernels, and intermediate results in compute-intensive workloads.

In the memory hierarchy of an NPU, SPM sits closer to the compute units than global DRAM (like HBM) but is distinct from registers. Its software-managed nature allows for optimal data locality exploitation through compiler techniques like tiling and double buffering, where one data block is processed while another is loaded. This explicit control is essential for achieving peak memory bandwidth and predictable low latency, which are fundamental for accelerating AI inference and training on specialized silicon.

NPU MEMORY HIERARCHY

Key Characteristics of Scratchpad Memory

Scratchpad memory is a small, high-speed, software-managed on-chip memory used in accelerators like NPUs for explicit, low-latency storage of frequently accessed data, as opposed to hardware-managed caches.

01

Software-Managed vs. Hardware-Managed

The defining characteristic of scratchpad memory is its software-managed nature. Unlike a traditional hardware cache, which uses automatic algorithms (e.g., LRU) to decide what data to keep, the programmer or compiler must explicitly control all data movement into and out of the scratchpad. This shifts the complexity of optimizing data locality from hardware logic to software, providing deterministic performance at the cost of increased programming effort. The compiler must analyze data access patterns and insert explicit DMA (Direct Memory Access) transfers or load/store instructions to populate the scratchpad.

02

Deterministic Low Latency

Because scratchpad memory is on-chip SRAM and access is controlled explicitly by software, it offers predictable, low-latency access. There is no concept of a cache miss; if data is in the scratchpad, the access time is constant. This determinism is critical for real-time and latency-sensitive applications common in NPU workloads, such as processing individual layers of a neural network within a strict inference deadline. The absence of tag-checking and replacement logic found in caches further simplifies the memory controller, reducing access energy and cycle time.

03

Explicit Data Movement & Tiling

Effective use of scratchpad memory relies on the algorithmic technique of tiling (or blocking). Large tensors or matrices are broken into smaller tiles that fit within the scratchpad's limited capacity. A computational kernel loads a tile into the scratchpad, performs all necessary operations on it, writes results back to main memory (e.g., HBM), and then loads the next tile. This pattern maximizes data reuse within the fast on-chip memory, minimizing costly accesses to slower off-chip DRAM. The compiler's ability to automate this tiling and data movement is a key optimization in frameworks like MLIR and TVM.

04

Architectural Placement & Hierarchy

In a typical NPU memory hierarchy, scratchpad memory sits between processor registers and large, off-chip High Bandwidth Memory (HBM). It is often organized as Shared Memory or Local Data Memory that is accessible by a group of processing cores (e.g., a tensor core array). This placement makes it ideal for storing:

  • Activation maps between neural network layers
  • Weight tiles for convolutional or linear layers
  • Intermediate results from partial computations Its size is a critical hardware design trade-off, typically ranging from hundreds of kilobytes to a few megabytes per core cluster.
05

Contrast with Hardware Caches

Scratchpad memory and hardware caches represent two different solutions to the memory wall problem.

Scratchpad (SPM):

  • Pro: Deterministic latency, no miss penalty, higher energy efficiency, simpler hardware.
  • Con: Requires complex compiler analysis and explicit data management.

Hardware Cache:

  • Pro: Transparent to software, adapts to dynamic access patterns.
  • Con: Non-deterministic performance due to misses, complex tag RAM and logic, coherence overhead in multi-core systems.

Many modern NPUs and GPUs use a hybrid approach, featuring both small L1 caches for instruction/ scalar data and larger software-managed scratchpads (e.g., Shared Memory in CUDA) for bulk tensor data.

06

Compiler & Runtime Role

Leveraging scratchpad memory is a primary task for NPU compilers (e.g., for Google's TPU, NVIDIA's TensorRT, or Intel's OpenVINO). The compiler's job includes:

  • Memory Allocation: Statically assigning regions of the scratchpad to specific tensors or tiles.
  • Scheduling DMA Transfers: Overlapping data movement with computation to hide latency.
  • Coalescing Accesses: Ensuring memory transactions are efficient for the underlying DRAM and interconnect (e.g., CXL).
  • Kernel Fusion: Merging operations to keep intermediate results in the scratchpad, avoiding round trips to main memory. This compiler-driven optimization is a cornerstone of achieving peak FLOPS/Watt on AI accelerators.
MEMORY HIERARCHY MANAGEMENT

How Scratchpad Memory Works in an NPU

Scratchpad memory is a foundational component of neural processing unit (NPU) architecture, designed for explicit, low-latency data management critical to AI workload acceleration.

Scratchpad memory is a small, high-speed, software-managed on-chip memory block within a neural processing unit (NPU) used for the explicit, low-latency storage of frequently accessed data, such as activation tensors and weight tiles. Unlike hardware-managed caches that operate transparently, the scratchpad requires the compiler or programmer to explicitly orchestrate data movement, enabling deterministic performance and eliminating unpredictable cache miss penalties. This explicit control is essential for maximizing data reuse and minimizing costly accesses to slower High Bandwidth Memory (HBM) or system DRAM.

The compiler statically analyzes the neural network computational graph to schedule precise load and store operations between global memory and the scratchpad, a process known as tiling or blocking. This software-defined approach allows for optimal spatial locality and temporal locality exploitation within a kernel's execution. By managing the scratchpad explicitly, NPUs achieve higher memory bandwidth utilization and lower effective memory latency for core matrix operations, which is the primary bottleneck in accelerating deep learning inference and training workloads.

ARCHITECTURAL COMPARISON

Scratchpad Memory vs. Hardware Cache

A technical comparison of two fundamental on-chip memory architectures used in Neural Processing Units (NPUs) and other accelerators, highlighting their distinct management models, performance characteristics, and design trade-offs.

Feature / CharacteristicScratchpad Memory (SPM)Hardware-Managed Cache

Management Model

Explicitly managed by software (compiler/programmer)

Implicitly managed by hardware controller

Allocation & Placement

Deterministic; data location and lifetime are explicitly defined in code

Heuristic-based; uses replacement policies (e.g., LRU) and prefetchers

Access Latency

Predictable, constant low latency (single-cycle access typical)

Variable latency; depends on hit/miss status and coherence state

Access Guarantees

Guaranteed on-chip access if correctly programmed

No guarantee; data may be evicted, leading to off-chip misses

Hardware Overhead

Lower (simple SRAM arrays, address decoders, no tags/state logic)

Higher (tag arrays, state bits, replacement logic, coherence directories)

Bandwidth Utilization

Optimal when programmed correctly; enables precise data orchestration

Can suffer from bandwidth waste due to prefetch inaccuracies or conflict misses

Coherence Handling

Software's responsibility; requires explicit synchronization (e.g., barriers)

Hardware-enforced (e.g., MESI protocol); automatic for shared data

Best Use Case

Streaming, regular access patterns; kernels with known data lifetimes

Irregular, data-dependent access patterns; general-purpose workloads

Compiler Complexity

Higher; requires sophisticated analysis for data placement & movement

Lower; hardware abstracts complexity from the compiler

Power Efficiency

Higher for predictable workloads (no tag checks, minimal control logic)

Lower for predictable workloads (overhead of tag checks and miss handling)

SCRATCHPAD MEMORY

Primary Use Cases in AI Acceleration

Scratchpad memory (SPM) is a small, high-speed, software-managed on-chip memory used in accelerators like NPUs for explicit, low-latency storage of frequently accessed data, as opposed to hardware-managed caches. Its primary use cases center on predictable, high-performance data orchestration for compute-intensive AI workloads.

SCRATCHPAD MEMORY

Frequently Asked Questions

Scratchpad memory is a critical, software-managed component in hardware accelerators like Neural Processing Units (NPUs). This FAQ addresses common technical questions about its purpose, operation, and advantages over traditional caches.

Scratchpad memory is a small, high-speed, software-managed on-chip memory explicitly controlled by the programmer or compiler to store frequently accessed data for low-latency access, as opposed to a hardware-managed cache. In the context of Neural Processing Unit (NPU) acceleration, it is a key component of the memory hierarchy, sitting closer to the compute units than global DRAM (like High Bandwidth Memory (HBM)) to minimize the memory wall problem. Its management is a core aspect of Memory Hierarchy Management for maximizing data throughput and computational efficiency.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.