liveBook · Manning

Data-reuse test

As explained in Grokking GPU Programming

The data-reuse test is a criterion for deciding whether a kernel benefits from shared memory based on whether data is read repeatedly.

Before using shared memory, ask whether the same data is read repeatedly—by one thread or by multiple threads. If not, shared memory adds overhead without capturing reuse. section 11.4

Use the test as a guide, not a guarantee:

  • A pure element-wise map, such as out[i] = in[i] * 2, reads each element once; shared memory offers no reuse to capture. section 11.4
  • Repeated reads can make staging worthwhile, but shared-memory use may still lose if it reduces occupancy. Some kernels without reuse may benefit for another reason, such as improved coalescing. section 11.4

Overlapping convolution windows

When one thread computes neighboring outputs in a 1D convolution, it may reread overlapping input values. Staging the input window in shared memory can let it fetch each value from global memory once and reuse it on-chip. section 11.4

How Grokking GPU Programming covers it

How deep it goes
Distinguishes same-thread and cross-thread reuse, then notes occupancy and coalescing exceptions.
Examples
Uses an element-wise map and overlapping 1D convolution windows to contrast absent and present reuse.
What you can do after
Evaluate whether repeated reads could justify shared-memory staging, while accounting for overhead and exceptions.
How it connects
Connects shared memory with global memory, occupancy, convolution, and memory coalescing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.