Reinforcement learning environments for compiler research
Project description
CompilerGym is a toolkit for exposing compiler optimization problems for reinforcement learning. It allows machine learning researchers to experiment with program optimization techniques without requiring any experience in compilers, and provides a framework for compiler developers to expose new optimization problems for AI.
Table of Contents
Getting Started
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.
Installation
Install the latest CompilerGym release using:
$ pip install compiler_gym
The binary works on macOS and Linux (on Ubuntu 18.04, Fedora 28, Debian 10 or newer equivalents).
Building from Source
If you prefer, you may build from source. This requires a modern C++ toolchain. On macOS you can use the system compiler. On linux, install the required toolchain using:
$ sudo apt install clang libtinfo5 patchelf
$ export CC=clang
$ export CXX=clang++
We recommend using conda to manage the remaining build dependencies. First create a conda environment with the required dependencies:
$ conda create -n compiler_gym python=3.8 bazel=3.1.0 cmake pandoc
$ conda activate compiler_gym
Then clone the CompilerGym source code using:
$ git clone https://github.com/facebookresearch/CompilerGym.git
$ cd CompilerGym
Install the python development dependencies using:
$ make init
Then run the test suite to confirm that everything is working:
$ make test
To build and install the python package, run:
$ make install
NOTE: To use the python code that is installed by make install
you must
leave the root directory of this repository. Attempting to import compiler_gym
while in the root of this repository will cause import errors.
When you are finished, you can deactivate and delete the conda environment using:
$ conda deactivate
$ conda env remove -n compiler_gym
Trying it out
In Python, import compiler_gym
to use the environments:
>>> import gym
>>> import compiler_gym # imports the CompilerGym environments
>>> env = gym.make("llvm-autophase-ic-v0") # starts a new environment
>>> env.require_dataset("npb-v0") # downloads a set of programs
>>> env.reset() # starts a new compilation session with a random program
>>> env.render() # prints the IR of the program
>>> env.step(env.action_space.sample()) # applies a random optimization, updates state/reward/actions
See the documentation website for tutorials, further details, and API reference.
Leaderboards
🚧 Under construction 🚧 As of CompilerGym v0.1.6 we are not yet accepting submissions for these leaderboards. Please check back soon!
These leaderboards track the performance of user-submitted algorithms for CompilerGym tasks. To submit a result please see this document.
llvm-ic-v0
LLVM is a popular open source compiler used widely in industry and research.
This environment exposes the optimization pipeline 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 codesize
achieved scaled to the reduction achieved by LLVM's builtin -Oz
pipeline.
cBench-v1
This leaderboard tracks the results achieved by algorithms on the llvm-ic-v0
environment on the 23 benchmarks in the cBench-v1
dataset.
Author | Algorithm | Links | Date | Walltime (mean) | Codesize Reduction (geomean) |
---|---|---|---|---|---|
Greedy search | write-up, results | 2021-03 | 169.237s | 1.055× | |
e-Greedy search (e=0.1) | write-up, results | 2021-03 | 152.579s | 1.041× |
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:
@Misc{CompilerGym,
author = {Cummins, Chris and Leather, Hugh and Steiner, Benoit and He, Horace and Chintala, Soumith},
title = {{CompilerGym}: A Reinforcement Learning Toolkit for Compilers},
howpublished = {\url{https://github.com/facebookresearch/CompilerGym/}},
year = {2020}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for compiler_gym-0.1.6-py3-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44869d250342a7bffb7cef02a71aa7426e212b7cfe7ebc85c7a1d0d0373612c4 |
|
MD5 | 7adea1dbfc13b77bdb2128aed61c495e |
|
BLAKE2b-256 | 162df99a50a094b3c4699f970fe4f53f02923e33d080e1a9690259a23e4bc99d |
Hashes for compiler_gym-0.1.6-py3-none-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 542bba162d01ea80d77ee0e5fb13ee682bf8bb97793d55800606c2250626df02 |
|
MD5 | de3dbabfac71c549960acb8fcd7f32c3 |
|
BLAKE2b-256 | 80d16d30337ce793dfdbe359ce458c103cd976352c349a86d4c110289091fca4 |