Skip to content

Commit 3afdfbe

Browse files
authored
Merge pull request #630 from facebookresearch/release/v0.2.3
CompilerGym v0.2.3
2 parents 7bfc578 + 57724e1 commit 3afdfbe

File tree

263 files changed

+14456
-8558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+14456
-8558
lines changed

.github/actions/install-cmake-build-dependencies/action.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ runs:
99
- name: Install CMake dependencies
1010
run: |
1111
if [ "$(uname)" = "Darwin" ]; then
12-
echo "CMake build for Darwin is unimplemented."
13-
exit 1
12+
brew install bazelisk ccache cmake zlib
1413
else
1514
# Compiler
16-
sudo apt-get install clang++-9 lld-9 tar bzip2 ninja-build
17-
sudo apt-get install tar bzip2 ninja-build
15+
sudo apt-get install -y bzip2 clang-9 clang++-9 lld-9 tar bzip2 ninja-build tar ninja-build
1816
# CMake
1917
wget https://github.com/Kitware/CMake/releases/download/v3.20.5/cmake-3.20.5-linux-x86_64.sh -O /tmp/cmake.sh
2018
sudo bash /tmp/cmake.sh --prefix=/usr/local --exclude-subdir --skip-license

.github/actions/install-runtime-dependencies/action.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,5 @@ runs:
99
if [ "$(uname)" = "Darwin" ]; then
1010
brew install zlib
1111
fi
12-
shell: bash
13-
14-
# DGL creates ~/.dgl on first run and I have found that this will fail
15-
# if run from pytest / bazel. Suppress errors if DGL is not installed.
16-
- name: Initialize DGL
17-
run: |
18-
python3 -c 'import dgl; print(dgl.__version__)' || true
12+
python -m pip install -U pip wheel
1913
shell: bash

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ jobs:
9494
uses: ./.github/actions/install-runtime-dependencies
9595

9696
- name: Run the examples tests
97-
run: make examples-test
97+
run: make -C examples test

.github/workflows/ci.yaml

+26-52
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,30 @@ jobs:
5252
- name: Install build dependencies
5353
uses: ./.github/actions/install-cmake-build-dependencies
5454

55+
- name: Download LLVM 10.0.0 release
56+
run: |
57+
if [ "$(uname)" = "Darwin" ]; then
58+
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz -O ~/llvm.tar.xz
59+
else
60+
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz -O ~/llvm.tar.xz
61+
fi
62+
# TODO(cummins): Remove 'v' debugging flag:
63+
mkdir ~/llvm && tar xvf ~/llvm.tar.xz --strip-components 1 -C ~/llvm
64+
rm ~/llvm.tar.xz
65+
echo "Unpacked, testing for expected file:"
66+
test -d ~/llvm/lib/cmake/llvm
67+
5568
- name: CMake Build
5669
run: |
5770
cmake \
5871
-GNinja \
59-
-DCMAKE_C_COMPILER=clang-9 \
60-
-DCMAKE_CXX_COMPILER=clang++-9 \
72+
-DCMAKE_C_COMPILER=clang \
73+
-DCMAKE_CXX_COMPILER=clang++ \
6174
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
6275
-DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
6376
-DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \
77+
-DCOMPILER_GYM_LLVM_PROVIDER=external \
78+
-DLLVM_DIR=$HOME/llvm/lib/cmake/llvm \
6479
-DPython3_FIND_VIRTUALENV=FIRST \
6580
-DCOMPILER_GYM_BUILD_TESTS=ON \
6681
-DCOMPILER_GYM_BUILD_EXAMPLES=ON \
@@ -345,42 +360,6 @@ jobs:
345360
uses: codecov/codecov-action@v2
346361

347362
test-gcc-env-macos:
348-
needs: build-macos
349-
runs-on: macos-latest
350-
steps:
351-
- uses: docker-practice/actions-setup-docker@master
352-
353-
- name: Confirm docker install
354-
run: docker version
355-
356-
- uses: actions/checkout@v2
357-
358-
- name: Set up Python
359-
uses: actions/setup-python@v2
360-
with:
361-
python-version: 3.9
362-
363-
- name: Download Python wheel
364-
uses: actions/download-artifact@v2
365-
with:
366-
name: macos-wheel
367-
368-
- name: Install wheel
369-
run: python -m pip install *.whl
370-
371-
- name: Install runtime dependencies
372-
uses: ./.github/actions/install-runtime-dependencies
373-
374-
- name: Install test dependencies
375-
run: python -m pip install -r tests/requirements.txt
376-
377-
- name: Run the test suite
378-
run: make install-test-cov TEST_TARGET="tests/gcc"
379-
380-
- name: Upload coverage report to Codecov
381-
uses: codecov/codecov-action@v2
382-
383-
test-gcc-env-macos-no-docker:
384363
needs: build-macos
385364
runs-on: macos-latest
386365
steps:
@@ -446,11 +425,6 @@ jobs:
446425
needs: build-macos
447426
runs-on: macos-latest
448427
steps:
449-
- uses: docker-practice/actions-setup-docker@master
450-
451-
- name: Confirm docker install
452-
run: docker version
453-
454428
- uses: actions/checkout@v2
455429

456430
- name: Set up Python
@@ -501,14 +475,14 @@ jobs:
501475
- name: Install wheel
502476
run: python -m pip install *.whl
503477

504-
- name: Install test dependencies
505-
run: python -m pip install -r examples/requirements.txt -r tests/requirements.txt
506-
507478
- name: Install runtime dependencies
508479
uses: ./.github/actions/install-runtime-dependencies
509480

481+
- name: Install test dependencies
482+
run: make -C examples install
483+
510484
- name: Run the test suite
511-
run: make examples-test
485+
run: make -C examples test
512486

513487
- name: Upload coverage report to Codecov
514488
uses: codecov/codecov-action@v2
@@ -536,14 +510,14 @@ jobs:
536510
- name: Install wheel
537511
run: python -m pip install *.whl
538512

539-
- name: Install test dependencies
540-
run: python -m pip install -r examples/requirements.txt -r tests/requirements.txt
541-
542513
- name: Install runtime dependencies
543514
uses: ./.github/actions/install-runtime-dependencies
544515

516+
- name: Install test dependencies
517+
run: make -C examples install
518+
545519
- name: Run the test suite
546-
run: make examples-test
520+
run: make -C examples test
547521

548522
- name: Upload coverage report to Codecov
549523
uses: codecov/codecov-action@v2
@@ -636,7 +610,7 @@ jobs:
636610
fail-fast: false
637611
matrix:
638612
os: [ubuntu-latest, macos-latest]
639-
node: [16]
613+
node: [17]
640614
steps:
641615
- uses: actions/checkout@v2
642616

.github/workflows/pip_install_test.yaml

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
2-
# This workflow pip install's teh compiler_gym package and checks that the
3-
# module can be imported. The goal of this workflow is to catch failures in the
4-
# installation process that can occur because of a breaking change in the
5-
# dependent packages.
2+
# This workflow pip install's the compiler_gym package and checks that the
3+
# module can be imported.
4+
#
5+
# The goal of this workflow is to catch failures in the installation process
6+
# that can occur because of a breaking change in the dependent packages, and to
7+
# test for any import-time error.
68
name: Pip install test
79

810
on:
@@ -26,7 +28,12 @@ jobs:
2628
python-version: ${{ matrix.python }}
2729

2830
- name: Install python wheel
29-
run: python -m pip install compiler_gym
31+
# We use the TestPyPI repository to install the compiler_gym
32+
# package from because we use the install count on the main
33+
# repository to track growth and usage of the project. We also
34+
# provide the main PyPI repo as a fallback for installing
35+
# dependencies.
36+
run: python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ compiler_gym
3037

3138
- name: Check package version
3239
run: python -c 'import compiler_gym; print(compiler_gym.__version__)'

.pre-commit-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ repos:
7272
rev: v1.0
7373
hooks:
7474
- id: dockerlint
75+
- repo: https://github.com/BlankSpruce/gersemi
76+
rev: 0.7.5
77+
hooks:
78+
- id: gersemi

CMakeLists.txt

+47-35
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,79 @@
66
cmake_minimum_required(VERSION 3.20)
77

88
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
9-
message(FATAL_ERROR "In-source builds are unsupported. Please, build out of the source tree.")
9+
message(
10+
FATAL_ERROR
11+
"In-source builds are unsupported. Please, build out of the source tree."
12+
)
1013
endif()
1114

12-
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
13-
set(DARWIN TRUE)
14-
endif()
15-
16-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
17-
1815
project(compiler_gym ASM C CXX)
1916

2017
set(CMAKE_C_STANDARD 11 CACHE STRING "C standard to be used.")
2118
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to be used.")
2219

2320
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2421

25-
list(APPEND CMAKE_MODULE_PATH
26-
${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake/
27-
)
22+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake)
2823

24+
# Project features.
2925
set(COMPILER_GYM_BUILD_TESTS OFF CACHE BOOL "Enable Compiler Gym tests.")
3026
set(COMPILER_GYM_BUILD_EXAMPLES OFF CACHE BOOL "Enable Comiler Gym examples.")
3127

32-
include(cg_macros)
33-
include(cg_copts)
34-
include(cg_genrule)
35-
include(cg_cc_binary)
36-
include(cg_cc_library)
37-
include(cg_cc_test)
38-
include(cg_py_binary)
39-
include(cg_py_library)
40-
include(cg_py_test)
41-
include(cg_python)
42-
include(cg_add_all_subdirs)
43-
include(cg_filegroup)
44-
include(grpc)
45-
include(protobuf)
46-
47-
set(COMPILER_GYM_PYTHONPATH "$ENV{PYTHONPATH}" CACHE STRING "PYTHONPATH environment variable during build step.")
48-
if (COMPILER_GYM_PYTHONPATH)
49-
string(PREPEND COMPILER_GYM_PYTHONPATH ":")
28+
# Toolchain configuration.
29+
include(build_tools/cmake/FindAndEnableCcache.cmake)
30+
include(build_tools/cmake/FindAndEnableLld.cmake)
31+
32+
include(build_tools/cmake/cg_macros.cmake)
33+
include(build_tools/cmake/cg_copts.cmake)
34+
include(build_tools/cmake/cg_genrule.cmake)
35+
include(build_tools/cmake/cg_cc_binary.cmake)
36+
include(build_tools/cmake/cg_cc_library.cmake)
37+
include(build_tools/cmake/cg_cc_test.cmake)
38+
include(build_tools/cmake/cg_py_binary.cmake)
39+
include(build_tools/cmake/cg_py_library.cmake)
40+
include(build_tools/cmake/cg_py_test.cmake)
41+
include(build_tools/cmake/cg_python.cmake)
42+
include(build_tools/cmake/cg_add_all_subdirs.cmake)
43+
include(build_tools/cmake/cg_filegroup.cmake)
44+
include(build_tools/cmake/grpc.cmake)
45+
include(build_tools/cmake/protobuf.cmake)
46+
47+
# Set up the build Python path.
48+
set(COMPILER_GYM_BUILD_PYTHONPATH "$ENV{PYTHONPATH}"
49+
CACHE STRING "PYTHONPATH environment variable during build step."
50+
)
51+
if(COMPILER_GYM_BUILD_PYTHONPATH)
52+
string(PREPEND COMPILER_GYM_BUILD_PYTHONPATH ":")
5053
endif()
51-
string(PREPEND COMPILER_GYM_PYTHONPATH "${CMAKE_BINARY_DIR}")
52-
include(set_command_pythonpath)
54+
string(PREPEND COMPILER_GYM_BUILD_PYTHONPATH "${CMAKE_BINARY_DIR}")
55+
include(build_tools/cmake/set_command_pythonpath.cmake)
5356

5457
set(DEFAULT_CMAKE_BUILD_TYPE "Release")
5558
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
56-
message(STATUS "No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}")
57-
set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE)
59+
message(
60+
STATUS
61+
"No build type selected, default to ${DEFAULT_CMAKE_BUILD_TYPE}"
62+
)
63+
set(CMAKE_BUILD_TYPE "${DEFAULT_CMAKE_BUILD_TYPE}"
64+
CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})"
65+
FORCE
66+
)
5867
endif()
5968

6069
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
6170

6271
find_package(Python3 REQUIRED COMPONENTS Interpreter)
6372

6473
include(external/external.cmake)
74+
6575
add_subdirectory(compiler_gym)
76+
6677
if(COMPILER_GYM_BUILD_TESTS)
67-
enable_testing()
68-
add_subdirectory(tests)
78+
enable_testing()
79+
add_subdirectory(tests)
6980
endif()
81+
7082
if(COMPILER_GYM_BUILD_EXAMPLES)
71-
add_subdirectory(examples)
83+
add_subdirectory(examples)
7284
endif()

INSTALL.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ with the required dependencies:
5454

5555
conda create -y -n compiler_gym python=3.8
5656
conda activate compiler_gym
57-
conda install -y -c conda-forge cmake pandoc patchelf
57+
conda install -y -c conda-forge cmake doxygen pandoc patchelf
5858

5959
Then clone the CompilerGym source code using:
6060

@@ -122,24 +122,24 @@ By default most dependencies are built together with Compiler Gym. To search for
122122
* `COMPILER_GYM_GLOG_PROVIDER`
123123
* `COMPILER_GYM_GRPC_PROVIDER`
124124
* `COMPILER_GYM_GTEST_PROVIDER`
125+
* `COMPILER_GYM_LLVM_PROVIDER`
125126
* `COMPILER_GYM_NLOHMANN_JSON_PROVIDER`
126127
* `COMPILER_GYM_PROTOBUF_PROVIDER`
127128

128129
```bash
129-
cmake -GNinja \
130+
cmake \
130131
-DCMAKE_C_COMPILER=clang-9 \
131132
-DCMAKE_CXX_COMPILER=clang++-9 \
132-
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ # For faster rebuilds, can be removed
133-
-DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \ # For faster builds, can be removed
134133
-DPython3_FIND_VIRTUALENV=FIRST \
135134
-DCMAKE_BUILD_WITH_INSTALL_RPATH=true \
136135
-S "<path to source directory>" \
137136
-B "<path to build directory>"
138137

139-
cmake --build "<path to build directory>"
138+
cmake --build "<path to build directory>"
140139

141140
pip install <path to build directory>/py_pkg/dist/compiler_gym*.whl --force-reinstall
142141
```
142+
143143
Additional optional configuration arguments:
144144

145145
* Enables testing.
@@ -168,3 +168,18 @@ Additional optional configuration arguments:
168168
-DCMAKE_C_COMPILER_LAUNCHER=ccache
169169
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
170170
```
171+
172+
By default, CompilerGym builds LLVM from source. This takes a long time and a
173+
lot of compute resources. To prevent this, download a pre-compiled clang+llvm
174+
release of LLVM 10.0.0 from the [llvm-project releases
175+
page](https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.0), unpack
176+
it, and pass path of the `lib/cmake/llvm` subdirectory in the archive you just
177+
extracted to `LLVM_DIR`:
178+
179+
```
180+
$ cmake ... \
181+
-DCOMPILER_GYM_LLVM_PROVIDER=external \
182+
-DLLVM_DIR=/path/to/llvm/lib/cmake/llvm
183+
```
184+
185+
⚠️ CompilerGym requires exactly LLVM 10.0.0.

0 commit comments

Comments
 (0)