ci: enable ccache on Windows (#1548)

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).
pull/1553/head
Ashay Rane 2022-11-03 12:17:22 -05:00 committed by GitHub
parent f847642495
commit 2846776897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 87 deletions

View File

@ -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"
@ -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: Ccache for C++ compilation
uses: hendrikmuhs/ccache-action@v1.2
- 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: 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 }}-

View File

@ -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: |

View File

@ -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' }}
@ -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

View File

@ -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
@ -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
@ -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:

View File

@ -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

View File

@ -1,24 +0,0 @@
# Uncomment if you want to install Python. GHA provides this
#Write-Host "Installing python"
#Start-Process choco 'install python --version=3.10.8' -wait -NoNewWindow
#Write-Host "python installation completed successfully"
#Write-Host "Reload environment variables"
#$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
#Write-Host "Reloaded environment variables"
Write-Host "Installing Build Dependencies"
python -m venv .\mlir_venv\
.\mlir_venv\Scripts\activate
pip install -r .\requirements.txt
Write-Host "Build Deps installation completed successfully"
Write-Host "Building torch-mlir"
$env:CMAKE_GENERATOR='Ninja'
$env:TORCH_MLIR_ENABLE_LTC='0'
python -m pip wheel -v -w wheelhouse ./ -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html -r whl-requirements.txt
Write-Host "Build completed successfully"

View File

@ -1,42 +0,0 @@
#Uncomment if you want to test locally. GHA provides Python
#Write-Host "Installing python"
#Start-Process choco 'install python --version=3.10.8' -wait -NoNewWindow
#Write-Host "python installation completed successfully"
#Write-Host "Reload environment variables"
#$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
#Write-Host "Reloaded environment variables"
Write-Host "Installing Build Dependencies"
python -m venv .\mlir_venv\
.\mlir_venv\Scripts\activate
pip install -r .\requirements.txt
Write-Host "Build Deps installation completed successfully"
Write-Host "Building torch-mlir"
#Start-Process cmake '-GNinja -Bbuild \
# -DCMAKE_BUILD_TYPE=Release \
# -DPython3_FIND_VIRTUALENV=ONLY \
# -DLLVM_ENABLE_PROJECTS=mlir \
# -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 \
# -DMLIR_ENABLE_BINDINGS_PYTHON=ON \
# -DLLVM_TARGETS_TO_BUILD=host \
# /externals/llvm-project/llvm'
#Write-Host "Build completed successfully"
Write-Host "Building torch-mlir"
$env:CMAKE_GENERATOR='Ninja'
$env:TORCH_MLIR_ENABLE_LTC='0'
python -m pip wheel -v -w wheelhouse ./ -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html -r whl-requirements.txt
Write-Host "Build completed successfully"
Write-Host "Testing torch-mlir"
$env:PYTHONPATH = "$PWD/build/cmake_build/tools/torch-mlir/python_packages/torch_mlir;$PWD/examples"
# Uncomment here to enable tests. TODO: Fix paths
#cmake --build cmake_build/build --target check-torch-mlir-all
Write-Host "Testing completed successfully"

View File

@ -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"