Skip to content

Commit

Permalink
[ci] add torch frontend ci (#51)
Browse files Browse the repository at this point in the history
* add ci

* fix yml

* add +x

* fix script

* don't use llvm prebuild for torch frontend

* update llvm

* clear workspace before and after

* use prebuilt'

* add yml change
  • Loading branch information
zhekunz2 authored Sep 1, 2023
1 parent 0e76730 commit c752156
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compiler-and-runtime-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- main
paths-ignore:
- "frontends/**"
- "scripts/frontends/**"
pull_request:
branches:
- main
paths-ignore:
- "frontends/**"
- "scripts/frontends/**"
workflow_dispatch:

jobs:
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/torch-frontend-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: TorchFrontend CI

on:
push:
branches:
- main
paths:
- "frontends/torch-frontend/**"
- "scripts/frontends/torch-frontend/**"
pull_request:
branches:
- main
paths:
- "frontends/torch-frontend/**"
- "scripts/frontends/torch-frontend/**"
workflow_dispatch:

jobs:
torch_frontend_build_and_test:
name: torch-frontend CI
runs-on: self-hosted
steps:
- name: clear workspace
run: rm -rf $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
- name: Checkout byteir repo
uses: actions/checkout@v3
- name: Build and test TorchFrontend
run: ./scripts/frontends/torch-frontend/build_and_test.sh ${{ secrets.TORCH_FRONTEND_LLVM_INSTALL_DIR }}
shell: bash
34 changes: 34 additions & 0 deletions scripts/frontends/torch-frontend/build_and_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

set -e
set -x

# path to script
CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# path to byteir root
ROOT_PROJ_DIR="$CUR_DIR/../../.."
# path to byteir/frontends/torch-frontend
PROJ_DIR="$ROOT_PROJ_DIR/frontends/torch-frontend"

source $CUR_DIR/envsetup.sh
prepare_for_build

LLVM_INSTALL_DIR="$1"

pushd $PROJ_DIR
cmake -S . \
-B ./build \
-GNinja \
-DMLIR_DIR="$LLVM_INSTALL_DIR/lib/cmake/mlir" \
-DLLVM_EXTERNAL_LIT=$(which lit) \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DPython3_EXECUTABLE=$(which python3)

cmake --build ./build --target all

python3 -m pip install -r ./torch-requirements.txt
PYTHONPATH=./build/python_packages/ python3 -m pytest torch-frontend/python/test

popd
38 changes: 38 additions & 0 deletions scripts/frontends/torch-frontend/envsetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -e
set -x

# path to script
CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# path to byteir root
ROOT_PROJ_DIR="$CUR_DIR/../../.."
# path to byteir/frontends/torch-frontend
PROJ_DIR="$ROOT_PROJ_DIR/frontends/torch-frontend"
# path to torch-mlir
TORCH_MLIR_ROOT="$PROJ_DIR/third_party/torch-mlir"

function apply_patches() {
pushd $TORCH_MLIR_ROOT
git clean -fd .
for patch in ../patches/*; do
git apply $patch
done
popd
}

function prepare_for_build() {
pushd ${PROJ_DIR}
# install requirements
python3 -m pip install -r requirements.txt

# init submodule
git submodule update --init -f $TORCH_MLIR_ROOT
pushd $TORCH_MLIR_ROOT
git submodule update --init -f externals/mlir-hlo
git submodule update --init -f externals/llvm-project
popd

# apply patches
apply_patches
}

0 comments on commit c752156

Please sign in to comment.