Pearl: Automatic Code Optimization Using Deep Reinforcement Learning
Djamel Rassem Lamouri, Iheb Nassim Aouadj, Smail Kourta, Riyadh Baghdadi · 2025
Compilers are crucial in optimizing programs and accelerating their execution, particularly for compute-intensive tasks such as training deep learning models and conducting physics simulations.However, optimizing programs automatically using compilers is not trivial.Recent work has attempted to use reinforcement learning (RL) to solve this problem.It has limitations though.Current methods either do not support the optimization of general loop nests or can only be used to optimize loop nests seen during training.In this paper, we propose Pearl, a novel framework that uses deep reinforcement learning to automate compiler code optimization.It uses an RL agent to select the sequence of code optimizations a compiler should apply to make the input code run faster.This agent can optimize general loop nests (i.e., it is not domain-specific) and can generalize to programs unseen during training.To enable the optimization of general loop nests, we propose a novel representation of the action space that allows the RL agent to select on which part of the loop nest a given code optimization should be applied.One of the main challenges that hinder the development of RL agents for optimizing general loop nests is the fact that this task is data-intensive, with each experiment taking weeks.To avoid this problem and enable fast