TL;DR
This paper introduces a novel compiler-based technique for "array regrouping," a performance optimization that rearranges data in memory to improve cache utilization. Their method, "frequency-based affinity analysis," achieves significant performance gains comparable to costly profiling methods, without requiring any runtime instrumentation.
What Problem Does This Paper Address?
Modern high-performance computing relies heavily on efficient data access. As processors become faster, the speed at which they can fetch data from memory (memory bandwidth and latency) becomes a major bottleneck. Scientific programs, in particular, often deal with massive datasets stored in arrays. When multiple arrays are accessed together but stored far apart in memory, it leads to poor cache utilization. This means that when data is brought into the cache, a large portion of it might be unused, wasting precious cache space and increasing the number of times the processor has to wait for data from slower memory levels.
Previous solutions for improving this "spatial locality" involved techniques like array regrouping, which aims to store data that is frequently accessed together in contiguous memory locations. However, the most effective methods for determining which arrays to group required detailed profiling of program execution, which is expensive and can significantly slow down the program. This paper addresses the need for an efficient, compiler-only approach to array regrouping that can achieve similar performance benefits without the overhead of runtime profiling.
Methods
The core contribution of this paper is the frequency-based affinity analysis technique. This method aims to group arrays that are likely to be accessed together by analyzing their "access patterns" statically, i.e., at compile time. Here's a breakdown of their approach:
- Frequency-Based Affinity Model: Instead of just looking at whether arrays are always accessed together (conservative analysis), this model considers how frequently they are accessed together. It uses "access-frequency vectors" for each array, where each element in the vector represents the frequency of access to that array within a specific "code unit" (primarily loops).
- Code Units: Loops are chosen as the primary code units because they often access large portions of arrays, are relatively independent in terms of their execution order, and are efficient to analyze.
- Interprocedural Analysis: To handle complex programs with function calls and parameter arrays, they employ a context-sensitive interprocedural analysis. This means the analysis considers how procedures are called and how data flows between them, allowing for more accurate frequency estimations even when arrays are passed as parameters.
- Affinity Graph and Partitioning: Arrays are represented as nodes in a graph, and the "affinity" (how likely they are to be accessed together) between pairs of arrays is represented as edge weights. This graph is then partitioned to identify groups of arrays that should be regrouped.
- Two Frequency Estimation Methods:
- Static Analysis: This method uses compiler techniques like control flow graph analysis, constant propagation, and symbolic analysis to estimate loop execution frequencies. It makes conservative assumptions about branches (e.g., assuming both paths are taken).
- Lightweight Profiling: This involves instrumenting the code to count actual execution frequencies. While more accurate than static analysis, it still incurs some overhead, though significantly less than previous trace-level profiling.
The key novelty lies in combining the frequency-based model with a context-sensitive interprocedural analysis that can be performed entirely at compile time.
Datasets
The authors evaluated their approach on a set of benchmarks:
- SPEC CPU2000 FORTRAN benchmarks: Eight programs from this suite were used.
- Three additional FORTRAN programs: These were previously used in distance-based affinity analysis studies.
These benchmarks represent scientific simulations in areas like quantum physics, meteorology, fluid dynamics, and molecular dynamics, which are representative of the types of programs that would benefit from array regrouping.
Key Insights and Ideas
- Compile-time analysis is sufficient: The most striking insight is that a purely compiler-based analysis, without any runtime profiling, can achieve performance improvements comparable to or even better than methods that rely on expensive profiling. This makes the optimization much more practical for widespread adoption.
- Frequency matters more than absolute co-occurrence: Moving beyond conservative "always accessed together" rules to a frequency-based approach allows for more aggressive and beneficial regrouping, especially for arrays that are sporadically accessed together.
- Interprocedural analysis is crucial: For realistic scientific programs, data access patterns are often spread across multiple procedures and involve parameter arrays. A context-sensitive interprocedural analysis is essential to accurately capture these complex relationships.
- Loops are ideal analysis units: The choice of loops as the primary unit for frequency counting is well-justified by their coverage, independence, and efficiency.
- Array regrouping benefits even contiguous access: The paper notes that array regrouping can still offer benefits even for arrays that are already contiguously accessed, by reducing cache interference and improving TLB misses.
Key Results
- Performance Improvement: Array regrouping, using their frequency-based compiler analysis, improved performance for the majority of the tested programs.
- Comparison with Profiling: The pure compiler-based array regrouping performed as well as, and sometimes better than, distance-based profiling methods on both IBM and Intel architectures. For example, on the IBM POWER4, array regrouping achieved over 10% improvement on Swim2K, Swim95, and Tomcatv at the "-O5" optimization level. At "-O3", the improvements were even more significant.
- Low Overhead: The static analysis method incurs minimal overhead, and even the lightweight profiling method is significantly less costly than previous trace-level profiling.
- Insensitivity to Threshold: The choice of the affinity threshold for grouping arrays was found to be relatively insensitive, with a wide range yielding the same affinity groups.
Limitations and Future Work
- Aliasing: The paper acknowledges that aliasing (where different names can refer to the same memory location) is a challenge, particularly with storage association in FORTRAN. Their current analysis primarily considers parameter passing aliasing.
- Pointer-based Control Flow: The invocation graph construction excludes pointer-based control flow, which is not a significant issue for FORTRAN but could be a limitation for other languages.
- Semi-automated Transformations: While the analysis identifies groups, the actual array transformations are semi-automated, indicating that full integration into the compiler's transformation pipeline requires further work.
- Future Work: The authors mention future work on splitting large arrays into smaller pieces to improve affinity, and investigating the possibility of performing array regrouping later in the compilation process, after loop transformations have been applied. They also note the anomaly of Applu running slower on the Intel machine and are investigating the reasons.
Summary updated