Created
June 17, 2021 09:50
-
-
Save Colibrow/9d2b31bc7eff127cfe74c807fce86451 to your computer and use it in GitHub Desktop.
ml-compiler traning process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export LLVM_SRCDIR=~/llvm-project | |
export LLVM_INSTALLDIR=~/llvm-install | |
cd $LLVM_SRCDIR | |
git checkout fa4c3f70ff0768a270b0620dc6d158ed1205ec4e | |
sed -i '9i\set(ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER ON CACHE BOOL "")' ${LLVM_SRCDIR}/clang/cmake/caches/Android-stage2.cmake | |
sed -i '10i\set(LLVM_ENABLE_LTO OFF CACHE BOOL "")' ${LLVM_SRCDIR}/clang/cmake/caches/Android-stage2.cmake | |
//build llvm for training | |
cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_LTO=OFF -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALLDIR} -DLLVM_ENABLE_PROJECTS="clang;lld" -DTENSORFLOW_C_LIB_PATH=${TENSORFLOW_C_LIB_PATH} -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=On -C ${LLVM_SRCDIR}/clang/cmake/caches/Android-stage2.cmake | |
cd build | |
ninja install -j80 | |
//replace toolchain use the one builed | |
... | |
//add compile flag in Build.gn(maybe build/compiler/Build.gn etc) (make sure no flto is open and also remove function-sections && data-sections) | |
cflags += [ | |
"-emit-llvm-bc", | |
"-fexperimental-new-pass-manager", | |
"-Oz", | |
"-Xclang", | |
"-fembed-bitcode=all", | |
] | |
// real build | |
gn --export-compile-commands args out/xxx | |
//then use ml-compiler-opt to run training process and wait all traning is done and saved_policy is saved | |
... | |
//build real llvm for applying ml-compiler | |
cd $LLVM_SRCDIR | |
rm -rf llvm/lib/Analysis/models/inliner/* | |
cp -rf $OUTPUT_DIR/saved_policy/* llvm/lib/Analysis/models/inliner/ | |
cmake -S llvm -B build-release -G Ninja -DLLVM_ENABLE_LTO=OFF -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALLDIR} -DLLVM_ENABLE_PROJECTS="clang;lld" -DTENSORFLOW_AOT_PATH=${TENSORFLOW_AOT_PATH} -C ${LLVM_SRCDIR}/clang/cmake/caches/Android-stage2.cmake | |
cd build-release | |
ninja install -j80 | |
//replace the toochain and use new CFLAGS | |
cflags += [ | |
"-fexperimental-new-pass-manager", | |
"-Oz", | |
"-mllvm -enable-ml-inliner=release" | |
] | |
//recompile the project and compare the size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment