Skip to content

Commit f639f31

Browse files
Added integration tests
1 parent f45ed53 commit f639f31

File tree

8 files changed

+295
-0
lines changed

8 files changed

+295
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
export PATH=/fuchsia/.jiri_root/bin:$PATH
18+
cd /fuchsia
19+
fx set core.x64 \
20+
--args='clang_prefix="/llvm-install/bin"' \
21+
--args=clang_embed_bitcode=true \
22+
--args='optimize="size"' \
23+
--args='clang_ml_inliner=false'
24+
fx build
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
cd /
18+
git clone --depth 1 https://github.com/llvm/llvm-project
19+
mkdir /llvm-build
20+
cd /llvm-build
21+
apt-get install -y lld
22+
cmake -G Ninja \
23+
-DLLVM_ENABLE_LTO=OFF \
24+
-DLINUX_x86_64-unknown-linux-gnu_SYSROOT=/fuchsia-sysroot/linux-x64 \
25+
-DLINUX_aarch64-unknown-linux-gnu_SYSROOT=/fuchsia-sysroot/linux-arm64 \
26+
-DFUCHSIA_SDK=/fuchsia-idk \
27+
-DCMAKE_INSTALL_PREFIX= \
28+
-DTENSORFLOW_C_LIB_PATH=/tmp/tensorflow \
29+
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=On \
30+
-C /llvm-project/clang/cmake/caches/Fuchsia-stage2.cmake \
31+
/llvm-project/llvm
32+
ninja distribution
33+
DESTDIR=/llvm-install ninja install-distribution-stripped
34+
cd /fuchsia
35+
python3 scripts/clang/generate_runtimes.py \
36+
--clang-prefix=/llvm-install \
37+
--sdk-dir=/fuchsia-idk \
38+
--build-id-dir=/llvm-install/lib/.build-id > /llvm-install/lib/runtime.json

integration_tests/inlining/ci.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
docker build -t mlgo-development -f ../experimental/docker/development.Dockerfile ../
18+
docker run --name inlining-integration-tests mlgo-development /ml-compiler-opt/integration_tests/inlining/pipeline.sh
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
cd /
18+
apt-get install -y curl file unzip
19+
curl -s "https://fuchsia.googlesource.com/fuchsia/+/HEAD/scripts/bootstrap?format=TEXT" | base64 --decode | bash
20+
export PATH=/fuchsia/.jiri_root/bin:$PATH
21+
cipd install fuchsia/sdk/core/linux-amd64 latest -root /fuchsia-idk
22+
cipd install fuchsia/sysroot/linux-arm64 latest -root /fuchsia-sysroot/linux-arm64
23+
cipd install fuchsia/sysroot/linux-amd64 latest -root /fuchsia-sysroot/linux-x64
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
../build_llvm.sh
18+
./build_fuchsia.sh
19+
./train_ml.sh
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
cd /ml-compiler-opt
18+
export PYTHONPATH=$PYTHONPATH:.
19+
mkdir /corpus
20+
python3 compiler_opt/tools/extract_ir.py \
21+
--cmd_filter="^-O2|-Os|-Oz$" \
22+
--input=/fuchsia/out/default/compile_commands.json \
23+
--input_type=json \
24+
--llvm_objcopy_path=/llvm-build/bin/llvm-objcopy \
25+
--output_dir=/corpus
26+
python3 compiler_opt/tools/generate_default_trace.py \
27+
--data_path=/corpus \
28+
--output_path=/default_trace \
29+
--gin_files=compiler_opt/rl/inlining/gin_configs/common.gin \
30+
--gin_bindings=config_registry.get_configuration.implementation=@configs.InliningConfig \
31+
--gin_bindings=clang_path="'/llvm-build/bin/clang'" \
32+
--gin_bindings=llvm_size_path="'/llvm-build/bin/llvm-size'" \
33+
--sampling_rate=0.2
34+
rm -rf compiler_opt/rl/inlining/vocab
35+
python3 compiler_opt/tools/sparse_bucket_generator.py \
36+
--gin_files=compiler_opt/rl/inlining/gin_configs/common.gin \
37+
--input=/default_trace \
38+
--output_dir=compiler_opt/rl/inlining/vocab
39+
# Only train bc agent for 100 iterations. We're verifying the tooling is
40+
# working correctly, not the model performance.
41+
sed -i 's/train_eval.num_iterations=10000/train_eval.num_iterations=100/' \
42+
compiler_opt/rl/inlining/gin_configs/behavioral_cloning_nn_agent.gin
43+
python3 compiler_opt/rl/train_bc.py \
44+
--root_dir=/warmstart \
45+
--data_path=/default_trace \
46+
--gin_files=compiler_opt/rl/regalloc/gin_configs/behavioral_cloning_nn_agent.gin
47+
# same for the rl training. Only do one policy iteration.
48+
sed -i 's/train_eval.num_policy_iterations=3000/train_eval.num_policy_iterations=1/' \
49+
compiler_opt/rl/inlining/gin_configs/ppo_nn_agent.gin
50+
python3 compiler_opt/rl/train_locally.py \
51+
--root_dir=/output_model \
52+
--data_path=/corpus \
53+
--gin_bindings=clang_path="'/llvm-build/bin/clang'" \
54+
--gin_bindings=llvm_size_path="'/llvm-build/bin/llvm-size'" \
55+
--num_modules=100 \
56+
--gin_files=compiler_opt/rl/inlining/gin_configs/ppo_nn_agent.gin \
57+
--gin_bindings=train_eval.warmstart_policy_dir=\"/warmstart/saved_policy\"

integration_tests/regalloc/ci.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
docker build -t mlgo-development -f ../experimental/docker/development.Dockerfile ../
18+
docker run --name regalloc-integration-tests mlgo-development /ml-compiler-opt/integration_tests/regalloc/pipeline.sh
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
set -e
17+
# clone and build llvm
18+
cd /
19+
git clone https://github.com/llvm/llvm-project
20+
mkdir /llvm-build
21+
cd /llvm-build
22+
cmake -G Ninja \
23+
-DCMAKE_BUILD_TYPE=Release \
24+
-DTENSORFLOW_C_LIB_PATH=/tmp/tensorflow \
25+
-DTENSORFLOW_AOT_PATH=$(python3 -c "import tensorflow; import os; print(os.path.dirname(tensorflow.__file__))") \
26+
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
27+
-DLLVM_ENABLE_PROJECTS="clang" \
28+
/llvm-project/llvm
29+
cmake --build .
30+
31+
# clone and build chromium
32+
cd /
33+
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
34+
export PATH="$PATH:/depot_tools"
35+
mkdir /chromium
36+
cd /chromium
37+
fetch --nohooks --no-history chromium
38+
sed -i 's/"custom_vars": {},/"custom_vars": { "checkout_pgo_profiles" : True },/' .gclient
39+
cd src
40+
git apply /ml-compiler-opt/experimental/chromium-bitcode-embedding.patch
41+
apt-get install -y sudo
42+
sed -i 's/${dev_list} snapcraft/${dev_list}/' ./build/install-build-deps.sh
43+
./build/install-build-deps.sh
44+
gclient runhooks
45+
gn gen out/Release --export-compile-commands --args="\
46+
is_official_build=true \
47+
use_thin_lto=false \
48+
is_cfi=false \
49+
clang_embed_bitcode=true \
50+
is_debug=false \
51+
symbol_level=0 \
52+
enable_nacl=false"
53+
# tensorflow and chromium protobuf versions are incompatible
54+
# install protobuf4 here so that the chromium build will complete
55+
pip3 install protobuf==4.21.5
56+
autoninja -C out/Release
57+
58+
# test training ml
59+
cd /ml-compiler-opt
60+
export PYTHONPATH=$PYTHONPATH:.
61+
mkdir /corpus
62+
# make sure protobuf is now at the tensorflow version requirement
63+
pip3 install -r requirements.txt
64+
python3 compiler_opt/tools/extract_ir.py \
65+
--cmd_filter="^-O2|-O3$" \
66+
--input=/chromium/src/out/Release/compile_commands.json \
67+
--input_type=json \
68+
--llvm_objcopy_path=/llvm-build/bin/llvm-objcopy \
69+
--output_dir=/corpus
70+
python3 compiler_opt/tools/generate_default_trace.py \
71+
--data_path=/corpus \
72+
--output_path=/default_trace \
73+
--gin_files=compiler_opt/rl/regalloc/gin_configs/common.gin \
74+
--gin_bindings=config_registry.get_configuration.implementation=@configs.RegallocEvictionConfig \
75+
--gin_bindings=clang_path="'/llvm-build/bin/clang'" \
76+
--sampling_rate=0.2
77+
rm -rf ./compiler_opt/rl/regalloc/vocab
78+
python3 \
79+
compiler_opt/tools/sparse_bucket_generator.py \
80+
--input=/default_trace \
81+
--output_dir=./compiler_opt/rl/regalloc/vocab
82+
# Only train bc agent for 100 iterations. We're verifying the tooling is
83+
# working correctly, not the model performance.
84+
sed -i 's/train_eval.num_iterations=10000/train_eval.num_iterations=100/' \
85+
compiler_opt/rl/regalloc/gin_configs/behavioral_cloning_nn_agent.gin
86+
python3 compiler_opt/rl/train_bc.py \
87+
--root_dir=/warmstart \
88+
--data_path=/default_trace \
89+
--gin_files=compiler_opt/rl/regalloc/gin_configs/behavioral_cloning_nn_agent.gin
90+
# same for the rl training. Only do one policy iteration.
91+
sed -i 's/train_eval.num_policy_iterations=3000/train_eval.num_policy_iterations=1/' \
92+
compiler_opt/rl/regalloc/gin_configs/ppo_nn_agent.gin
93+
python3 compiler_opt/rl/train_locally.py \
94+
--root_dir=/output_model \
95+
--data_path=/corpus \
96+
--gin_bindings=clang_path="'/llvm-build/bin/clang'" \
97+
--gin_files=compiler_opt/rl/regalloc/gin_configs/ppo_nn_agent.gin \
98+
--gin_bindings=train_eval.warmstart_policy_dir=\"/warmstart/saved_policy\"

0 commit comments

Comments
 (0)