One stone two birds: synchronization relaxation and redundancy removal in GPU-CPU translation

Ziyu Guo, Bo Wu, Xipeng ShenICS 2012

TL;DR

This paper introduces a novel approach to translate GPU programs to CPU code, addressing two major sources of inefficiency: overly strong synchronizations and thread-level partial redundancy. By analyzing dynamic instruction instances rather than static code, their method achieves significant speedups, up to 14x, on various benchmarks.

What Problem Does This Paper Address?

Heterogeneous computing systems, combining CPUs and GPUs, offer immense processing power. However, efficiently running GPU-optimized code on a CPU presents challenges. This paper focuses on two key problems in translating fine-grained SPMD (Single Program, Multiple Data) GPU code (like CUDA) to CPU code:

  1. Overly Strong Synchronizations: GPU programs often use barriers for synchronization due to their massive parallelism and difficulty with fine-grained locking. When translated to CPU, these barriers become unnecessarily restrictive, forcing sequential execution where parallelism could exist.
  2. Thread-Level Partial Redundancy: In GPU programs, some threads might perform computations that are not strictly necessary for the final result, but are tolerated due to GPU's parallel nature. When these "useless" computations are translated to CPU, they can significantly degrade performance.

Existing GPU-CPU translators often fail to address these issues effectively, leading to inefficient CPU code.

Methods

The authors propose a unified solution based on a Thread-Level Dependence Graph (TLDG). Unlike traditional program dependence graphs that operate on static statements, TLDGs model dynamic instances of instructions executed by each thread. This fine-grained, instance-level analysis is the core of their approach.

Key techniques include:

  • Thread-Level Dependence Graphs (TLDG): Nodes represent individual instruction instances, and edges capture control and data dependencies between them. This allows for a detailed view of thread interactions and computations.
  • Instance-Level Instruction Scheduling: Instead of loop fission (a common but inefficient translation technique), they schedule instruction instances directly from the TLDG. This relaxes overly strong synchronizations by ensuring dependencies are met without unnecessary barriers. They propose three scheduling algorithms:
  • Breadth-First Scheduling: Prioritizes nodes at the same "level" across threads, aiming for good spatial locality.
  • Depth-First Scheduling: Focuses on intra-thread data reuse, trying to schedule nodes from the same thread consecutively.
  • Length-First Scheduling: Selects nodes along the longest uninterrupted path in the TLDG, aiming for temporal data locality.
  • Code Shape Optimization: Identifies and exploits repetitive subgraph patterns in the TLDG to reduce the size of the generated CPU code by using loops.
  • Thread Partial Redundancy Removal: Detects and removes "useless" instruction instances (nodes in the TLDG) that are not on a path to a useful output, effectively pruning unnecessary computations before scheduling.

Datasets

The evaluation uses five CUDA programs:

  • Reduction: From NVIDIA CUDA SDK.
  • Transpose: From NVIDIA CUDA SDK.
  • SortingNetworks: From NVIDIA CUDA SDK.
  • CG (Conjugate Gradient): From NPB benchmark suite.
  • Nw (Needleman-Wunsch): From the Rodinia benchmark suite.

These benchmarks were chosen for their representative GPU program features, including non-trivial synchronizations and thread partial redundancy. No new benchmarks were introduced.

Key Insights and Ideas

  • Unified Solution for Two Problems: The core insight is that both overly strong synchronizations and thread-level partial redundancy stem from the same underlying cause: non-uniformity among GPU threads. This realization enables a single, unified framework (TLDG) to tackle both issues.
  • Instance-Level Analysis is Crucial: Moving from static statement analysis to dynamic instruction instance analysis is key to accurately capturing thread behavior and dependencies, which is essential for both synchronization relaxation and redundancy removal.
  • TLDG as a Powerful Representation: The TLDG provides a detailed, yet manageable, representation of GPU kernel execution that is amenable to sophisticated optimizations not possible with traditional program analysis techniques.
  • Avoiding Loop Fission: The proposed instance-level scheduling directly addresses the inefficiencies introduced by loop fission, a common but suboptimal translation strategy.

Key Results

The TLDG-based approach, particularly when combined with thread partial redundancy removal and the length-first scheduling algorithm, consistently outperforms existing state-of-the-art GPU-CPU translation methods (like MCUDA with statement-level analysis and loop fission).

  • Speedup: Achieved speedups ranging from 1.9x to 14.2x on four out of five benchmarks (Reduction, CG, SortingNetworks, Nw).
  • Code Size Reduction: The code shape optimization demonstrated a two-fold reduction in code size for the SortingNetworks benchmark, without impacting performance due to large CPU instruction caches.
  • Performance Trade-offs: While the TLDG-based methods generally excel, they showed a slight slowdown on the "Transpose" benchmark, which has very few memory references and no redundant computations. The authors suggest that for such small kernels, the overhead of TLDG analysis might outweigh the benefits.

Limitations and Future Work

  • Overhead on Small Kernels: The TLDG-based analysis and scheduling introduce some overhead, which can lead to a slight performance degradation on very small or simple kernels with minimal redundancy or synchronization needs.
  • Future Work: The authors suggest that the instance-level analysis framework opens up many other opportunities for program optimizations in heterogeneous computing systems. They also note that the code shape optimization's benefits might be more prominent on mobile CPUs with smaller instruction caches.

Summary updated

BibTeX
@inproceedings{guo2012one,
  author = {Ziyu Guo and Bo Wu and Xipeng Shen},
  title = {{One stone two birds: synchronization relaxation and redundancy removal in GPU-CPU translation}},
  booktitle = {ICS},
  year = {2012},
  doi = {10.1145/2304576.2304583},
}
Figure