diff --git a/.clangd b/.clangd new file mode 100644 index 000000000..45f339fef --- /dev/null +++ b/.clangd @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8b510cd56..1f042e87c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -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 @@ -207,7 +208,6 @@ aten/build/* .clang-format-bin/ .clang-tidy-bin/ - # Bram plsdontbreak @@ -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 diff --git a/.vscode/cmake-tools-kits.json b/.vscode/cmake-tools-kits.json new file mode 100644 index 000000000..42852ca90 --- /dev/null +++ b/.vscode/cmake-tools-kits.json @@ -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 + } +] \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..b73c935d5 --- /dev/null +++ b/.vscode/launch.json @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..3773d47d6 --- /dev/null +++ b/.vscode/settings.json @@ -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", + ], +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..a1e5ba0ed --- /dev/null +++ b/.vscode/tasks.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/compile_bundle.sh b/compile_bundle.sh new file mode 100755 index 000000000..1072f6880 --- /dev/null +++ b/compile_bundle.sh @@ -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__}');" diff --git a/compile_bundle_bk.sh b/compile_bundle_bk.sh new file mode 100755 index 000000000..ed3006685 --- /dev/null +++ b/compile_bundle_bk.sh @@ -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__}');" diff --git a/csrc/.vscode/cmake-tools-kits.json b/csrc/.vscode/cmake-tools-kits.json new file mode 100644 index 000000000..42852ca90 --- /dev/null +++ b/csrc/.vscode/cmake-tools-kits.json @@ -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 + } +] \ No newline at end of file diff --git a/csrc/.vscode/launch.json b/csrc/.vscode/launch.json new file mode 100644 index 000000000..b73c935d5 --- /dev/null +++ b/csrc/.vscode/launch.json @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/csrc/.vscode/settings.json b/csrc/.vscode/settings.json new file mode 100644 index 000000000..0a6b5e101 --- /dev/null +++ b/csrc/.vscode/settings.json @@ -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", + ], +} \ No newline at end of file diff --git a/csrc/.vscode/tasks.json b/csrc/.vscode/tasks.json new file mode 100644 index 000000000..60c202e0f --- /dev/null +++ b/csrc/.vscode/tasks.json @@ -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 /home/wangzhe/zhe/intel-extension-for-pytorch/env_init.sh" + } + ] +} \ No newline at end of file diff --git a/csrc/cpu/CMakeLists.txt b/csrc/cpu/CMakeLists.txt index 5800fc8c4..2ac393179 100644 --- a/csrc/cpu/CMakeLists.txt +++ b/csrc/cpu/CMakeLists.txt @@ -29,6 +29,7 @@ add_subdirectory(${IPEX_CPU_CPP_THIRD_PARTY_ROOT}/ideep/mkl-dnn ${THIRD_PARTY_BU IF(IPEX_DISP_OP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPEX_DISP_OP") ENDIF() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") # ---[ Main build # include mkl-dnn before PyTorch diff --git a/csrc/cpu/aten/kernels/CumsumKrnl.cpp b/csrc/cpu/aten/kernels/CumsumKrnl.cpp index 1700957e3..a61f4f270 100644 --- a/csrc/cpu/aten/kernels/CumsumKrnl.cpp +++ b/csrc/cpu/aten/kernels/CumsumKrnl.cpp @@ -28,6 +28,7 @@ static inline void cumsum_lastdim_kernel( const at::Tensor& self, int64_t dim) { const auto input_ndim = self.dim(); + std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; TORCH_CHECK( dim == input_ndim - 1, "cumsum_lastdim_kernel: expect dim to be ", diff --git a/env_init.sh b/env_init.sh new file mode 100755 index 000000000..57f100ec3 --- /dev/null +++ b/env_init.sh @@ -0,0 +1,8 @@ +LLVM_ROOT="/home/wangzhe/zhe/llvm-project/release" +export PATH=${LLVM_ROOT}/bin:$PATH +export LD_LIBRARY_PATH=${LLVM_ROOT}/lib:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=/home/wangzhe/.local/envs/zhe_ipex/lib:$LD_LIBRARY_PATH +export USE_LLVM=${LLVM_ROOT} +export LLVM_DIR=${USE_LLVM}/lib/cmake/llvm +export DNNL_GRAPH_BUILD_COMPILER_BACKEND=1 +# -DBUILD_MODULE_TYPE=CPU -DBUILD_WITH_XPU=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=/home/wangzhe/zhe/intel-extension-for-pytorch/build/Release/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/Release/packages/intel_extension_for_pytorch/lib -DIPEX_PROJ_NAME=intel_extension_for_pytorch -DLIBIPEX_GITREV=25b721274 -DLIBIPEX_VERSION=2.0.100+git25b7212 -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 -DUSE_LLVM=/home/wangzhe/zhe/llvm-project/release diff --git a/setup.py b/setup.py index 895283203..fd15cfc6e 100644 --- a/setup.py +++ b/setup.py @@ -146,13 +146,14 @@ def _check_env_flag(name, default=""): def get_build_type(): - return ( - "RelWithDebInfo" - if _check_env_flag("REL_WITH_DEB_INFO") - else "Debug" - if _check_env_flag("DEBUG") - else "Release" - ) + return "Debug" + # return ( + # "RelWithDebInfo" + # if _check_env_flag("REL_WITH_DEB_INFO") + # else "Debug" + # if _check_env_flag("DEBUG") + # else "Release" + # ) def create_if_not_exist(path_dir):