Home

Awesome

CompilerGym

<p align="center"> <!-- Getting started colab --> <a href="https://colab.research.google.com/github/facebookresearch/CompilerGym/blob/stable/examples/getting-started.ipynb"> <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Colab" height="20"> </a> <!-- Supported python versions list --> <a href="https://pypi.org/project/compiler-gym/"> <img src="https://img.shields.io/pypi/pyversions/compiler-gym" alt="Python versions" height="20"> </a> <!-- Downloads counter --> <a href="https://pypi.org/project/compiler-gym/"> <img src="https://pepy.tech/badge/compiler-gym" alt="PyPi Downloads" height="20"> </a> <!-- PyPi Version --> <a href="https://pypi.org/project/compiler-gym/"> <img src="https://badge.fury.io/py/compiler-gym.svg" alt="PyPI version" height="20"> </a> <!-- license --> <a href="https://tldrlegal.com/license/mit-license"> <img src="https://img.shields.io/pypi/l/compiler-gym" alt="License" height="20"> </a> <!-- CI status --> <a href="https://github.com/facebookresearch/CompilerGym/actions?query=workflow%3ACI+branch%3Adevelopment"> <img src="https://github.com/facebookresearch/CompilerGym/workflows/CI/badge.svg?branch=development" alt="CI status" height="20"> </a> </p> <p align="center"> <i>Reinforcement learning environments for compiler optimization tasks.</i> </p> <p align="center"> <i> Check <a href="http://facebookresearch.github.io/CompilerGym/">the website</a> for more information. </i> </p>

Introduction

CompilerGym is a library of easy to use and performant reinforcement learning environments for compiler tasks. It allows ML researchers to interact with important compiler optimization problems in a language and vocabulary with which they are comfortable, and provides a toolkit for systems developers to expose new compiler tasks for ML research. We aim to act as a catalyst for making compilers faster using ML. Key features include:

For a glimpse of what's to come, check out our roadmap.

News

Installation

Install the latest CompilerGym release using:

pip install -U compiler_gym

See INSTALL.md for further details.

Usage

Starting with CompilerGym is simple. If you not already familiar with the gym interface, refer to the getting started guide for an overview of the key concepts.

In Python, import compiler_gym to use the environments:

>>> import compiler_gym                      # imports the CompilerGym environments
>>> env = compiler_gym.make(                 # creates a new environment (same as gym.make)
...     "llvm-v0",                           # selects the compiler to use
...     benchmark="cbench-v1/qsort",         # selects the program to compile
...     observation_space="Autophase",       # selects the observation space
...     reward_space="IrInstructionCountOz", # selects the optimization target
... )
>>> env.reset()                              # starts a new compilation session
>>> env.render()                             # prints the IR of the program
>>> env.step(env.action_space.sample())      # applies a random optimization, updates state/reward/actions
>>> env.close()                              # closes the environment, freeing resources

See the examples directory for agent implementations, environment extensions, and more. See the documentation website for the API reference.

Leaderboards

These leaderboards track the performance of user-submitted algorithms for CompilerGym tasks. To submit a result please see this document.

LLVM Instruction Count

LLVM is a popular open source compiler used widely in industry and research. The llvm-ic-v0 environment exposes LLVM's optimizing passes as a set of actions that can be applied to a particular program. The goal of the agent is to select the sequence of optimizations that lead to the greatest reduction in instruction count in the program being compiled. Reward is the reduction in instruction count achieved scaled to the reduction achieved by LLVM's builtin -Oz pipeline.

This leaderboard tracks the results achieved by algorithms on the llvm-ic-v0 environment on the 23 benchmarks in the cbench-v1 dataset.

AuthorAlgorithmLinksDateWalltime (mean)Codesize Reduction (geomean)
Robin Schmöcker, Yannik Mahlau, Nicolas FröhlichPPO + Guided Searchwrite-up, results2022-0269.821s1.070×
FacebookRandom search (t=10800)write-up, results2021-0310,512.356s1.062×
FacebookRandom search (t=3600)write-up, results2021-033,630.821s1.061×
FacebookGreedy searchwrite-up, results2021-03169.237s1.055×
Anthony. W. JungGATv2 + DD-PPOwrite-up, results2022-06258.149s1.047×
FacebookRandom search (t=60)write-up, results2021-0391.215s1.045×
Facebooke-Greedy search (e=0.1)write-up, results2021-03351.611s1.041×
Jiadong GuoTabular Q (N=5000, H=10)write-up, results2021-042534.3051.036×
FacebookRandom search (t=10)write-up, results2021-0342.939s1.031×
Patrick HesseDQN (N=4000, H=10)write-up, results2021-0691.018s1.029×
Jiadong GuoTabular Q (N=2000, H=5)write-up, results2021-04694.1050.988×

Contributing

We welcome contributions to CompilerGym. If you are interested in contributing please see this document.

Citation

If you use CompilerGym in any of your work, please cite our paper:

@inproceedings{CompilerGym,
      title={{CompilerGym: Robust, Performant Compiler Optimization Environments for AI Research}},
      author={Chris Cummins and Bram Wasti and Jiadong Guo and Brandon Cui and Jason Ansel and Sahir Gomez and Somya Jain and Jia Liu and Olivier Teytaud and Benoit Steiner and Yuandong Tian and Hugh Leather},
      booktitle={CGO},
      year={2022},
}