|
| 1 | +#!/bin/bash |
| 2 | +set -x |
| 3 | + |
| 4 | +VER_LLVM="llvmorg-13.0.0" |
| 5 | +VER_PYTORCH="v1.13.1" |
| 6 | +VER_TORCHVISION="v0.14.1" |
| 7 | +VER_TORCHAUDIO="v0.13.1" |
| 8 | +VER_IPEX="v1.13.100+cpu" |
| 9 | + |
| 10 | +# Check existance of required Linux commands |
| 11 | +which python > /dev/null 2>&1 |
| 12 | +if [[ $? -ne 0 ]]; then |
| 13 | + echo "Error: linux command \"python\" not found." |
| 14 | + exit 4 |
| 15 | +fi |
| 16 | +which git > /dev/null 2>&1 |
| 17 | +if [[ $? -ne 0 ]]; then |
| 18 | + echo "Error: linux command \"git\" not found." |
| 19 | + exit 5 |
| 20 | +fi |
| 21 | +env | grep CONDA_PREFIX > /dev/null 2>&1 |
| 22 | +CONDA=$? |
| 23 | + |
| 24 | +# Save current directory path |
| 25 | +BASEFOLDER=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 26 | +cd ${BASEFOLDER} |
| 27 | +# Checkout individual components |
| 28 | +if [ ! -d llvm-project ]; then |
| 29 | + git clone https://github.com/llvm/llvm-project.git |
| 30 | +fi |
| 31 | +if [ ! -d intel-extension-for-pytorch ]; then |
| 32 | + git clone https://github.com/intel/intel-extension-for-pytorch.git |
| 33 | +fi |
| 34 | + |
| 35 | +# Checkout required branch/commit and update submodules |
| 36 | +cd llvm-project |
| 37 | +git checkout ${VER_LLVM} |
| 38 | +git submodule sync |
| 39 | +git submodule update --init --recursive |
| 40 | +cd ../intel-extension-for-pytorch |
| 41 | +git checkout ${VER_IPEX} |
| 42 | +git submodule sync |
| 43 | +git submodule update --init --recursive |
| 44 | + |
| 45 | +# Install dependencies |
| 46 | +python -m pip install cmake |
| 47 | +python -m pip install torch==${VER_PYTORCH}+cpu torchvision==${VER_TORCHVISION}+cpu torchaudio==${VER_TORCHAUDIO}+cpu --extra-index-url https://download.pytorch.org/whl/cpu |
| 48 | +ABI=$(python -c "import torch; print(int(torch._C._GLIBCXX_USE_CXX11_ABI))") |
| 49 | + |
| 50 | +# Compile individual component |
| 51 | +# LLVM |
| 52 | +cd ../llvm-project |
| 53 | +git config --global --add safe.directory `pwd` |
| 54 | +if [ -d build ]; then |
| 55 | + rm -rf build |
| 56 | +fi |
| 57 | +mkdir build |
| 58 | +cd build |
| 59 | +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF ../llvm/ |
| 60 | +cmake --build . -j $(nproc) |
| 61 | +LLVM_ROOT=`pwd`/../release |
| 62 | +if [ -d ${LLVM_ROOT} ]; then |
| 63 | + rm -rf ${LLVM_ROOT} |
| 64 | +fi |
| 65 | +cmake -DCMAKE_INSTALL_PREFIX=${LLVM_ROOT}/../release/ -P cmake_install.cmake |
| 66 | +#xargs rm -rf < install_manifest.txt |
| 67 | +ln -s ${LLVM_ROOT}/bin/llvm-config ${LLVM_ROOT}/bin/llvm-config-13 |
| 68 | +export PATH=${LLVM_ROOT}/bin:$PATH |
| 69 | +export LD_LIBRARY_PATH=${LLVM_ROOT}/lib:$LD_LIBRARY_PATH |
| 70 | +cd .. |
| 71 | +git config --global --unset safe.directory |
| 72 | +# Intel® Extension for PyTorch* |
| 73 | +cd ../intel-extension-for-pytorch |
| 74 | +git config --global --add safe.directory `pwd` |
| 75 | +python -m pip install -r requirements.txt |
| 76 | +export USE_LLVM=${LLVM_ROOT} |
| 77 | +export LLVM_DIR=${USE_LLVM}/lib/cmake/llvm |
| 78 | +export DNNL_GRAPH_BUILD_COMPILER_BACKEND=1 |
| 79 | +python setup.py clean |
| 80 | +python setup.py bdist_wheel 2>&1 | tee build.log |
| 81 | +unset DNNL_GRAPH_BUILD_COMPILER_BACKEND |
| 82 | +unset LLVM_DIR |
| 83 | +unset USE_LLVM |
| 84 | +python -m pip install --force-reinstall dist/*.whl |
| 85 | +git config --global --unset safe.directory |
| 86 | + |
| 87 | +# Sanity Test |
| 88 | +cd .. |
| 89 | +python -c "import torch; import torchvision; import torchaudio; import intel_extension_for_pytorch as ipex; print(f'torch_cxx11_abi: {torch._C._GLIBCXX_USE_CXX11_ABI}'); print(f'torch_version: {torch.__version__}'); print(f'torchvision_version: {torchvision.__version__}'); print(f'torchaudio_version: {torchaudio.__version__}'); print(f'ipex_version: {ipex.__version__}');" |
0 commit comments