Skip to content

Commit

Permalink
compile
Browse files Browse the repository at this point in the history
  • Loading branch information
zhewang1-intc committed Sep 22, 2023
1 parent 1bcb28c commit d75a4d1
Show file tree
Hide file tree
Showing 16 changed files with 369 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Diagnostics:
Suppress: [attribute_wrong_number_arguments, builtin_definition]
CompileFlags:
Add: -fgnuc-version=12.2.0
InlayHints:
Designators: Yes
Enabled: Yes
ParameterNames: Yes
DeducedTypes: Yes
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ intel_extension_for_pytorch/_version.py
csrc/utils/version.h

cscope.*

# Roo t level file used in CI to specify certain env configs.
# E.g ., see .circleci/config.yaml
env
.circ leci/scripts/COMMIT_MSG
env
.circ leci/scripts/COMMIT_MSG

# IPython notebook checkpoints
.ipynb_checkpoints
Expand Down Expand Up @@ -188,6 +188,7 @@ docs/source/scripts/activation_images/

# build, distribute, and bins (+ python proto bindings)
build
build2
build_host_protoc
build_android
build_ios
Expand All @@ -207,7 +208,6 @@ aten/build/*
.clang-format-bin/
.clang-tidy-bin/


# Bram
plsdontbreak

Expand Down Expand Up @@ -248,8 +248,9 @@ TAGS
# Below files are not deleted by "setup.py clean".

# Visual Studio Code files
.vscode
# .vscode
.vs
.cache

# YouCompleteMe config file
.ycm_extra_conf.py
Expand Down
11 changes: 11 additions & 0 deletions .vscode/cmake-tools-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"name": "ipex",
"environmentSetupScript": "/home/wangzhe/zhe/intel-extension-for-pytorch/env_init.sh",
"compilers": {
"C": "/home/wangzhe/.local/envs/zhe_ipex/bin/gcc",
"CXX": "/home/wangzhe/.local/envs/zhe_ipex/bin/g++"
},
"isTrusted": true
}
]
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"args": [
"bdist_wheel"
],
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"preLaunchTask": "sourceScript"
},
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/wangzhe/.local/envs/zhe_ipex/bin/python",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "/home/wangzhe/.local/envs/zhe_ipex/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
38 changes: 38 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"cmake.configureArgs": [
"-DBUILD_MODULE_TYPE=CPU",
"-DBUILD_WITH_XPU=OFF",
"-DCMAKE_BUILD_TYPE=Debug",
"-DCMAKE_INSTALL_LIBDIR=lib",
"-DCMAKE_INSTALL_PREFIX=/home/wangzhe/zhe/intel-extension-for-pytorch/build/Debug/packages/intel_extension_for_pytorch",
"-DCMAKE_PREFIX_PATH=/home/wangzhe/.local/envs/zhe_ipex/lib/python3.9/site-packages/torch/share/cmake",
"-DCMAKE_PROJECT_VERSION=2.2.0",
"-DIPEX_PROJ_NAME=intel_extension_for_pytorch",
"-DLIBIPEX_GITREV=969e67bf8",
"-DLIBIPEX_VERSION=2.2.0+git969e67b",
"-DPYTHON_EXECUTABLE=/home/wangzhe/.local/envs/zhe_ipex/bin/python",
"-DPYTHON_INCLUDE_DIR=/home/wangzhe/.local/envs/zhe_ipex/include/python3.9",
"-DPYTHON_PLATFORM_INFO=Linux-5.16.0-rc1-intel-next-00543-g5867b0a2a125-x86_64-with-glibc2.28",
],
"cmake.buildDirectory": "${workspaceFolder}/build",
"clangd.arguments": [
"--log=verbose",
"--header-insertion=iwyu",
"--query-driver=/home/wangzhe/.local/envs/zhe_ipex/bin/g++*",
// 在后台自动分析文件(基于complie_commands)
"--background-index",
// 同时开启的任务数量
"-j=12",
// clang-tidy功能
"--clang-tidy",
"--clang-tidy-checks=performance-*,bugprone-*",
// 全局补全(会自动补充头文件)
"--all-scopes-completion",
// 更详细的补全内容
"--completion-style=detailed",
// 补充头文件的形式
"--header-insertion=iwyu",
// pch优化的位置
"--pch-storage=disk",
],
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "sourceScript",
"type": "shell",
"command": "source env_init.sh"
}
]
}
54 changes: 54 additions & 0 deletions compile_bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -x
set -e

VER_LLVM="llvmorg-13.0.0"
VER_PYTORCH=""
VER_TORCHVISION=""
VER_TORCHAUDIO=""
VER_IPEX="v2.0.100+cpu"

# Check existance of required Linux commands
for CMD in gcc g++ python git nproc; do
command -v ${CMD} || (
echo "Error: Command \"${CMD}\" not found."
exit 4
)
done
echo "You are using GCC: $(gcc --version | grep gcc)"

MAX_JOBS_VAR=$(nproc)
if [ ! -z "${MAX_JOBS}" ]; then
MAX_JOBS_VAR=${MAX_JOBS}
fi

# Save current directory path
BASEFOLDER=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cd ${BASEFOLDER}

ABI=$(python -c "import torch; print(int(torch._C._GLIBCXX_USE_CXX11_ABI))")

# Compile individual component
# LLVM
cd llvm-project

LLVM_ROOT="$(pwd)/release"
# ln -s ${LLVM_ROOT}/bin/llvm-config ${LLVM_ROOT}/bin/llvm-config-13
export PATH=${LLVM_ROOT}/bin:$PATH
export LD_LIBRARY_PATH=${LLVM_ROOT}/lib:$LD_LIBRARY_PATH
# Intel® Extension for PyTorch*
cd ../intel-extension-for-pytorch
python -m pip install -r requirements.txt
export USE_LLVM=${LLVM_ROOT}
export LLVM_DIR=${USE_LLVM}/lib/cmake/llvm
export DNNL_GRAPH_BUILD_COMPILER_BACKEND=1
# python setup.py clean
python setup.py bdist_wheel 2>&1 | tee build.log
unset DNNL_GRAPH_BUILD_COMPILER_BACKEND
unset LLVM_DIR
unset USE_LLVM
python -m pip install --force-reinstall dist/*.whl

# Sanity Test
cd ..
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__}');"
87 changes: 87 additions & 0 deletions compile_bundle_bk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
set -x
set -e

VER_LLVM="llvmorg-13.0.0"
VER_PYTORCH=""
VER_TORCHVISION=""
VER_TORCHAUDIO=""
VER_IPEX="v2.0.100+cpu"

# Check existance of required Linux commands
for CMD in gcc g++ python git nproc; do
command -v ${CMD} || (echo "Error: Command \"${CMD}\" not found." ; exit 4)
done
echo "You are using GCC: $(gcc --version | grep gcc)"

MAX_JOBS_VAR=$(nproc)
if [ ! -z "${MAX_JOBS}" ]; then
MAX_JOBS_VAR=${MAX_JOBS}
fi

# Save current directory path
BASEFOLDER=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd ${BASEFOLDER}
# Checkout individual components
if [ ! -d llvm-project ]; then
git clone https://github.com/llvm/llvm-project.git
fi
if [ ! -d intel-extension-for-pytorch ]; then
git clone https://github.com/intel/intel-extension-for-pytorch.git
fi

# Checkout required branch/commit and update submodules
cd llvm-project
if [ ! -z ${VER_LLVM} ]; then
git checkout ${VER_LLVM}
fi
git submodule sync
git submodule update --init --recursive
cd ../intel-extension-for-pytorch
if [ ! -z ${VER_IPEX} ]; then
git checkout ${VER_IPEX}
fi
git submodule sync
git submodule update --init --recursive

# Install dependencies
python -m pip install cmake
python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
ABI=$(python -c "import torch; print(int(torch._C._GLIBCXX_USE_CXX11_ABI))")

# Compile individual component
# LLVM
cd ../llvm-project
if [ -d build ]; then
rm -rf build
fi
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=${ABI}" -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF ../llvm/
cmake --build . -j ${MAX_JOBS_VAR}
LLVM_ROOT="$(pwd)/../release"
if [ -d ${LLVM_ROOT} ]; then
rm -rf ${LLVM_ROOT}
fi
cmake -DCMAKE_INSTALL_PREFIX=${LLVM_ROOT}/../release/ -P cmake_install.cmake
#xargs rm -rf < install_manifest.txt
ln -s ${LLVM_ROOT}/bin/llvm-config ${LLVM_ROOT}/bin/llvm-config-13
export PATH=${LLVM_ROOT}/bin:$PATH
export LD_LIBRARY_PATH=${LLVM_ROOT}/lib:$LD_LIBRARY_PATH
cd ..
# Intel® Extension for PyTorch*
cd ../intel-extension-for-pytorch
python -m pip install -r requirements.txt
export USE_LLVM=${LLVM_ROOT}
export LLVM_DIR=${USE_LLVM}/lib/cmake/llvm
export DNNL_GRAPH_BUILD_COMPILER_BACKEND=1
python setup.py clean
python setup.py bdist_wheel 2>&1 | tee build.log
unset DNNL_GRAPH_BUILD_COMPILER_BACKEND
unset LLVM_DIR
unset USE_LLVM
python -m pip install --force-reinstall dist/*.whl

# Sanity Test
cd ..
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__}');"
11 changes: 11 additions & 0 deletions csrc/.vscode/cmake-tools-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"name": "ipex",
"environmentSetupScript": "/home/wangzhe/zhe/intel-extension-for-pytorch/env_init.sh",
"compilers": {
"C": "/home/wangzhe/.local/envs/zhe_ipex/bin/gcc",
"CXX": "/home/wangzhe/.local/envs/zhe_ipex/bin/g++"
},
"isTrusted": true
}
]
36 changes: 36 additions & 0 deletions csrc/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"args": [
"bdist_wheel"
],
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"preLaunchTask": "sourceScript"
},
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/home/wangzhe/.local/envs/zhe_ipex/bin/python",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "/home/wangzhe/.local/envs/zhe_ipex/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
39 changes: 39 additions & 0 deletions csrc/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"cmake.configureArgs": [
"-DBUILD_MODULE_TYPE=CPU",
"-DBUILD_WITH_XPU=OFF",
"-DCMAKE_BUILD_TYPE=Debug",
"-DCMAKE_INSTALL_LIBDIR=lib",
"-DCMAKE_INSTALL_PREFIX=/home/wangzhe/zhe/intel-extension-for-pytorch/build/Debug/packages/intel_extension_for_pytorch",
"-DCMAKE_PREFIX_PATH=/home/wangzhe/.local/envs/zhe_ipex/lib/python3.9/site-packages/torch/share/cmake",
"-DCMAKE_PROJECT_VERSION=2.0.100",
"-DIPEX_INSTALL_LIBDIR=/home/wangzhe/zhe/intel-extension-for-pytorch/build/Debug/packages/intel_extension_for_pytorch/lib",
"-DIPEX_PROJ_NAME=intel_extension_for_pytorch",
"-DLIBIPEX_GITREV=6aa94f277",
"-DLIBIPEX_VERSION=2.0.100+git6aa94f2",
"-DPYTHON_EXECUTABLE=/home/wangzhe/.local/envs/zhe_ipex/bin/python",
"-DPYTHON_INCLUDE_DIR=/home/wangzhe/.local/envs/zhe_ipex/include/python3.9",
"-DPYTHON_PLATFORM_INFO=Linux-5.16.0-rc1-intel-next-00543-g5867b0a2a125-x86_64-with-glibc2.28"
],
"cmake.buildDirectory": "${workspaceFolder}/build",
"clangd.arguments": [
"--log=verbose",
"--header-insertion=iwyu",
"--query-driver=/home/wangzhe/.local/envs/zhe_ipex/bin/g++*",
// 在后台自动分析文件(基于complie_commands)
"--background-index",
// 同时开启的任务数量
"-j=12",
// clang-tidy功能
"--clang-tidy",
"--clang-tidy-checks=performance-*,bugprone-*",
// 全局补全(会自动补充头文件)
"--all-scopes-completion",
// 更详细的补全内容
"--completion-style=detailed",
// 补充头文件的形式
"--header-insertion=iwyu",
// pch优化的位置
"--pch-storage=disk",
],
}
Loading

0 comments on commit d75a4d1

Please sign in to comment.