2022-04-21 17:19:12 +08:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright 2022 The IREE Authors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
|
|
|
# build_macos_packages.sh
|
2024-08-22 21:43:20 +08:00
|
|
|
# One stop build of torch-mlir Python packages for MacOS. This presumes that
|
2022-04-21 17:19:12 +08:00
|
|
|
# dependencies are installed from install_macos_deps.sh. This will build
|
|
|
|
# for a list of Python versions synchronized with that script and corresponding
|
|
|
|
# with directory names under:
|
|
|
|
# /Library/Frameworks/Python.framework/Versions
|
|
|
|
#
|
|
|
|
# MacOS convention is to refer to this as major.minor (i.e. "3.9", "3.10").
|
|
|
|
# Valid packages:
|
|
|
|
# torch-mlir
|
|
|
|
|
|
|
|
set -eu -o errtrace
|
|
|
|
|
2022-07-07 05:39:30 +08:00
|
|
|
this_dir="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
repo_root="$(cd "$this_dir"/../../ && pwd)"
|
2023-02-10 23:16:37 +08:00
|
|
|
python_versions="${TORCH_MLIR_PYTHON_VERSIONS:-3.9 3.10 3.11}"
|
2022-04-21 17:19:12 +08:00
|
|
|
output_dir="${output_dir:-${this_dir}/wheelhouse}"
|
2023-03-06 14:13:33 +08:00
|
|
|
packages="${packages:-torch-mlir}"
|
2022-04-21 17:19:12 +08:00
|
|
|
|
2022-07-07 05:39:30 +08:00
|
|
|
PKG_VER_FILE="${repo_root}"/torch_mlir_package_version ; [ -f "$PKG_VER_FILE" ] && . "$PKG_VER_FILE"
|
2022-04-26 05:13:17 +08:00
|
|
|
export TORCH_MLIR_PYTHON_PACKAGE_VERSION="${TORCH_MLIR_PYTHON_PACKAGE_VERSION:-0.0.1}"
|
|
|
|
echo "Setting torch-mlir Python Package version to: ${TORCH_MLIR_PYTHON_PACKAGE_VERSION}"
|
|
|
|
|
2022-04-21 17:19:12 +08:00
|
|
|
# Note that this typically is selected to match the version that the official
|
|
|
|
# Python distributed is built at.
|
2024-08-22 21:43:20 +08:00
|
|
|
export MACOSX_DEPLOYMENT_TARGET="${TORCH_MLIR_OSX_TARGET:-11.1}"
|
2022-05-03 00:04:12 +08:00
|
|
|
export CMAKE_OSX_ARCHITECTURES="${TORCH_MLIR_OSX_ARCH:-arm64;x86_64}"
|
|
|
|
echo "CMAKE_OSX_ARCHITECTURES: $CMAKE_OSX_ARCHITECTURES"
|
|
|
|
echo "MACOSX_DEPLOYMENT_TARGET $MACOSX_DEPLOYMENT_TARGET"
|
2022-04-21 17:19:12 +08:00
|
|
|
|
2022-08-20 03:25:00 +08:00
|
|
|
# Disable LTC build on MacOS to avoid linkage issues
|
|
|
|
# https://github.com/llvm/torch-mlir/issues/1253
|
|
|
|
export TORCH_MLIR_ENABLE_LTC=0
|
|
|
|
|
2022-04-21 17:19:12 +08:00
|
|
|
function run() {
|
|
|
|
echo "Using python versions: ${python_versions}"
|
|
|
|
|
|
|
|
local orig_path="$PATH"
|
|
|
|
|
|
|
|
# Build phase.
|
|
|
|
for package in $packages; do
|
|
|
|
echo "******************** BUILDING PACKAGE ${package} ********************"
|
|
|
|
for python_version in $python_versions; do
|
|
|
|
python_dir="/Library/Frameworks/Python.framework/Versions/$python_version"
|
|
|
|
if ! [ -x "$python_dir/bin/python3" ]; then
|
|
|
|
echo "ERROR: Could not find python3: $python_dir (skipping)"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
export PATH=$python_dir/bin:$orig_path
|
|
|
|
echo ":::: Python version $(python3 --version)"
|
|
|
|
case "$package" in
|
|
|
|
torch-mlir)
|
2022-07-07 05:39:30 +08:00
|
|
|
clean_wheels torch_mlir "$python_version"
|
|
|
|
build_torch_mlir torch_mlir "$python_version"
|
|
|
|
run_audit_wheel torch_mlir "$python_version"
|
2022-04-21 17:19:12 +08:00
|
|
|
;;
|
2023-03-07 14:20:06 +08:00
|
|
|
torch-mlir-core)
|
|
|
|
clean_wheels torch_mlir_core "$python_version"
|
|
|
|
build_torch_mlir_core torch_mlir_core "$python_version"
|
|
|
|
run_audit_wheel torch_mlir_core "$python_version"
|
2023-03-06 02:23:43 +08:00
|
|
|
;;
|
2022-04-21 17:19:12 +08:00
|
|
|
*)
|
|
|
|
echo "Unrecognized package '$package'"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_torch_mlir() {
|
2022-05-13 07:39:35 +08:00
|
|
|
local wheel_basename="$1"
|
|
|
|
local python_version="$2"
|
2022-07-07 05:39:30 +08:00
|
|
|
rm -rf "$output_dir"/build_venv
|
|
|
|
python"${python_version}" -m venv "$output_dir"/build_venv
|
|
|
|
source "$output_dir"/build_venv/bin/activate
|
|
|
|
python"${python_version}" -m pip install -U pip
|
2023-02-14 11:22:09 +08:00
|
|
|
python"${python_version}" -m pip install -r "$repo_root"/pytorch-requirements.txt --extra-index-url https://download.pytorch.org/whl/nightly/cpu
|
|
|
|
python"${python_version}" -m pip install -r "$repo_root"/build-requirements.txt
|
2022-04-21 17:19:12 +08:00
|
|
|
CMAKE_GENERATOR=Ninja \
|
2022-04-26 05:13:17 +08:00
|
|
|
TORCH_MLIR_PYTHON_PACKAGE_VERSION=${TORCH_MLIR_PYTHON_PACKAGE_VERSION} \
|
2022-05-03 00:04:12 +08:00
|
|
|
MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET \
|
|
|
|
CMAKE_OSX_ARCHITECTURES=$CMAKE_OSX_ARCHITECTURES \
|
2024-08-22 21:43:20 +08:00
|
|
|
python"${python_version}" -m pip wheel -v --no-build-isolation -w "$output_dir" "$repo_root" --extra-index-url https://download.pytorch.org/whl/nightly/cpu
|
2022-05-13 07:39:35 +08:00
|
|
|
deactivate
|
2022-07-07 05:39:30 +08:00
|
|
|
rm -rf "$output_dir"/build_venv
|
2022-04-21 17:19:12 +08:00
|
|
|
}
|
|
|
|
|
2023-03-07 14:20:06 +08:00
|
|
|
function build_torch_mlir_core() {
|
2023-03-06 02:23:43 +08:00
|
|
|
local wheel_basename="$1"
|
|
|
|
local python_version="$2"
|
|
|
|
rm -rf "$output_dir"/build_venv
|
|
|
|
python"${python_version}" -m venv "$output_dir"/build_venv
|
|
|
|
source "$output_dir"/build_venv/bin/activate
|
|
|
|
python"${python_version}" -m pip install -U pip delocate
|
|
|
|
python"${python_version}" -m pip install -r "$repo_root"/build-requirements.txt
|
|
|
|
CMAKE_GENERATOR=Ninja \
|
|
|
|
TORCH_MLIR_PYTHON_PACKAGE_VERSION=${TORCH_MLIR_PYTHON_PACKAGE_VERSION} \
|
|
|
|
MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET \
|
|
|
|
CMAKE_OSX_ARCHITECTURES=$CMAKE_OSX_ARCHITECTURES \
|
|
|
|
TORCH_MLIR_ENABLE_JIT_IR_IMPORTER=0 \
|
|
|
|
TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS=1 \
|
2024-08-22 21:43:20 +08:00
|
|
|
python"${python_version}" -m pip wheel -v --no-build-isolation -w "$output_dir" "$repo_root"
|
2023-03-06 02:23:43 +08:00
|
|
|
deactivate
|
|
|
|
rm -rf "$output_dir"/build_venv
|
|
|
|
}
|
|
|
|
|
2022-04-21 17:19:12 +08:00
|
|
|
function clean_wheels() {
|
|
|
|
local wheel_basename="$1"
|
|
|
|
local python_version="$2"
|
|
|
|
echo ":::: Clean wheels $wheel_basename $python_version"
|
2022-07-07 05:39:30 +08:00
|
|
|
rm -rf "$repo_root"/build/
|
|
|
|
rm -f "$output_dir"/"${wheel_basename}"-*-"${python_version//./}"-*.whl
|
2022-05-13 05:16:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_audit_wheel() {
|
|
|
|
set +x
|
|
|
|
local wheel_basename="$1"
|
|
|
|
local python_version="$2"
|
2022-07-07 05:39:30 +08:00
|
|
|
generic_wheel=$(ls "$output_dir"/"${wheel_basename}"-* | grep "${python_version//./}")
|
2022-05-13 05:16:32 +08:00
|
|
|
echo "Looking for $generic_wheel"
|
|
|
|
if [ -f "$generic_wheel" ]; then
|
|
|
|
echo "$generic_wheel found. Delocating it.."
|
2022-07-07 05:39:30 +08:00
|
|
|
rm -rf "$output_dir"/test_venv
|
|
|
|
python"${python_version}" -m venv "$output_dir"/test_venv
|
|
|
|
source "$output_dir"/test_venv/bin/activate
|
|
|
|
python"${python_version}" -m pip install -U pip
|
2023-02-14 11:22:09 +08:00
|
|
|
python"${python_version}" -m pip install -r "$repo_root"/pytorch-requirements.txt --extra-index-url https://download.pytorch.org/whl/nightly/cpu
|
|
|
|
python"${python_version}" -m pip install -r "$repo_root"/build-requirements.txt
|
2022-07-07 05:39:30 +08:00
|
|
|
python"${python_version}" -m pip install "$generic_wheel" --extra-index-url https://download.pytorch.org/whl/nightly/cpu
|
2022-07-16 10:51:59 +08:00
|
|
|
DYLD_LIBRARY_PATH="$output_dir"/test_venv/lib/python"${python_version}"/site-packages/torch/lib delocate-wheel -v "$generic_wheel"
|
2022-05-13 05:16:32 +08:00
|
|
|
deactivate
|
2022-07-07 05:39:30 +08:00
|
|
|
rm -rf "$output_dir"/test_venv
|
2022-05-13 05:16:32 +08:00
|
|
|
fi
|
2022-04-21 17:19:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
run
|