diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml index 826c16acd187..4cb234aa60c1 100644 --- a/.github/actions/setup-build/action.yml +++ b/.github/actions/setup-build/action.yml @@ -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: 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 }}- diff --git a/.github/workflows/RollPyTorch.yml b/.github/workflows/RollPyTorch.yml index d92c592f2150..8290566d4a4a 100644 --- a/.github/workflows/RollPyTorch.yml +++ b/.github/workflows/RollPyTorch.yml @@ -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: | diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index b5ece94d03cf..de041a9bf322 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -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 diff --git a/.github/workflows/buildRelease.yml b/.github/workflows/buildRelease.yml index 988d46214b9c..5c62fdc6fa28 100644 --- a/.github/workflows/buildRelease.yml +++ b/.github/workflows/buildRelease.yml @@ -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: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8587697bee20..5446c65a4b13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/build_tools/python_deploy/build_windows.ps1 b/build_tools/python_deploy/build_windows.ps1 deleted file mode 100644 index e3372ee431fa..000000000000 --- a/build_tools/python_deploy/build_windows.ps1 +++ /dev/null @@ -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" diff --git a/build_tools/python_deploy/build_windows_ci.ps1 b/build_tools/python_deploy/build_windows_ci.ps1 deleted file mode 100644 index 31fdd753e5a9..000000000000 --- a/build_tools/python_deploy/build_windows_ci.ps1 +++ /dev/null @@ -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" diff --git a/build_tools/python_deploy/build_windows_ci.sh b/build_tools/python_deploy/build_windows_ci.sh new file mode 100644 index 000000000000..f03d1bdfe919 --- /dev/null +++ b/build_tools/python_deploy/build_windows_ci.sh @@ -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"