6.5. Utilize Reuse Opportunities
Basically there are two variants of unused reuse opportunities that
the Freja tools detect: reuse within a loop, and reuse between
different loops. The former is addressed by applying a technique
called blocking or tiling, and the latter is handled by bringing the
two loops closer together or actually merging the loop bodies
completely.
Reuse come in two distinct flavors: spatial reuse, where the benefit
comes from that subsequent data is already fetched into the cache,
and temporal reuse, where the very same data is revisited multiple
times. Minimizing the time before the revisit will lower miss ratios.
Addressing these issues will usually cause loop hierarchies to be
partially turned around and broken up. Loop fusion will also
necessarily change the features of the program. This changed scene
should be re-analyzed for unnecessary memory accesses, poor layout
and poor access patterns.
| Tip |
---|
Bring related loops closer together, and optimally merge related
parts of their loop bodies. |
| Tip |
---|
Look for spatial reuse, and change loop nesting or block with respect
to the data structure that displays long reuse distance. |
| Tip |
---|
Look for temporal reuse, and change algorithms to perform as many
iterations as possible for a given data chunk before moving
along. |
| Tip |
---|
After merging loop bodies or transforming loop structures, rerun
analysis to find advice for the new program structure. |