﻿# GPU L2 reuse: a cache policy is attached to an access pattern

Cache retention policies help a measured reusable working set; oversized windows and competing streams can defeat the intended persistence benefit.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-l2-cache-access-window/
Language: en

Some GPU workloads repeatedly read a small useful region while streaming through much larger arrays. NVIDIA cache access policies can express a preference for retaining that reusable region in part of the cache on supported devices. This is a hint within a constrained hardware resource, not a private memory allocation with guaranteed residence for every byte.

## Identify reuse before requesting persistence

A cache policy cannot create reuse that the algorithm does not have. Consider a kernel that repeatedly reads a lookup table while scanning a large input. The table is a plausible candidate for preferential retention; the scan is not. Establish the access pattern from the algorithm and measurements. Applying a persistence preference to the entire input can merely increase competition for the same finite cache space.

Primary reference: [CUDA Programming Guide: L2 Cache Control](https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/l2-cache-control.html).

## An access window describes a preference

An access-policy window identifies an address range and policies for accesses associated with the configured stream or graph node. The device still manages actual cache contents. Capacity, replacement behavior, and competing accesses influence the result. Do not make correctness depend on a line remaining resident. A program must return identical valid results when data misses in the cache and is fetched through the ordinary memory hierarchy instead.

Primary reference: [CUDA C++ Best Practices Guide](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/).

## Several streams share the underlying capacity

Independent streams can each describe a desirable cache window while their combined reusable data exceeds the available persistence resource. An isolated benchmark may therefore look favorable and a concurrent service may not. Test representative coexistence, including kernels that scan unrelated allocations. Tune the retained fraction and window size with the aggregate working set in mind. A stream-level configuration does not mean a stream owns a physically isolated cache.

Primary reference: [Nsight Compute Profiling Guide](https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html).

## Reset a policy whose useful phase has ended

A region that was reusable during one phase may become irrelevant in the next. Retaining an outdated preference can interfere with later work. Make policy lifetime visible in the application structure and restore ordinary behavior when the reusable phase finishes. This is particularly relevant in libraries reused by unrelated callers: a local optimization should not silently leave a lasting cache preference for future requests with different allocations and access patterns.

## A hit-rate improvement needs an end-to-end result

Measure total kernel time and useful memory traffic alongside cache metrics. A better hit rate can coexist with negligible application improvement when arithmetic or synchronization dominates. Warm and cold conditions should be explicit, because a repeated microbenchmark can exaggerate reuse. Keep an unmodified policy baseline and vary only the candidate window. The strongest explanation connects an identifiable reusable region to reduced relevant memory stalls and improved completion time.

Related reading: [A GPU inference benchmark you can trust](/journal/inference-benchmark-method/); [Reproducible inference stacks: preserving a GPU pilot’s result](/journal/software-stack-reproducibility/).
