mirror of https://github.com/llvm/torch-mlir
Add linux and macOS source builds in CI (#1070)
This enables building Pytorch from source in the CI. The build should mostly hit the ccache. Release builds will follow once we have some runtime on the CI.pull/1103/head
parent
c0ef192865
commit
31fd812acf
|
@ -31,6 +31,7 @@ runs:
|
||||||
run: echo "::set-output name=hash::$(md5sum $(git submodule status))"
|
run: echo "::set-output name=hash::$(md5sum $(git submodule status))"
|
||||||
shell: bash
|
shell: bash
|
||||||
- name: Ccache for C++ compilation
|
- name: Ccache for C++ compilation
|
||||||
uses: hendrikmuhs/ccache-action@4687d037e4d7cf725512d9b819137a3af34d39b3
|
uses: hendrikmuhs/ccache-action@85bd285251b831e5a761d26e3dbfdbccbca1b23f
|
||||||
with:
|
with:
|
||||||
key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }}${{ inputs.cache-suffix }}
|
key: ${{ runner.os }}-clangreleaseasserts-${{ steps.get-submodule-hash.outputs.hash }}${{ inputs.cache-suffix }}
|
||||||
|
max-size: 2G
|
||||||
|
|
|
@ -103,3 +103,101 @@ jobs:
|
||||||
|
|
||||||
# Don't run python tests, as check-torch-mlir-all already checks
|
# Don't run python tests, as check-torch-mlir-all already checks
|
||||||
# what we want.
|
# what we want.
|
||||||
|
|
||||||
|
build-from-src:
|
||||||
|
name: Build and Test Source Build (Release Asserts)
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Get torch-mlir
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
|
- uses: ./.github/actions/setup-build
|
||||||
|
with:
|
||||||
|
cache-suffix: 'src-linux'
|
||||||
|
- name: Build and Test torch-mlir (Assert)
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
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 \
|
||||||
|
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
|
||||||
|
-DPython3_EXECUTABLE=$(which python) \
|
||||||
|
-DLLVM_ENABLE_ASSERTIONS=ON \
|
||||||
|
-DLLVM_ENABLE_PROJECTS=mlir \
|
||||||
|
-DLLVM_EXTERNAL_PROJECTS="torch-mlir;torch-mlir-dialects" \
|
||||||
|
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$GITHUB_WORKSPACE" \
|
||||||
|
-DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="${GITHUB_WORKSPACE}/external/llvm-external-projects/torch-mlir-dialects" \
|
||||||
|
-DTORCH_MLIR_ENABLE_MHLO=ON \
|
||||||
|
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
|
||||||
|
-DTORCH_MLIR_USE_INSTALLED_PYTORCH=OFF \
|
||||||
|
-DLLVM_TARGETS_TO_BUILD=host
|
||||||
|
ninja check-torch-mlir-all
|
||||||
|
- name: RefBackend - TorchScript end-to-end tests
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
export PYTHONPATH="$GITHUB_WORKSPACE/build/tools/torch-mlir/python_packages/torch_mlir"
|
||||||
|
python -m e2e_testing.torchscript.main --config=refbackend -v
|
||||||
|
- name: EagerMode - TorchScript end-to-end tests
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
export PYTHONPATH="$GITHUB_WORKSPACE/build/tools/torch-mlir/python_packages/torch_mlir"
|
||||||
|
python -m e2e_testing.torchscript.main --config=eager_mode -v
|
||||||
|
- name: TOSA backend - TorchScript end-to-end tests
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
export PYTHONPATH="$GITHUB_WORKSPACE/build/tools/torch-mlir/python_packages/torch_mlir"
|
||||||
|
python -m e2e_testing.torchscript.main --config=tosa -v
|
||||||
|
|
||||||
|
macOS-x86_64:
|
||||||
|
name: Build and Test macOS(x86_64) Build (Release Asserts)
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Get torch-mlir
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
|
- uses: ./.github/actions/setup-build
|
||||||
|
with:
|
||||||
|
cache-suffix: '-macos-x86_64'
|
||||||
|
- name: Build and Test torch-mlir (Assert)
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
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 \
|
||||||
|
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
|
||||||
|
-DPython3_EXECUTABLE=$(which python) \
|
||||||
|
-DLLVM_ENABLE_ASSERTIONS=ON \
|
||||||
|
-DLLVM_ENABLE_PROJECTS=mlir \
|
||||||
|
-DLLVM_EXTERNAL_PROJECTS="torch-mlir;torch-mlir-dialects" \
|
||||||
|
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$GITHUB_WORKSPACE" \
|
||||||
|
-DLLVM_EXTERNAL_TORCH_MLIR_DIALECTS_SOURCE_DIR="${GITHUB_WORKSPACE}/external/llvm-external-projects/torch-mlir-dialects" \
|
||||||
|
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
|
||||||
|
-DTORCH_MLIR_ENABLE_MHLO=ON \
|
||||||
|
-DTORCH_MLIR_USE_INSTALLED_PYTORCH=OFF \
|
||||||
|
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
|
||||||
|
-DMACOSX_DEPLOYMENT_TARGET=10.15 \
|
||||||
|
-DLLVM_TARGETS_TO_BUILD=host
|
||||||
|
ninja check-torch-mlir-all
|
||||||
|
- name: RefBackend - TorchScript end-to-end tests
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
export PYTHONPATH="$GITHUB_WORKSPACE/build/tools/torch-mlir/python_packages/torch_mlir"
|
||||||
|
python -m e2e_testing.torchscript.main --config=refbackend -v
|
||||||
|
- name: EagerMode - TorchScript end-to-end tests
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
export PYTHONPATH="$GITHUB_WORKSPACE/build/tools/torch-mlir/python_packages/torch_mlir"
|
||||||
|
python -m e2e_testing.torchscript.main --config=eager_mode -v
|
||||||
|
- name: TOSA backend - TorchScript end-to-end tests
|
||||||
|
run: |
|
||||||
|
cd $GITHUB_WORKSPACE
|
||||||
|
export PYTHONPATH="$GITHUB_WORKSPACE/build/tools/torch-mlir/python_packages/torch_mlir"
|
||||||
|
python -m e2e_testing.torchscript.main --config=tosa -v
|
||||||
|
|
|
@ -54,7 +54,7 @@ jobs:
|
||||||
|
|
||||||
build_macos:
|
build_macos:
|
||||||
name: MacOS Build
|
name: MacOS Build
|
||||||
runs-on: macos-latest
|
runs-on: macos-12
|
||||||
steps:
|
steps:
|
||||||
- name: Get torch-mlir
|
- name: Get torch-mlir
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
|
@ -9,7 +9,8 @@ PYTORCH_REPO="${PYTORCH_REPO:-pytorch/pytorch}"
|
||||||
PYTORCH_BRANCH="${PYTORCH_BRANCH:-master}"
|
PYTORCH_BRANCH="${PYTORCH_BRANCH:-master}"
|
||||||
PT_C_COMPILER="${PT_C_COMPILER:-clang}"
|
PT_C_COMPILER="${PT_C_COMPILER:-clang}"
|
||||||
PT_CXX_COMPILER="${PT_CXX_COMPILER:-clang++}"
|
PT_CXX_COMPILER="${PT_CXX_COMPILER:-clang++}"
|
||||||
CMAKE_OSX_ARCHITECTURES="${CMAKE_OSX_ARCHITECTURES:-arm64;x86_64}"
|
CMAKE_OSX_ARCHITECTURES="${CMAKE_OSX_ARCHITECTURES:-x86_64}"
|
||||||
|
MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-12.0}"
|
||||||
WHEELHOUSE="${WHEELHOUSE:-$SRC_ROOT/build_tools/python_deploy/wheelhouse}"
|
WHEELHOUSE="${WHEELHOUSE:-$SRC_ROOT/build_tools/python_deploy/wheelhouse}"
|
||||||
PYTHON_BIN="${TORCH_MLIR_PYTHON_VERSION:-python3}"
|
PYTHON_BIN="${TORCH_MLIR_PYTHON_VERSION:-python3}"
|
||||||
PIP_BIN="${TORCH_MLIR_PIP_VERSION:-pip3}"
|
PIP_BIN="${TORCH_MLIR_PIP_VERSION:-pip3}"
|
||||||
|
@ -25,8 +26,11 @@ echo "SRC_ROOT=${SRC_ROOT}"
|
||||||
echo "PYTORCH_ROOT=${PYTORCH_ROOT}"
|
echo "PYTORCH_ROOT=${PYTORCH_ROOT}"
|
||||||
echo "PYTORCH_REPO=${PYTORCH_REPO}"
|
echo "PYTORCH_REPO=${PYTORCH_REPO}"
|
||||||
echo "PYTORCH_BRANCH=${PYTORCH_BRANCH}"
|
echo "PYTORCH_BRANCH=${PYTORCH_BRANCH}"
|
||||||
|
echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}"
|
||||||
echo "CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}"
|
echo "CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}"
|
||||||
|
|
||||||
export CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
|
export CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
|
||||||
|
export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}
|
||||||
export CMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
|
export CMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
|
||||||
export CMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
|
export CMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
|
||||||
|
|
||||||
|
@ -46,11 +50,7 @@ checkout_pytorch() {
|
||||||
cd "$PYTORCH_ROOT"
|
cd "$PYTORCH_ROOT"
|
||||||
git reset --hard HEAD
|
git reset --hard HEAD
|
||||||
git clean -df
|
git clean -df
|
||||||
for dep in protobuf pocketfft cpuinfo FP16 psimd fmt sleef pybind11 onnx flatbuffers foxi; do
|
git submodule update --init --depth 1 --recursive
|
||||||
git submodule update --init --depth 1 -- third_party/$dep
|
|
||||||
done
|
|
||||||
# setup.py will try to re-fetch
|
|
||||||
sed -i.bak -E 's/^[[:space:]]+check_submodules()/#check_submodules()/g' setup.py
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_pytorch() {
|
build_pytorch() {
|
||||||
|
@ -68,9 +68,14 @@ build_pytorch() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BUILD_SHARED_LIBS=ON \
|
BUILD_SHARED_LIBS=ON \
|
||||||
|
BUILD_CAFFE2_OPS=OFF \
|
||||||
|
INTERN_BUILD_ATEN_OPS=OFF \
|
||||||
|
ATEN_NO_TEST=OFF \
|
||||||
|
USE_LITE_INTERPRETER_PROFILER=OFF \
|
||||||
BUILD_TEST=OFF \
|
BUILD_TEST=OFF \
|
||||||
GLIBCXX_USE_CXX11_ABI=1 \
|
GLIBCXX_USE_CXX11_ABI=1 \
|
||||||
CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} \
|
CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} \
|
||||||
|
MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} \
|
||||||
INTERN_BUILD_ATEN_OPS=OFF \
|
INTERN_BUILD_ATEN_OPS=OFF \
|
||||||
INTERN_DISABLE_ONNX=ON \
|
INTERN_DISABLE_ONNX=ON \
|
||||||
INTERN_USE_EIGEN_BLAS=ON \
|
INTERN_USE_EIGEN_BLAS=ON \
|
||||||
|
@ -78,11 +83,12 @@ build_pytorch() {
|
||||||
ONNX_ML=OFF \
|
ONNX_ML=OFF \
|
||||||
USE_BREAKPAD=OFF \
|
USE_BREAKPAD=OFF \
|
||||||
USE_CUDA=OFF \
|
USE_CUDA=OFF \
|
||||||
|
USE_ITT=OFF \
|
||||||
USE_DISTRIBUTED=OFF \
|
USE_DISTRIBUTED=OFF \
|
||||||
USE_EIGEN_FOR_BLAS=OFF \
|
USE_EIGEN_FOR_BLAS=OFF \
|
||||||
USE_FBGEMM=OFF \
|
USE_FBGEMM=ON \
|
||||||
USE_GLOO=OFF \
|
USE_GLOO=OFF \
|
||||||
USE_KINETO=OFF \
|
USE_KINETO=ON \
|
||||||
USE_MKL=OFF \
|
USE_MKL=OFF \
|
||||||
USE_MKLDNN=OFF \
|
USE_MKLDNN=OFF \
|
||||||
USE_MPS=OFF \
|
USE_MPS=OFF \
|
||||||
|
@ -90,7 +96,7 @@ build_pytorch() {
|
||||||
USE_NNPACK=OFF \
|
USE_NNPACK=OFF \
|
||||||
USE_OBSERVERS=OFF \
|
USE_OBSERVERS=OFF \
|
||||||
USE_OPENMP=OFF \
|
USE_OPENMP=OFF \
|
||||||
USE_PYTORCH_QNNPACK=OFF \
|
USE_PYTORCH_QNNPACK=ON \
|
||||||
USE_QNNPACK=OFF \
|
USE_QNNPACK=OFF \
|
||||||
USE_XNNPACK=OFF \
|
USE_XNNPACK=OFF \
|
||||||
${PYTHON_BIN} setup.py bdist_wheel -d "$WHEELHOUSE"
|
${PYTHON_BIN} setup.py bdist_wheel -d "$WHEELHOUSE"
|
||||||
|
@ -123,10 +129,24 @@ install_pytorch() {
|
||||||
${PIP_BIN} install --force-reinstall $WHEELHOUSE/*
|
${PIP_BIN} install --force-reinstall $WHEELHOUSE/*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unpack_pytorch() {
|
||||||
|
PYTHON_SITE=`${PYTHON_BIN} -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'`
|
||||||
|
pip uninstall torch
|
||||||
|
echo "wheel unpacking Pytorch..into ${PYTHON_SITE}"
|
||||||
|
wheel unpack -d "$WHEELHOUSE"/unpack_tmp "$WHEELHOUSE"/*.whl
|
||||||
|
mv "$WHEELHOUSE"/unpack_tmp/* "$PYTHON_SITE"/
|
||||||
|
}
|
||||||
|
|
||||||
#main
|
#main
|
||||||
echo "Building libtorch from source"
|
echo "Building libtorch from source"
|
||||||
checkout_pytorch
|
checkout_pytorch
|
||||||
install_requirements
|
install_requirements
|
||||||
build_pytorch
|
build_pytorch
|
||||||
package_pytorch
|
package_pytorch
|
||||||
install_pytorch
|
if [[ $CMAKE_OSX_ARCHITECTURES = "arm64" ]]; then
|
||||||
|
echo "${Yellow} Cross compiling for arm64 so unpacking PyTorch wheel for libs${NC}"
|
||||||
|
unpack_pytorch
|
||||||
|
else
|
||||||
|
echo "${Green} Installing the built PyTorch wheel ${NC}"
|
||||||
|
install_pytorch
|
||||||
|
fi
|
||||||
|
|
|
@ -65,6 +65,7 @@ option(TORCH_MLIR_USE_INSTALLED_PYTORCH "Build from local PyTorch in environment
|
||||||
if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER)
|
if(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER)
|
||||||
if (NOT TORCH_MLIR_USE_INSTALLED_PYTORCH)
|
if (NOT TORCH_MLIR_USE_INSTALLED_PYTORCH)
|
||||||
# Source builds
|
# Source builds
|
||||||
|
set(ENV{MACOSX_DEPLOYMENT_TARGET} ${MACOSX_DEPLOYMENT_TARGET})
|
||||||
set(ENV{CMAKE_OSX_ARCHITECTURES} ${CMAKE_OSX_ARCHITECTURES})
|
set(ENV{CMAKE_OSX_ARCHITECTURES} ${CMAKE_OSX_ARCHITECTURES})
|
||||||
set(ENV{CMAKE_C_COMPILER_LAUNCHER} ${CMAKE_C_COMPILER_LAUNCHER})
|
set(ENV{CMAKE_C_COMPILER_LAUNCHER} ${CMAKE_C_COMPILER_LAUNCHER})
|
||||||
set(ENV{CMAKE_CXX_COMPILER_LAUNCHER} ${CMAKE_CXX_COMPILER_LAUNCHER})
|
set(ENV{CMAKE_CXX_COMPILER_LAUNCHER} ${CMAKE_CXX_COMPILER_LAUNCHER})
|
||||||
|
|
|
@ -7,6 +7,7 @@ import typing
|
||||||
import torch
|
import torch
|
||||||
from torch_mlir.dialects.torch.importer.jit_ir import ModuleBuilder
|
from torch_mlir.dialects.torch.importer.jit_ir import ModuleBuilder
|
||||||
|
|
||||||
|
# UNSUPPORTED: system-darwin
|
||||||
# RUN: %PYTHON %s | torch-mlir-opt | FileCheck %s
|
# RUN: %PYTHON %s | torch-mlir-opt | FileCheck %s
|
||||||
|
|
||||||
mb = ModuleBuilder()
|
mb = ModuleBuilder()
|
||||||
|
|
Loading…
Reference in New Issue