A Metaprogramming and Autotuning Framework for Deploying Deep Learning Applications

Matthew W. Moskewicz, Ali Jannesari, Kurt KeutzerarXiv 2016

Introduction

The rapid evolution of deep learning has created a "portability vs. performance" crisis. High-performance GPU programming typically requires "ninja-level" engineering to manually manage loop unrolling, register blocking, and complex memory hierarchies. Consequently, developers are often locked into specific ecosystems, such as NVIDIA’s cuDNN, because vendor-specific libraries are the only way to achieve necessary performance.

To address this, researchers from UC Berkeley introduced Boda, a framework that leverages C++-based metaprogramming and automated autotuning to generate high-efficiency GPU code. Boda allows for portable deployment across diverse hardware—including AMD and mobile Qualcomm GPUs—while remaining competitive with hand-optimized vendor libraries.

The Boda Framework

Boda is designed to bridge the gap between popular neural network front-ends and a variety of target back-ends. By focusing on a small set of computationally critical operations, such as convolutions, it avoids the complexity of a general-purpose compiler while delivering specialized performance.

Boda acts as a bridge between various neural network front-ends and diverse hardware back-ends.

Core Methodology

The framework employs several key technical strategies to achieve its goals:

  • CUCL (Common Unified Compute Language): A C-like syntax representing the intersection of CUDA and OpenCL, allowing core logic to be written once for multiple APIs.
  • Metaprogramming: Boda uses C++ "metacode" to generate final GPU kernels. By knowing input dimensions (e.g., image size, channel count) at code-generation time, Boda "bakes" these values into the code as constants. This enables the underlying GPU compiler to perform aggressive optimizations like perfect loop unrolling.
  • Autotuning: Because optimal configurations (thread block sizes, vector widths) are hardware-dependent, Boda includes an autotuner that searches for the best parameters for the specific chip in use.
  • Graph-Level Optimizations: The framework automatically performs "kernel fusion," combining operations like convolution and ReLU activation into a single pass to minimize memory bandwidth usage.
Internal components of the Boda framework, including autotuning and code generation.

Evaluation and Results

The researchers evaluated Boda using a benchmark set of convolution operations extracted from landmark networks: AlexNet, Network-in-Network (NiN), and Inception (v1). They focused on unique layers with a batch size of 5 to simulate streaming deployment scenarios.

Performance Benchmarks

  • NVIDIA Hardware: Boda achieved performance competitive with cuDNN v5. While it lagged in 3x3 convolutions (where cuDNN uses specialized Winograd algorithms), it was occasionally faster in other configurations.
  • Mobile Deployment: On the Qualcomm Snapdragon 820 (Adreno 530 GPU), autotuning provided a 10x speedup over unoptimized code, reaching production-level performance with minimal manual effort.
  • AMD Portability: On the AMD R9-Nano, the framework improved performance with zero manual code changes, demonstrating true performance portability.

Key Insights and Future Work

A primary takeaway is the "Power of Constants": GPU compilers are significantly more effective when loop bounds and array indices are hard-coded via metaprogramming. Furthermore, the results suggest that the choice of API (OpenCL vs. CUDA) is less critical than the quality of the generated code and the effectiveness of autotuning.

Future work for Boda includes implementing algorithmic optimizations like Winograd or FFT-based convolutions for small filters and exploring more advanced autotuning search strategies, such as genetic algorithms or machine learning, to navigate larger parameter spaces more efficiently.

Summary updated

BibTeX
@misc{moskewicz2016metaprogramming,
  author = {Matthew W. Moskewicz and Ali Jannesari and Kurt Keutzer},
  title = {{A Metaprogramming and Autotuning Framework for Deploying Deep Learning Applications}},
  year = {2016},
  eprint = {1611.06945},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1611.06945},
}
Figure