From 18b66969e95bb4828facc87ca60025bf7e7c29fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 4 Apr 2022 10:58:58 +0100 Subject: [PATCH 1/9] Add README instructions for OOT build --- README.md | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 015c8c6b4aa2..963306307c21 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,9 @@ python -m pip install -r requirements.txt ``` ## Build + +The following command generates configuration files to build the project *in-tree*, that is, using llvm/llvm-project as the main build. + ```shell cmake -GNinja -Bbuild \ -DCMAKE_C_COMPILER=clang \ @@ -65,23 +68,44 @@ cmake -GNinja -Bbuild \ -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ -DLLVM_TARGETS_TO_BUILD=host \ externals/llvm-project/llvm - -# Additional quality of life CMake flags: -# Enable ccache: -# -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -# Enable LLD (links in seconds compared to minutes) -# -DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" +``` +The following additional quality of life flags can be used to reduce build time: +* Enabling ccache: +```shell + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache +``` +* Enabling LLD (links in seconds compared to minutes) +```shell + -DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" # Use --ld-path= instead of -fuse-ld=lld for clang > 13 +``` +If you have built llvm-project separately in the directory `$LLVM_INSTALL_DIR`, you can also build the project *out-of-tree* using the following command as template: +```shell +cmake -GNinja -Bbuild \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DPython3_FIND_VIRTUALENV=ONLY \ + -DMLIR_DIR="$LLVM_INSTALL_DIR/lib/cmake/mlir/" \ + -DLLVM_DIR="$LLVM_INSTALL_DIR/lib/cmake/llvm/" \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DLLVM_TARGETS_TO_BUILD=host \ + . +``` +The same QoL CMake flags can be used to enable ccache and lld. Be sure to have built LLVM with `-DLLVM_ENABLE_PROJECTS=mlir`. + +After either cmake run (in-tree/out-of-tree), use one of the following commands to build the project: +```shell # Build just torch-mlir (not all of LLVM) cmake --build build --target tools/torch-mlir/all # Run unit tests. cmake --build build --target check-torch-mlir -# Build everything (including LLVM) +# Build everything (including LLVM if in-tree) cmake --build build ``` + ## Demos ## Setup Python Environment From 6f97e804b092271753324f9f08cb4667d75ac191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 4 Apr 2022 11:13:29 +0100 Subject: [PATCH 2/9] Refactor current CI workflow into composable jobs --- .github/actions/setup-build/action.yml | 28 ++++++++++++++++++++++++++ .github/workflows/buildAndTest.yml | 28 ++++---------------------- 2 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 .github/actions/setup-build/action.yml diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml new file mode 100644 index 000000000000..fe7df05ce305 --- /dev/null +++ b/.github/actions/setup-build/action.yml @@ -0,0 +1,28 @@ +name: "Setup build environment" +description: "Setup the build environment. An action so that it can be shared between in-tree/out-of-tree jobs" + +runs: + using: "composite" + steps: + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install MLIR Python depends + run: | + python -m pip install -r $GITHUB_WORKSPACE/externals/llvm-project/mlir/python/requirements.txt + shell: bash + - name: Install PyTorch nightly depends + run: | + python -m pip install -r requirements.txt + shell: bash + - name: Install Ninja + uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268 + - name: Get Submodule Hash + id: get-submodule-hash + run: echo "::set-output name=hash::$(md5sum $(git submodule status))" + shell: bash + - name: Ccache for C++ compilation + uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 + with: + key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index e60b02c20295..e9b2ae81a9db 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -19,30 +19,11 @@ jobs: name: Build and Test (Release Asserts) runs-on: ubuntu-20.04 steps: - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - name: Get torch-mlir uses: actions/checkout@v2 with: submodules: 'true' - - name: Install MLIR Python depends - run: | - python -m pip install -r $GITHUB_WORKSPACE/externals/llvm-project/mlir/python/requirements.txt - - name: Install PyTorch nightly depends - run: | - python -m pip install -r requirements.txt - - name: Install Ninja - uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268 - - name: Get Submodule Hash - id: get-submodule-hash - run: echo "::set-output name=hash::$(md5sum $(git submodule status))" - shell: bash - - name: Ccache for C++ compilation - uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 - with: - key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} + - uses: ./.github/actions/setup-build - name: Build and Test torch-mlir (Assert) run: | cd $GITHUB_WORKSPACE @@ -85,11 +66,10 @@ jobs: TORCH_MLIR_PYTHON_PACKAGE_VERSION="${{ github.event.inputs.python_package_version }}" \ ./build_tools/build_python_wheels.sh - # If we were given a release_id, then upload the package we just built - # to the github releases page. + # upload the package we just built to the github releases page. - name: Upload Release Assets (if requested) - if: github.event.inputs.release_id != '' id: upload-release-assets + if: github.event.inputs.release_id != '' uses: dwenegar/upload-release-assets@v1 env: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} @@ -99,8 +79,8 @@ jobs: # Publishing is necessary to make the release visible to `pip` # on the github releases page. - name: Publish Release (if requested) - if: github.event.inputs.release_id != '' id: publish_release + if: github.event.inputs.release_id != '' uses: eregon/publish-release@v1 env: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} From 341207e94d20e71633e76b132a110b64a6e70bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 4 Apr 2022 16:20:56 +0100 Subject: [PATCH 3/9] Add build-out-of-tree job --- .github/workflows/buildAndTest.yml | 52 +++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index e9b2ae81a9db..8f80a1267b28 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -16,7 +16,7 @@ on: jobs: build: - name: Build and Test (Release Asserts) + name: Build and Test and maybe Publish (Release Asserts) runs-on: ubuntu-20.04 steps: - name: Get torch-mlir @@ -86,3 +86,53 @@ jobs: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} with: release_id: ${{ github.event.inputs.release_id }} + + build-out-of-tree: + name: Build and Test out-of-tree (Release Asserts) + runs-on: ubuntu-20.04 + steps: + - name: Get torch-mlir + uses: actions/checkout@v2 + with: + submodules: 'true' + - uses: ./.github/actions/setup-build + - name: Build LLVM (standalone) + run: | + cd $GITHUB_WORKSPACE + cmake -Bllvm-build -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_LINKER=lld \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ + -DPython3_EXECUTABLE=$(which python) \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DLLVM_ENABLE_PROJECTS=mlir \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DLLVM_TARGETS_TO_BUILD=host \ + externals/llvm-project/llvm + ninja -Cllvm-build + + - name: Build and test torch-mlir (out-of-tree) + run: | + cd $GITHUB_WORKSPACE + cmake -GNinja -Bbuild \ + -DCMAKE_LINKER=lld \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ + -DMLIR_DIR="$(pwd)/llvm-build/lib/cmake/mlir/" \ + -DLLVM_DIR="$(pwd)/llvm-build/lib/cmake/llvm/" \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DPython3_EXECUTABLE=$(which python) \ + . + ninja -Cbuild check-torch-mlir-all + + - name: RefBackend - TorchScript end-to-end tests + run: | + cd $GITHUB_WORKSPACE + export PYTHONPATH="$GITHUB_WORKSPACE/build/python_packages/torch_mlir" + python -m e2e_testing.torchscript.main --config=refbackend -v + - name: TOSA backend - TorchScript end-to-end tests + run: | + cd $GITHUB_WORKSPACE + export PYTHONPATH="$GITHUB_WORKSPACE/build/python_packages/torch_mlir" + python -m e2e_testing.torchscript.main --config=tosa -v From 45d8950b7093da692b43100bfe3b9bf2f23eec4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 11 Apr 2022 17:50:32 +0100 Subject: [PATCH 4/9] address PR review --- .github/workflows/buildAndTest.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 8f80a1267b28..79bcabd365fb 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -66,10 +66,11 @@ jobs: TORCH_MLIR_PYTHON_PACKAGE_VERSION="${{ github.event.inputs.python_package_version }}" \ ./build_tools/build_python_wheels.sh - # upload the package we just built to the github releases page. + # If we were given a release_id, then upload the package we just built + # to the github releases page. - name: Upload Release Assets (if requested) - id: upload-release-assets if: github.event.inputs.release_id != '' + id: upload-release-assets uses: dwenegar/upload-release-assets@v1 env: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} @@ -79,8 +80,8 @@ jobs: # Publishing is necessary to make the release visible to `pip` # on the github releases page. - name: Publish Release (if requested) - id: publish_release if: github.event.inputs.release_id != '' + id: publish_release uses: eregon/publish-release@v1 env: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} From 88dbaa8182eb80d74f74a6ab0a9f45072fefb05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 11 Apr 2022 17:55:45 +0100 Subject: [PATCH 5/9] Improve README --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 963306307c21..1adea86b3e62 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,11 @@ python -m pip install -r requirements.txt ## Build -The following command generates configuration files to build the project *in-tree*, that is, using llvm/llvm-project as the main build. +Two setups are possible to build: in-tree and out-of-tree. The in-tree setup is the most straightforward, as it will build LLVM dependencies as well. + +### Building torch-mlir in-tree + +The following command generates configuration files to build the project *in-tree*, that is, using llvm/llvm-project as the main build. This will build LLVM as well as torch-mlir and its subprojects. ```shell cmake -GNinja -Bbuild \ @@ -80,6 +84,8 @@ The following additional quality of life flags can be used to reduce build time: # Use --ld-path= instead of -fuse-ld=lld for clang > 13 ``` +### Building against a pre-built LLVM + If you have built llvm-project separately in the directory `$LLVM_INSTALL_DIR`, you can also build the project *out-of-tree* using the following command as template: ```shell cmake -GNinja -Bbuild \ @@ -94,6 +100,11 @@ cmake -GNinja -Bbuild \ ``` The same QoL CMake flags can be used to enable ccache and lld. Be sure to have built LLVM with `-DLLVM_ENABLE_PROJECTS=mlir`. +Be aware that the installed version of LLVM needs in general to match the committed version in `externals/llvm-project`. Using a different version may or may not work. + + +### Build commands + After either cmake run (in-tree/out-of-tree), use one of the following commands to build the project: ```shell # Build just torch-mlir (not all of LLVM) From ee7ea19e46d66c3de1b219030ab6348c109a5bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 12 Apr 2022 17:49:13 +0100 Subject: [PATCH 6/9] wip: Build OOT in same job --- .github/actions/setup-build/action.yml | 28 -------- .github/workflows/buildAndTest.yml | 93 ++++++++++---------------- 2 files changed, 37 insertions(+), 84 deletions(-) delete mode 100644 .github/actions/setup-build/action.yml diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml deleted file mode 100644 index fe7df05ce305..000000000000 --- a/.github/actions/setup-build/action.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: "Setup build environment" -description: "Setup the build environment. An action so that it can be shared between in-tree/out-of-tree jobs" - -runs: - using: "composite" - steps: - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Install MLIR Python depends - run: | - python -m pip install -r $GITHUB_WORKSPACE/externals/llvm-project/mlir/python/requirements.txt - shell: bash - - name: Install PyTorch nightly depends - run: | - python -m pip install -r requirements.txt - shell: bash - - name: Install Ninja - uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268 - - name: Get Submodule Hash - id: get-submodule-hash - run: echo "::set-output name=hash::$(md5sum $(git submodule status))" - shell: bash - - name: Ccache for C++ compilation - uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 - with: - key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 79bcabd365fb..f45729c1e60c 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -16,20 +16,37 @@ on: jobs: build: - name: Build and Test and maybe Publish (Release Asserts) + name: Build and Test (Release Asserts) runs-on: ubuntu-20.04 steps: + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 - name: Get torch-mlir uses: actions/checkout@v2 with: submodules: 'true' - - uses: ./.github/actions/setup-build + - name: Install MLIR Python depends + run: | + python -m pip install -r $GITHUB_WORKSPACE/externals/llvm-project/mlir/python/requirements.txt + - name: Install PyTorch nightly depends + run: | + python -m pip install -r requirements.txt + - name: Install Ninja + uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268 + - name: Get Submodule Hash + id: get-submodule-hash + run: echo "::set-output name=hash::$(md5sum $(git submodule status))" + shell: bash + - name: Ccache for C++ compilation + uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 + with: + key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} - name: Build and Test torch-mlir (Assert) run: | cd $GITHUB_WORKSPACE - mkdir build - cd build - cmake $GITHUB_WORKSPACE/externals/llvm-project/llvm -GNinja \ + cmake externals/llvm-project/llvm -Bbuild -GNinja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_LINKER=lld \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ @@ -42,7 +59,21 @@ jobs: -DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="${GITHUB_WORKSPACE}/external/llvm-external-projects/torch-mlir-dialects" \ -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ -DLLVM_TARGETS_TO_BUILD=host - ninja check-torch-mlir-all + ninja -Cbuild check-torch-mlir-all + - name: Build torch-mlir out-of-tree (smoke test) + # This step rebuilds torch in an out-of-tree setup, reusing the output of the previous + # build to avoid building LLVM twice. + run: | + cd $GITHUB_WORKSPACE + cmake . -GNinja -Bbuild-oot \ + -DCMAKE_LINKER=lld \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ + -DMLIR_DIR="$(pwd)/build/lib/cmake/mlir/" \ + -DLLVM_DIR="$(pwd)/build/lib/cmake/llvm/" \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DPython3_EXECUTABLE=$(which python) + ninja -Cbuild-oot #just build, no tests - name: RefBackend - TorchScript end-to-end tests run: | cd $GITHUB_WORKSPACE @@ -87,53 +118,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} with: release_id: ${{ github.event.inputs.release_id }} - - build-out-of-tree: - name: Build and Test out-of-tree (Release Asserts) - runs-on: ubuntu-20.04 - steps: - - name: Get torch-mlir - uses: actions/checkout@v2 - with: - submodules: 'true' - - uses: ./.github/actions/setup-build - - name: Build LLVM (standalone) - run: | - cd $GITHUB_WORKSPACE - cmake -Bllvm-build -GNinja \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_LINKER=lld \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ - -DPython3_EXECUTABLE=$(which python) \ - -DLLVM_ENABLE_ASSERTIONS=ON \ - -DLLVM_ENABLE_PROJECTS=mlir \ - -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ - -DLLVM_TARGETS_TO_BUILD=host \ - externals/llvm-project/llvm - ninja -Cllvm-build - - - name: Build and test torch-mlir (out-of-tree) - run: | - cd $GITHUB_WORKSPACE - cmake -GNinja -Bbuild \ - -DCMAKE_LINKER=lld \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ - -DMLIR_DIR="$(pwd)/llvm-build/lib/cmake/mlir/" \ - -DLLVM_DIR="$(pwd)/llvm-build/lib/cmake/llvm/" \ - -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ - -DPython3_EXECUTABLE=$(which python) \ - . - ninja -Cbuild check-torch-mlir-all - - - name: RefBackend - TorchScript end-to-end tests - run: | - cd $GITHUB_WORKSPACE - export PYTHONPATH="$GITHUB_WORKSPACE/build/python_packages/torch_mlir" - python -m e2e_testing.torchscript.main --config=refbackend -v - - name: TOSA backend - TorchScript end-to-end tests - run: | - cd $GITHUB_WORKSPACE - export PYTHONPATH="$GITHUB_WORKSPACE/build/python_packages/torch_mlir" - python -m e2e_testing.torchscript.main --config=tosa -v From c3988ae09a45f44a9b172743f2aad1d89a74d791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 13 Apr 2022 13:40:09 +0100 Subject: [PATCH 7/9] Revert "wip: Build OOT in same job" This reverts commit ee7ea19e46d66c3de1b219030ab6348c109a5bb5. --- .github/actions/setup-build/action.yml | 28 ++++++++ .github/workflows/buildAndTest.yml | 93 ++++++++++++++++---------- 2 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 .github/actions/setup-build/action.yml diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml new file mode 100644 index 000000000000..fe7df05ce305 --- /dev/null +++ b/.github/actions/setup-build/action.yml @@ -0,0 +1,28 @@ +name: "Setup build environment" +description: "Setup the build environment. An action so that it can be shared between in-tree/out-of-tree jobs" + +runs: + using: "composite" + steps: + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - name: Install MLIR Python depends + run: | + python -m pip install -r $GITHUB_WORKSPACE/externals/llvm-project/mlir/python/requirements.txt + shell: bash + - name: Install PyTorch nightly depends + run: | + python -m pip install -r requirements.txt + shell: bash + - name: Install Ninja + uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268 + - name: Get Submodule Hash + id: get-submodule-hash + run: echo "::set-output name=hash::$(md5sum $(git submodule status))" + shell: bash + - name: Ccache for C++ compilation + uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 + with: + key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index f45729c1e60c..79bcabd365fb 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -16,37 +16,20 @@ on: jobs: build: - name: Build and Test (Release Asserts) + name: Build and Test and maybe Publish (Release Asserts) runs-on: ubuntu-20.04 steps: - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.9 - name: Get torch-mlir uses: actions/checkout@v2 with: submodules: 'true' - - name: Install MLIR Python depends - run: | - python -m pip install -r $GITHUB_WORKSPACE/externals/llvm-project/mlir/python/requirements.txt - - name: Install PyTorch nightly depends - run: | - python -m pip install -r requirements.txt - - name: Install Ninja - uses: llvm/actions/install-ninja@55d844821959226fab4911f96f37071c1d4c3268 - - name: Get Submodule Hash - id: get-submodule-hash - run: echo "::set-output name=hash::$(md5sum $(git submodule status))" - shell: bash - - name: Ccache for C++ compilation - uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 - with: - key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} + - uses: ./.github/actions/setup-build - name: Build and Test torch-mlir (Assert) run: | cd $GITHUB_WORKSPACE - cmake externals/llvm-project/llvm -Bbuild -GNinja \ + mkdir build + cd build + cmake $GITHUB_WORKSPACE/externals/llvm-project/llvm -GNinja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_LINKER=lld \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ @@ -59,21 +42,7 @@ jobs: -DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="${GITHUB_WORKSPACE}/external/llvm-external-projects/torch-mlir-dialects" \ -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ -DLLVM_TARGETS_TO_BUILD=host - ninja -Cbuild check-torch-mlir-all - - name: Build torch-mlir out-of-tree (smoke test) - # This step rebuilds torch in an out-of-tree setup, reusing the output of the previous - # build to avoid building LLVM twice. - run: | - cd $GITHUB_WORKSPACE - cmake . -GNinja -Bbuild-oot \ - -DCMAKE_LINKER=lld \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ - -DMLIR_DIR="$(pwd)/build/lib/cmake/mlir/" \ - -DLLVM_DIR="$(pwd)/build/lib/cmake/llvm/" \ - -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ - -DPython3_EXECUTABLE=$(which python) - ninja -Cbuild-oot #just build, no tests + ninja check-torch-mlir-all - name: RefBackend - TorchScript end-to-end tests run: | cd $GITHUB_WORKSPACE @@ -118,3 +87,53 @@ jobs: GITHUB_TOKEN: ${{ secrets.WORKFLOW_INVOCATION_TOKEN }} with: release_id: ${{ github.event.inputs.release_id }} + + build-out-of-tree: + name: Build and Test out-of-tree (Release Asserts) + runs-on: ubuntu-20.04 + steps: + - name: Get torch-mlir + uses: actions/checkout@v2 + with: + submodules: 'true' + - uses: ./.github/actions/setup-build + - name: Build LLVM (standalone) + run: | + cd $GITHUB_WORKSPACE + cmake -Bllvm-build -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_LINKER=lld \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ + -DPython3_EXECUTABLE=$(which python) \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DLLVM_ENABLE_PROJECTS=mlir \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DLLVM_TARGETS_TO_BUILD=host \ + externals/llvm-project/llvm + ninja -Cllvm-build + + - name: Build and test torch-mlir (out-of-tree) + run: | + cd $GITHUB_WORKSPACE + cmake -GNinja -Bbuild \ + -DCMAKE_LINKER=lld \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ + -DMLIR_DIR="$(pwd)/llvm-build/lib/cmake/mlir/" \ + -DLLVM_DIR="$(pwd)/llvm-build/lib/cmake/llvm/" \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DPython3_EXECUTABLE=$(which python) \ + . + ninja -Cbuild check-torch-mlir-all + + - name: RefBackend - TorchScript end-to-end tests + run: | + cd $GITHUB_WORKSPACE + export PYTHONPATH="$GITHUB_WORKSPACE/build/python_packages/torch_mlir" + python -m e2e_testing.torchscript.main --config=refbackend -v + - name: TOSA backend - TorchScript end-to-end tests + run: | + cd $GITHUB_WORKSPACE + export PYTHONPATH="$GITHUB_WORKSPACE/build/python_packages/torch_mlir" + python -m e2e_testing.torchscript.main --config=tosa -v From 67720029dac43f7398d41c5e619b11e19e3e2ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 13 Apr 2022 14:26:38 +0100 Subject: [PATCH 8/9] Use distinct ccaches Since they run in distinct jobs, using the same ccache would cause one job to overwrite the cache of the other. --- .github/actions/setup-build/action.yml | 10 +++++++++- .github/workflows/buildAndTest.yml | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index fe7df05ce305..09690cfbf2e0 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -1,6 +1,14 @@ name: "Setup build environment" description: "Setup the build environment. An action so that it can be shared between in-tree/out-of-tree jobs" +inputs: + cache-key: + description: | + Additional string that is used to compute the ccache hash. + Different jobs running the action need distinct values for this key, + but the content is irrelevant. + required: true + runs: using: "composite" steps: @@ -25,4 +33,4 @@ runs: - name: Ccache for C++ compilation uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3 with: - key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }} + key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }}-${{ inputs.cache-key }} diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 79bcabd365fb..c9adc9a7cfc7 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -24,6 +24,8 @@ jobs: with: submodules: 'true' - uses: ./.github/actions/setup-build + with: + cache-key: 'in-tree' - name: Build and Test torch-mlir (Assert) run: | cd $GITHUB_WORKSPACE @@ -97,6 +99,8 @@ jobs: with: submodules: 'true' - uses: ./.github/actions/setup-build + with: + cache-key: 'out-of-tree' - name: Build LLVM (standalone) run: | cd $GITHUB_WORKSPACE From 8ea61c7624b70ffb66254cd101c5bd74bfb18fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 13 Apr 2022 16:19:20 +0100 Subject: [PATCH 9/9] Dummy commit test ccache, build should take 15mins --- .github/actions/setup-build/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index 09690cfbf2e0..52f7495d3bbb 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -4,9 +4,9 @@ description: "Setup the build environment. An action so that it can be shared be inputs: cache-key: description: | - Additional string that is used to compute the ccache hash. + Additional string that is used to compute the ccache hash. Different jobs running the action need distinct values for this key, - but the content is irrelevant. + but the content is irrelevant. required: true runs: