Abstract
Managing data layouts is a critical yet complex task in heterogeneous computing, where CPUs and GPUs favor different memory organizations. This paper introduces ADHA (Automatic Data layout framework for Heterogeneous Architectures), a two-level compiler framework that automates layout selection. By utilizing affinity graphs for local optimization and shortest-path algorithms for global program optimization, ADHA identifies optimal configurations, including hybrid layouts and strategic data remapping. Evaluation on medical imaging and clustering benchmarks demonstrates performance gains of up to 6.92×, significantly enhancing developer productivity and system performance.
Introduction
In modern heterogeneous computing environments, achieving peak performance requires balancing the architectural nuances of CPUs and GPUs. A pivotal factor in this balance is the data layout—the organization of data in memory. CPUs typically benefit from an Array of Structures (AoS) due to cache locality, whereas GPUs require a Structure of Arrays (SoA) to facilitate memory coalescing.
Currently, developers must manually select layouts and refactor code for each hardware target. As the complexity of data structures and the number of parallel kernels grow, the search space for the optimal layout becomes exponentially large, making manual optimization impractical. ADHA addresses this by providing an automated framework for layout selection and implementation.
The ADHA Framework
ADHA employs a hierarchical approach to navigate the layout optimization space:
1. Lower Level: Optimal Data-layout of a Section (ODS)
This level optimizes individual code regions or "sections." It constructs an affinity graph where nodes represent data fields and edge weights reflect the frequency of co-access. A greedy clustering algorithm then groups these fields into structures based on the target architecture's specific constraints, such as cache size and memory hierarchy. This process can result in hybrid layouts like AoSU or AoSV, which combine elements of both AoS and SoA.
2. Higher Level: Program Data-Layout (PDL)
The higher level considers the global program structure. It represents the program as a directed acyclic graph (DAG) of code sections. Edges in this graph represent the costs associated with either maintaining a layout ("combining") or transforming it ("remapping") between sections. ADHA uses a shortest-path algorithm to determine the globally optimal sequence of layouts, balancing the benefits of specialized layouts against the overhead of data conversion.
The framework is integrated into the Heterogeneous Habanero-C (H2C) system, which translates high-level parallel loops into optimized OpenCL code.
Experimental Evaluation
The researchers evaluated ADHA using two primary benchmarks:
- Medical Image Registration: A complex benchmark with 7 sections and 6 data fields.
- K-Means Clustering: A data-intensive benchmark with 2 sections and 32 data fields.
Testing was conducted on a heterogeneous system comprising an Intel X5660 CPU and an NVIDIA Tesla M2050 GPU.
Key Results and Discussion
ADHA demonstrated significant performance improvements by automating layout decisions that are often counter-intuitive to manual optimization.
Performance Gains
In the K-Means benchmark, ADHA achieved a 6.92× speedup on the CPU. The framework identified that a combined AoS layout drastically reduced cache misses compared to the standard SoA layout. For the Medical Image Registration benchmark, a 1.34× speedup was achieved. This was accomplished by mapping control-flow-heavy sections to the CPU and vectorizable sections to the GPU, while strategically remapping data between them.
The Remapping Trade-off
A core insight of ADHA is the "Remapping Trade-off." The framework recognizes that the optimal global strategy may involve changing data layouts mid-execution. If the performance gain from using a GPU-optimized layout (SoA) in a kernel exceeds the time spent reordering memory from a CPU-optimized layout (AoS), ADHA will automatically insert the necessary remapping code.
Conclusion and Future Work
ADHA successfully automates the complex task of data layout optimization for heterogeneous systems, providing substantial speedups while reducing developer burden. Future work aims to expand the variety of supported layouts (e.g., multi-dimensional tiling), automate the initial CPU/GPU task mapping (currently guided by tuning profiles), and validate the framework on a broader range of hardware, such as FPGAs and DSPs.
Summary updated