Skip to content

Commit

Permalink
ci: enable ccache on Windows (llvm#1548)
Browse files Browse the repository at this point in the history
This patch makes a few small, but key, changes to enable ccache on
Windows.  First, it replaces the hendrikmuhs/ccache-action action with
command line invocations to the ccache binary, since the action has two
bugs, one of which causes CI to refer to different ccache artifacts
before versus after the build on Windows whereas the other bug can
sometimes cause the action to incorrectly infer that the cache is empty.

Second, this patch slightly alters the cache key, so that our old cache
artifacts, which have grown too big, are eventually discarded in favor
of the new, smaller cache artifacts.  Along the way, this patch also
keeps the RollPyTorch's cache artifact separate from the regular build's
cache artifact so as to keep these artifacts small, and also because the
RollPyTorch action is off the critical path for most contributors.

Finally, this patch makes small changes to the CMake file so that on
Windows, the ccache binary is added as a prefix, as recommended on the
[ccache Wiki](https://github.com/ccache/ccache/wiki/MS-Visual-Studio).
  • Loading branch information
ashay authored Nov 3, 2022
1 parent f847642 commit 2846776
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 87 deletions.
39 changes: 27 additions & 12 deletions .github/actions/setup-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ inputs:
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
required: false
default: ''

runs:
using: "composite"
Expand All @@ -28,24 +29,38 @@ runs:
python -m pip install -r requirements.txt
shell: bash

- name: Install Ninja (Linux)
- name: Install prerequisites (Linux)
if: ${{ runner.os == 'Linux' }}
run: sudo apt-get install -y ninja-build
run: sudo apt-get install --yes ccache ninja-build
shell: bash

- name: Install Ninja (macOS)
- name: Install prerequisites (macOS)
if: ${{ runner.os == 'macOS' }}
run: brew install ninja
run: brew install ccache ninja
shell: bash

- name: Install Ninja (Windows)
- name: Install prerequisites (Windows)
if: ${{ runner.os == 'Windows' }}
run: pip install ninja
run: |
pip install ninja
choco install ccache --yes
shell: bash

- name: Configure ccache
run: |
rm -rf ${{ github.workspace }}/.ccache
mkdir -p ${{ github.workspace }}/.ccache
ccache --set-config "cache_dir=${{ github.workspace }}/.ccache"
ccache --set-config "compression=true"
ccache --set-config "max_size=300M"
ccache --zero-stats
shell: bash

- name: Ccache for C++ compilation
uses: hendrikmuhs/ccache-action@v1.2
- name: Enable ccache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-torch_mlir_build_assets-${{ inputs.cache-suffix }}
max-size: 300M
verbose: 2
path: ${{ github.workspace }}/.ccache
key: ${{ runner.os }}-${{ inputs.cache-suffix }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ inputs.cache-suffix }}-
${{ runner.os }}-
2 changes: 1 addition & 1 deletion .github/workflows/RollPyTorch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup ccache
uses: ./.github/actions/setup-build
with:
cache-suffix: x86_64-out-of-tree-OFF
cache-suffix: 'rollPyTorch'

- name: Determine nightly PyTorch version
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Setup ccache
uses: ./.github/actions/setup-build
with:
cache-suffix: ${{ matrix.os-arch }}-${{ matrix.llvm-build }}-${{ matrix.torch-binary }}
cache-suffix: 'build-${{ matrix.llvm-build }}'

- name: Set up Visual Studio shell
if: ${{ matrix.os-arch == 'windows-x86_64' }}
Expand Down Expand Up @@ -123,8 +123,8 @@ jobs:
if: ${{ matrix.os-arch == 'macos-arm64' }}
run: |
cmake --build build_arm64
- name: Build torch-mlir (Windows)
- name: Build (Windows)
if: ${{ matrix.os-arch == 'windows-x86_64' }}
shell: pwsh
run: |
./build_tools/python_deploy/build_windows_ci.ps1
shell: bash
run: ./build_tools/python_deploy/build_windows_ci.sh
6 changes: 3 additions & 3 deletions .github/workflows/buildRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
submodules: 'true'
- uses: ./.github/actions/setup-build
with:
cache-suffix: ''
cache-suffix: 'release'
- name: Build Python wheels and smoke test.
run: |
cd $GITHUB_WORKSPACE
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
submodules: 'true'
- uses: ./.github/actions/setup-build
with:
cache-suffix: ''
cache-suffix: 'release'
- name: Build Python wheels and smoke test.
run: |
cd $GITHUB_WORKSPACE
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
submodules: 'true'
- uses: ./.github/actions/setup-build
with:
cache-suffix: ''
cache-suffix: 'release'
- name: Set up Visual Studio shell
uses: egor-tensin/vs-shell@v2
with:
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ torch_mlir_add_llvm_external_project(

option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)

# Adjustments to use ccache on Windows
if (WIN32)
find_program(ccache_exe ccache)
if(ccache_exe)
file(COPY_FILE ${ccache_exe} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)
set(CMAKE_VS_GLOBALS
"CLToolExe=cl.exe"
"CLToolPath=${CMAKE_BINARY_DIR}"
"TrackFileAccess=false"
"UseMultiToolTask=true"
"DebugInformationFormat=OldStyle"
)
endif()
endif()

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR TORCH_MLIR_OUT_OF_TREE_BUILD)
message(STATUS "Torch-MLIR out-of-tree build.")
# Out-of-tree build
Expand Down
24 changes: 0 additions & 24 deletions build_tools/python_deploy/build_windows.ps1

This file was deleted.

42 changes: 0 additions & 42 deletions build_tools/python_deploy/build_windows_ci.ps1

This file was deleted.

21 changes: 21 additions & 0 deletions build_tools/python_deploy/build_windows_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

echo "Building torch-mlir"

cmake -GNinja -Bbuild \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_TARGETS_TO_BUILD=host \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DPython3_FIND_VIRTUALENV=ONLY \
-DLLVM_EXTERNAL_PROJECTS="torch-mlir;torch-mlir-dialects" \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
-DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="$PWD/externals/llvm-external-projects/torch-mlir-dialects" \
-DPython3_EXECUTABLE="$(which python)" \
$GITHUB_WORKSPACE/externals/llvm-project/llvm

cmake --build build

echo "Build completed successfully"

0 comments on commit 2846776

Please sign in to comment.