-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After a lot of trial and error it has a good balance of working static library. In the future we can cull it further Linux jit_ir tracer and eager mode to libtorch.a so we can ship to pypi with a hermtic package. Remove any python level probing
- Loading branch information
Showing
7 changed files
with
144 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
.ipynb_checkpoints | ||
*.venv/ | ||
mlir_venv/ | ||
externals/pytorch/ | ||
libtorch* | ||
|
||
/build/ | ||
__pycache__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -xe pipefail | ||
|
||
SRC_ROOT="$( cd "$(dirname "$0")" ; pwd -P)/.." | ||
PYTORCH_ROOT=${PYTORCH_ROOT:-$SRC_ROOT/externals/pytorch} | ||
PYTORCH_INSTALL_PATH=${PYTORCH_INSTALL_PATH:-$SRC_ROOT/libtorch} | ||
PYTORCH_BRANCH="${PYTORCH_BRANCH:-master}" | ||
LIBTORCH_VARIANT="${LIBTORCH_VARIANT:-static-without-deps}" | ||
PT_C_COMPILER="${PT_C_COMPILER:-clang}" | ||
PT_CXX_COMPILER="${PT_CXX_COMPILER:-clang++}" | ||
|
||
echo "SRC_ROOT=${SRC_ROOT}" | ||
echo "PYTORCH_ROOT=${PYTORCH_ROOT}" | ||
echo "PYTORCH_BRANCH=${PYTORCH_BRANCH}" | ||
echo "LIBTORCH_VARIANT=${LIBTORCH_VARIANT}" | ||
|
||
if [[ "$LIBTORCH_VARIANT" == *"cxx11-abi"* ]]; then | ||
echo _GLIBCXX_USE_CXX11_ABI=1 | ||
export _GLIBCXX_USE_CXX11_ABI=1 | ||
CXX_ABI=1 | ||
LIBTORCH_ABI="cxx11-abi-" | ||
else | ||
echo _GLIBCXX_USE_CXX11_ABI=0 | ||
export _GLIBCXX_USE_CXX11_ABI=0 | ||
CXX_ABI=0 | ||
LIBTORCH_ABI= | ||
fi | ||
|
||
retry () { | ||
$* || (sleep 1 && $*) || (sleep 2 && $*) || (sleep 4 && $*) || (sleep 8 && $*) | ||
} | ||
|
||
install_requirements() { | ||
pip install -qr $PYTORCH_ROOT/requirements.txt | ||
pip list | ||
} | ||
|
||
# Check for an existing libtorch at $PYTORCH_ROOT | ||
# Download and unzip into externals/pytorch/libtorch | ||
# macOS x86_64 https://download.pytorch.org/libtorch/nightly/cpu/libtorch-macos-latest.zip | ||
# Download here (Pre-cxx11 ABI): https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip | ||
# Download here (cxx11 ABI): https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-shared-with-deps-latest.zip | ||
# Download static here (cxx11 ABI): https://download.pytorch.org/libtorch/nightly/cpu/libtorch-cxx11-abi-static-with-deps-latest.zip | ||
# static builds are broken upstream | ||
check_existing_libtorch() { | ||
if [[ -f "$PYTORCH_INSTALL_PATH/lib/libtorch.so" ]]; then | ||
echo "Existing PYTORCH shared build found.. skipping build" | ||
return 0 | ||
elif [[ -f "$PYTORCH_INSTALL_PATH/lib/libtorch.a" ]]; then | ||
echo "Existing PYTORCH static build found.. skipping build" | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
|
||
checkout_pytorch() { | ||
if [[ ! -d "$PYTORCH_ROOT" ]]; then | ||
git clone https://github.com/pytorch/pytorch $PYTORCH_ROOT | ||
fi | ||
cd $PYTORCH_ROOT | ||
git fetch --all | ||
git checkout ${PYTORCH_BRANCH} | ||
git submodule update --init --recursive | ||
} | ||
|
||
build_pytorch() { | ||
BUILD_SHARED_VAR="ON" | ||
if [[ $LIBTORCH_VARIANT = *"static"* ]]; then | ||
BUILD_SHARED_VAR="OFF" | ||
fi | ||
cd $PYTORCH_ROOT | ||
BUILD_SHARED_LIBS=${BUILD_SHARED_VAR} BUILD_TESTS=OFF USE_GLOO=OFF USE_PYTORCH_QNNPACK=OFF USE_OPENMP=OFF USE_OBSERVERS=OFF USE_KINETO=OFF USE_EIGEN_FOR_BLAS=OFF _GLIBCXX_USE_CXX11_ABI=${CXX_ABI} USE_NCCL=OFF INTERN_DISABLE_ONNX=OFF BUILD_PYTHONLESS=1 USE_CUDA=OFF USE_MKL=OFF USE_XNNPACK=OFF USE_DISTRIBUTED=OFF USE_BREAKPAD=OFF USE_MKLDNN=OFF USE_QNNPACK=OFF USE_NNPACK=OFF ONNX_ML=OFF python setup.py build | ||
} | ||
|
||
package_pytorch() { | ||
mkdir -p libtorch/{lib,bin,include,share} | ||
|
||
# Copy over all lib files | ||
cp -rv build/lib/* libtorch/lib/ | ||
cp -rv build/lib*/torch/lib/* libtorch/lib/ | ||
|
||
# Copy over all include files | ||
cp -rv build/include/* libtorch/include/ | ||
cp -rv build/lib*/torch/include/* libtorch/include/ | ||
|
||
# Copy over all of the cmake files | ||
cp -rv build/lib*/torch/share/* libtorch/share/ | ||
|
||
echo "${PYTORCH_BUILD_VERSION}" > libtorch/build-version | ||
echo "$(pushd $PYTORCH_ROOT && git rev-parse HEAD)" > libtorch/build-hash | ||
echo "Installing libtorch in ${PYTORCH_ROOT}/../../" | ||
rm -rf ${PYTORCH_ROOT}/../../libtorch | ||
mv libtorch ${PYTORCH_ROOT}/../../ | ||
} | ||
|
||
if check_existing_libtorch; then | ||
echo "Found libtorch" | ||
else | ||
echo "Building libtorch.." | ||
checkout_pytorch | ||
install_requirements | ||
build_pytorch | ||
package_pytorch | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 0 additions & 100 deletions
100
python/torch_mlir/dialects/torch/importer/jit_ir/cmake/modules/TorchMLIRPyTorch.cmake
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters