Automating Energy-Efficient GPU Kernel Generation: A Fast Search-Based Compilation Approach

Yijia Zhang, Zhihong Gou, Shijie Cao, Weigang Feng, Sicheng Zhang, Guohao Dai, Ningyi XuarXiv 2024

Abstract

Deep Neural Networks (DNNs) have revolutionized various fields, but their deployment on GPUs often leads to significant energy consumption. Unlike existing methods for reducing GPU energy consumption, which are either hardware-inflexible or limited by workload constraints, this paper addresses the problem at the GPU kernel level. We propose a novel search-based compilation method to generate energy-efficient GPU kernels by incorporating energy efficiency into the search process. To accelerate the energy evaluation process, we develop an accurate energy cost model based on high-level kernel features. Furthermore, we introduce a dynamic updating strategy for the energy cost model, reducing the need for on-device energy measurements and accelerating the search process. Our evaluation demonstrates that the proposed approach can generate GPU kernels with up to 21.69% reduced energy consumption while maintaining low latency.

Introduction

As Deep Neural Networks (DNNs) scale to massive sizes, such as LLaMA-3 or GPT-4, the energy required for training and deployment has become a critical bottleneck. Beyond the rising cost of electricity, the power demand from massive GPU clusters can overwhelm local power grids.

Current solutions to this "energy crisis" typically occur at the hardware level (e.g., power capping) or the workload level (e.g., adjusting batch sizes). However, these approaches are often inflexible. This research focuses on the GPU kernel level. A kernel is a small program performing specific mathematical operations, like matrix multiplication. While existing automated compilers like Ansor or TVM search for the fastest possible kernels, they often ignore power draw. This paper demonstrates that two kernels with nearly identical execution speeds can have significantly different energy footprints.

Methodology

The proposed framework integrates energy awareness directly into the automated search process through three primary components:

  1. Energy-Aware Search Process: Utilizing a genetic algorithm, the compiler filters for low-latency candidates and then selects the most energy-efficient individuals among them to "reproduce" for subsequent generations.
  2. Machine-Learning Energy Cost Model: Physical energy measurement via NVIDIA’s NVML API is slow due to low sampling frequencies. To bypass this, we developed an XGBoost-based cost model that predicts energy consumption using high-level kernel features such as floating-point operations, loop depth, and cache access patterns.
  3. Dynamic Online Updating Strategy: To handle novel kernel configurations encountered during the search, the system monitors prediction errors. If accuracy drops, it triggers a small number of real-world measurements to retrain and correct the model on the fly.
Overview of the energy-aware search-based compilation framework.

Key Insights

  • Power-Latency Dynamics: Higher latency often correlates with lower average power. However, since energy is the product of power and time, slow kernels can still be inefficient. The goal is to find the "sweet spot" where hardware resources are utilized efficiently without sacrificing speed.
  • Static Energy and Grid Size: Reducing the grid size (active thread blocks) can save significant energy. By utilizing fewer Streaming Multiprocessors (SMs) more effectively and allowing others to idle, static energy consumption is reduced without necessarily slowing down computation.
  • Memory Reuse: Larger block sizes facilitate better data reuse within shared memory, reducing expensive global memory transactions which can account for over half of a kernel's dynamic power consumption.

Evaluation and Results

The framework was evaluated using standard operators (Matrix Multiplication, Matrix-Vector Multiplication, and Convolution) on NVIDIA A100 and RTX 4090 architectures.

Comparison of energy and latency for kernels generated by Ansor versus the proposed energy-efficient approach.
  • Energy Savings: On the NVIDIA A100, the method achieved an average energy reduction of 7.47%, peaking at 21.69%. On the RTX 4090, energy reductions for Matrix-Vector (MV) operators exceeded 50%.
  • Search Efficiency: The predictive cost model makes the search process approximately 2x faster than a naive search relying solely on physical measurements.
  • Performance Neutrality: Crucially, these savings did not compromise performance. In several instances, the energy-aware search discovered kernels that were actually faster than those found by the baseline Ansor compiler.

Conclusion

While the proposed automated kernels significantly outperform existing compilers, a gap remains when compared to hand-tuned libraries like cuBLAS, which remains roughly 10% more efficient in certain scenarios. Future work will explore using these manual kernels as an "initial population" for the search algorithm to bridge the gap between automated flexibility and peak manual performance.

Summary updated

BibTeX
@misc{zhang2024automating,
  author = {Yijia Zhang and Zhihong Gou and Shijie Cao and Weigang Feng and Sicheng Zhang and Guohao Dai and Ningyi Xu},
  title = {{Automating Energy-Efficient GPU Kernel Generation: A Fast Search-Based Compilation Approach}},
  year = {2024},
  eprint = {2411.18873},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.18873},
}
Figure