Inferensys

Glossary

Cache Coherence

Cache coherence is a hardware property that ensures all processors in a multi-core system have a consistent view of shared memory, preventing data corruption from stale cached copies.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
MEMORY HIERARCHY MANAGEMENT

What is Cache Coherence?

A fundamental property of multi-processor and accelerator systems ensuring data consistency across caches.

Cache coherence is a hardware-enforced property in a multi-processor system that guarantees all caches maintain a consistent view of shared memory, preventing different processors or cores from reading stale or conflicting values for the same memory location. It is managed through a coherence protocol (e.g., MESI, MOESI) that tracks the state of each cache line and orchestrates invalidations or updates across the system. This mechanism is critical for the correctness of parallel programs and is a foundational concern in systems with Non-Uniform Memory Access (NUMA) and accelerators like Neural Processing Units (NPUs).

In systems with dedicated accelerators, such as an NPU and a host CPU, maintaining coherence is complex. Many NPUs use scratchpad memory or non-coherent caches for maximum performance, requiring explicit software management via Direct Memory Access (DMA) and memory barriers. When coherence is required, as with Unified Memory or interconnects like Compute Express Link (CXL), it ensures that the NPU's computations operate on the most recent data written by the CPU, preventing subtle bugs like data races and false sharing that can corrupt model outputs or training data.

MEMORY HIERARCHY MANAGEMENT

Core Properties of Cache Coherence

Cache coherence protocols enforce a formal contract for data consistency in multi-processor systems. These core properties define the guarantees that must be upheld to prevent logical errors and ensure deterministic program execution.

01

Write Propagation

Write Propagation is the guarantee that a write operation to a shared memory location by one processor will eventually become visible to all other processors. This is the fundamental requirement that prevents different cores from operating on stale data. Without this property, a processor could compute using an outdated value, leading to incorrect results.

  • Mechanism: Achieved through protocols that broadcast write notifications (snooping) or track ownership (directory-based).
  • Eventual Consistency: The write may not be instantly visible globally, but the system guarantees it will propagate, typically on the next coherence transaction for that address.
02

Write Serialization (Atomicity)

Write Serialization ensures that all processors observe writes to the same memory location in the same sequential order. This property is critical for establishing a global timeline of modifications, which is necessary for implementing synchronization primitives like locks and barriers.

  • Global Order: If two processors, P1 and P2, write to address X, all other processors must agree on whether P1's write happened before P2's or vice-versa.
  • Foundation for Synchronization: This atomic ordering is what allows a test-and-set or compare-and-swap instruction to function correctly across multiple caches.
03

Coherence States (MESI & MOESI)

Cache lines are tracked using finite coherence states that define permissions and data freshness. The most common protocol is MESI (Modified, Exclusive, Shared, Invalid). An extension is MOESI, which adds an Owned state.

  • Modified (M): The cache line is dirty (modified) and is the only valid copy; must write back to memory before eviction.
  • Exclusive (E): The cache line is clean and is the only cached copy.
  • Shared (S): The cache line is clean and may be present in other caches.
  • Invalid (I): The cache line data is stale and cannot be used.
  • Owned (O) in MOESI: The cache line is dirty and responsible for supplying data to other caches, but does not have to write back immediately.
04

Snooping vs. Directory-Based Protocols

These are the two primary architectural approaches to implementing coherence.

  • Snooping (Bus-Based): All caches monitor (snoop) a shared broadcast interconnect (bus or network) for transactions. When a write is seen, caches invalidate or update their local copies. Simple but does not scale well to many cores due to broadcast traffic.
  • Directory-Based: A centralized or distributed directory tracks which caches hold copies of each memory block. On a write, only the caches listed in the directory are notified. This is scalable for large multi-processor systems (e.g., 64+ cores) as it uses point-to-point messages instead of broadcasts.
05

Memory Consistency vs. Cache Coherence

These are distinct but related concepts often conflated.

  • Cache Coherence: Defines the behavior of reads and writes to a single memory location. It answers: "When will a write by one core be seen by a read from another core for the same address?"
  • Memory Consistency: Defines the legal ordering of reads and writes to different memory locations across multiple processors. It answers: "Can a read of location Y see a new value before a read of location X sees its new value, even if X was written first?"
  • Relationship: Coherence is a necessary precondition for most useful consistency models (like Sequential Consistency). A system can be coherent but have a weak (relaxed) consistency model.
06

Coherence in Heterogeneous Systems (CPU+NPU)

Maintaining coherence between a host CPU and a dedicated accelerator like an NPU presents unique challenges. The goal is to allow both processors to work on the same data without explicit, software-managed cache flushes.

  • Hardware-Managed Coherence: Modern interconnects like CXL (Compute Express Link) and some proprietary NPU links support hardware cache coherence between the device and the CPU. The NPU's caches participate in the system's coherence domain.
  • Software-Managed Coherence: In many systems, the NPU operates in a separate, non-coherent memory space. The programmer must use explicit DMA transfers or CPU cache management instructions (e.g., flush, invalidate) to move data, which adds complexity and latency.
  • Unified Virtual Memory: Frameworks like CUDA provide a unified address space, but true hardware coherence is often limited to specific GPU architectures and memory types.
MEMORY HIERARCHY MANAGEMENT

How Cache Coherence Works

Cache coherence is the hardware mechanism that ensures all processors in a multi-core system have a consistent view of shared memory.

Cache coherence is a property of a shared-memory multiprocessor system where any read of a memory location returns the most recently written value to that location, regardless of which processor performed the write. This prevents different cores from seeing stale or conflicting data for the same address in their local caches. The primary challenge is maintaining this consistency without crippling performance, as writes by one processor must be communicated to all other caches holding a copy of that data. Coherence protocols, such as MESI (Modified, Exclusive, Shared, Invalid), manage this by tracking the state of each cache line and orchestrating invalidations or updates across the system.

Protocols operate by having each cache controller monitor or snoop a shared bus for transactions related to memory addresses it holds. On a write, the protocol invalidates shared copies in other caches, forcing subsequent reads to fetch the updated value. More advanced systems use directory-based coherence for scalability, where a central directory tracks which caches hold which lines. Coherence is distinct from, but interacts with, the memory consistency model, which defines the legal order in which memory operations become visible to different processors. Effective coherence is foundational for correct parallel execution and is a critical concern in systems with NPUs, GPUs, and multi-socket CPUs.

PROTOCOL ARCHITECTURES

Cache Coherence Protocol Comparison

A comparison of fundamental hardware-based cache coherence protocols, detailing their mechanisms, performance characteristics, and trade-offs for multi-processor and accelerator-based systems.

Protocol Feature / MetricSnooping (Bus-Based)Directory-BasedToken Coherence

Underlying Interconnect

Broadcast Bus or Ring

Point-to-point Network (e.g., Mesh)

Point-to-point Network

Coherence State Tracking

Distributed (in each cache)

Centralized Directory

Distributed Tokens

Scalability (Core Count)

Low to Medium (< ~32 cores)

High (Tens to Hundreds of cores)

High (Tens to Hundreds of cores)

Read Miss Latency (to shared data)

Medium (broadcast request)

Low to Medium (query directory)

Medium (request tokens)

Write Miss / Invalidate Latency

High (broadcast invalidates)

Medium (unicast invalidates)

Medium (unicast token requests)

Bandwidth Overhead on Shared Data

High (broadcasts all requests)

Low (unicasts to sharers only)

Medium (token request/transfer traffic)

Silicon Area Overhead

Low (per-cache tags only)

High (directory storage + logic)

Medium (per-cache token counters)

Example Implementations / Use Cases

Early multi-core CPUs, small embedded MPSoCs

Large-scale server CPUs (Intel Xeon, AMD EPYC), GPUs

Research prototypes, some academic many-core processors

MEMORY HIERARCHY MANAGEMENT

Cache Coherence in AI Accelerators & NPUs

Cache coherence is the property of a multi-processor system that ensures all caches have a consistent view of shared memory, preventing different processors from seeing stale or conflicting values for the same memory location. In AI accelerators, maintaining this consistency is critical for correct and efficient parallel execution.

01

The Core Problem: Stale Data

In a system with multiple processing cores, each with its own cache, a fundamental problem arises: multiple copies of the same data can exist. If Core A writes a new value to its local cache, Core B may still be reading the old, stale value from its own cache. Cache coherence protocols are the hardware mechanisms that solve this by ensuring all caches see a single, up-to-date view of memory. Without it, parallel programs would produce non-deterministic and incorrect results.

02

Coherence Protocols (MESI & MOESI)

These are the standard hardware protocols that track cache line states to manage coherence traffic efficiently.

  • MESI: Defines four states: Modified (dirty, exclusive), Exclusive (clean, exclusive), Shared (clean, possibly in other caches), Invalid. It's the foundation for most CPU coherence.
  • MOESI: Adds an Owned state to MESI. A cache line in Owned state is responsible for supplying data to other caches, reducing write-back traffic to main memory. This is common in AMD processors and many accelerator interconnects.

These protocols work by broadcasting snoop requests or using directory-based schemes to track which caches have copies of data.

03

The NPU/Accelerator Challenge

AI accelerators (NPUs, GPUs) introduce unique coherence challenges:

  • Heterogeneous Systems: The NPU is a separate device with its own memory hierarchy, often connected via a bus (e.g., PCIe, CXL). Maintaining coherence between the host CPU's caches and the NPU's caches is complex.
  • Massive Parallelism: Thousands of simple cores accessing memory simultaneously generate enormous potential for coherence traffic, which can become a performance bottleneck.
  • Scratchpad vs. Cache: Many NPUs use software-managed scratchpad memory (SRAM) instead of hardware caches. While this avoids coherence issues for that local memory, data moved between scratchpad and globally shared DRAM still requires coherence management.
04

Snooping vs. Directory-Based Coherence

These are the two primary architectural approaches to implementing coherence.

  • Snooping (Broadcast): Every cache controller monitors (snoops) a shared bus for transactions. If a transaction is for an address it holds, it takes appropriate action (e.g., invalidates its copy). Simple but doesn't scale well to many cores due to bus bandwidth limits.
  • Directory-Based: A central directory keeps track of which caches have copies of each memory block. On a write, only the caches listed in the directory are sent invalidation messages. This scales better for large many-core and heterogeneous systems (like CPU+NPU) but adds latency for directory lookups.
05

Coherent Interconnects (CXL & CCIX)

Modern interconnects are designed with accelerator coherence in mind.

  • Compute Express Link (CXL): An open standard that maintains memory coherence between the CPU and devices like NPUs, GPUs, and memory expanders over a PCIe physical layer. CXL.io provides I/O semantics, CXL.cache allows the device to cache host memory coherently, and CXL.mem allows the host to access device memory.
  • CCIX: A similar cache-coherent interconnect standard for accelerators. These protocols allow the NPU to access the CPU's memory directly and coherently, simplifying programming by enabling a unified memory address space without explicit software-managed data synchronization.
06

Software Implications & Best Practices

Understanding hardware coherence is essential for writing efficient code.

  • False Sharing: A major performance pitfall. Occurs when unrelated variables used by different cores reside on the same cache line. Writes by one core cause the entire line to be invalidated for others, generating useless coherence traffic. Mitigated by memory alignment and padding.
  • Memory Barriers/Fences: Instructions that enforce ordering of memory operations. Crucial when coherence and consistency are managed separately. They ensure that results of writes are visible to other cores in the required order.
  • Explicit Synchronization: Using atomic operations (like compare-and-swap) or locks, which rely on the underlying coherence protocol to ensure safe concurrent access to shared data.
CACHE COHERENCE

Frequently Asked Questions

Cache coherence is a fundamental property of multi-processor and accelerator-based systems, ensuring a consistent view of shared memory. This FAQ addresses common technical questions about its mechanisms, protocols, and role in modern AI hardware.

Cache coherence is a property of a multi-processor or multi-core system that guarantees all caches have a consistent view of shared memory, preventing different processing units from seeing stale or conflicting values for the same memory location. It is critically important because without it, parallel programs would produce non-deterministic, incorrect results due to data races and visibility issues. In systems with Neural Processing Units (NPUs) and CPUs working on the same data, coherence protocols are essential for correct and efficient execution of heterogeneous workloads.

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.