Skip to content

Commit

Permalink
[Bug Fix] fixed compile error for cpu building (#2105)
Browse files Browse the repository at this point in the history
* [cmake] upgrade windows paddle inference -> 2.5.0

* [cmake] upgrade windows paddle inference -> 2.5.0

* fix paddle custom ops bug on windows

* [Backend] refactor paddle custom ops

* [Bug Fix] fixed paddle custom ops windows build error

* [Bug Fix] fixed compile error for cpu building
  • Loading branch information
DefTruth committed Jul 13, 2023
1 parent d5ad3d9 commit 77ee48f
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmake/paddle_inference.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,10 @@ function(set_paddle_custom_ops_compatible_policy)
endif()
endif()
# common compile flags for paddle custom ops
add_definitions(-DPADDLE_WITH_CUDA)
add_definitions(-DPADDLE_ON_INFERENCE)
add_definitions(-DPADDLE_NO_PYTHON)
add_definitions(-DPADDLE_NO_PYTHON)
if(WITH_GPU)
add_definitions(-DPADDLE_WITH_CUDA)
endif()
endif()
endfunction()
125 changes: 125 additions & 0 deletions scripts/linux/build_linux_x86_64_cpp_cpu_with_benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash
set -e
set +x

# -------------------------------------------------------------------------------
# readonly global variables
# -------------------------------------------------------------------------------
ROOT_PATH=$(pwd)
BUILD_ROOT=build/Linux
BUILD_DIR="${BUILD_ROOT}/x86_64_gpu"
PADDLEINFERENCE_DIRECTORY=$1
PADDLEINFERENCE_VERSION=$2
PADDLEINFERENCE_API_CUSTOM_OP=$3

BUILD_WITH_CUSTOM_PADDLE='OFF'
if [[ -d "$1" ]]; then
BUILD_WITH_CUSTOM_PADDLE='ON'
else
if [[ "$1" == "ON" ]]; then
PADDLEINFERENCE_API_CUSTOM_OP='ON'
fi
fi

# -------------------------------------------------------------------------------
# tasks
# -------------------------------------------------------------------------------
__make_build_dir() {
if [ ! -d "${BUILD_DIR}" ]; then
echo "-- [INFO] BUILD_DIR: ${BUILD_DIR} not exists, setup manually ..."
if [ ! -d "${BUILD_ROOT}" ]; then
mkdir -p "${BUILD_ROOT}" && echo "-- [INFO] Created ${BUILD_ROOT} !"
fi
mkdir -p "${BUILD_DIR}" && echo "-- [INFO] Created ${BUILD_DIR} !"
else
echo "-- [INFO] Found BUILD_DIR: ${BUILD_DIR}"
fi
}

__check_cxx_envs() {
if [ $LDFLAGS ]; then
echo "-- [INFO] Found LDFLAGS: ${LDFLAGS}, \c"
echo "unset it before crossing compiling ${BUILD_DIR}"
unset LDFLAGS
fi
if [ $CPPFLAGS ]; then
echo "-- [INFO] Found CPPFLAGS: ${CPPFLAGS}, \c"
echo "unset it before crossing compiling ${BUILD_DIR}"
unset CPPFLAGS
fi
if [ $CPLUS_INCLUDE_PATH ]; then
echo "-- [INFO] Found CPLUS_INCLUDE_PATH: ${CPLUS_INCLUDE_PATH}, \c"
echo "unset it before crossing compiling ${BUILD_DIR}"
unset CPLUS_INCLUDE_PATH
fi
if [ $C_INCLUDE_PATH ]; then
echo "-- [INFO] Found C_INCLUDE_PATH: ${C_INCLUDE_PATH}, \c"
echo "unset it before crossing compiling ${BUILD_DIR}"
unset C_INCLUDE_PATH
fi
}

__build_fastdeploy_linux_x86_64_gpu_shared() {

local FASDEPLOY_INSTALL_DIR="${ROOT_PATH}/${BUILD_DIR}/install"
cd "${BUILD_DIR}" && echo "-- [INFO] Working Dir: ${PWD}"

cmake -DCMAKE_BUILD_TYPE=Release \
-DWITH_GPU=OFF \
-DENABLE_ORT_BACKEND=ON \
-DENABLE_TRT_BACKEND=OFF \
-DENABLE_PADDLE_BACKEND=ON \
-DENABLE_OPENVINO_BACKEND=ON \
-DENABLE_PADDLE2ONNX=ON \
-DENABLE_VISION=ON \
-DENABLE_BENCHMARK=ON \
-DBUILD_EXAMPLES=OFF \
-DPADDLEINFERENCE_API_CUSTOM_OP=${PADDLEINFERENCE_API_CUSTOM_OP:-"OFF"} \
-DCMAKE_INSTALL_PREFIX=${FASDEPLOY_INSTALL_DIR} \
-Wno-dev ../../.. && make -j8 && make install

echo "-- [INFO][built][x86_64_gpu}][${BUILD_DIR}/install]"
}

__build_fastdeploy_linux_x86_64_gpu_shared_custom_paddle() {

local FASDEPLOY_INSTALL_DIR="${ROOT_PATH}/${BUILD_DIR}/install"
cd "${BUILD_DIR}" && echo "-- [INFO] Working Dir: ${PWD}"

cmake -DCMAKE_BUILD_TYPE=Release \
-DWITH_GPU=OFF \
-DENABLE_ORT_BACKEND=ON \
-DENABLE_TRT_BACKEND=OFF \
-DENABLE_PADDLE_BACKEND=ON \
-DPADDLEINFERENCE_DIRECTORY=${PADDLEINFERENCE_DIRECTORY} \
-DPADDLEINFERENCE_VERSION=${PADDLEINFERENCE_VERSION} \
-DPADDLEINFERENCE_API_CUSTOM_OP=${PADDLEINFERENCE_API_CUSTOM_OP:-"OFF"} \
-DENABLE_OPENVINO_BACKEND=ON \
-DENABLE_PADDLE2ONNX=ON \
-DENABLE_VISION=ON \
-DENABLE_BENCHMARK=ON \
-DBUILD_EXAMPLES=OFF \
-DCMAKE_INSTALL_PREFIX=${FASDEPLOY_INSTALL_DIR} \
-Wno-dev ../../.. && make -j8 && make install

echo "-- [INFO][built][x86_64_gpu}][${BUILD_DIR}/install]"
echo "-- [INFO][${PADDLEINFERENCE_VERSION}][${PADDLEINFERENCE_DIRECTORY}]"
}


main() {
__make_build_dir
__check_cxx_envs
if [ "${BUILD_WITH_CUSTOM_PADDLE}" == "ON" ]; then
__build_fastdeploy_linux_x86_64_gpu_shared_custom_paddle
else
__build_fastdeploy_linux_x86_64_gpu_shared
fi
exit 0
}

main

# Usage:
# ./scripts/linux/build_linux_x86_64_cpp_gpu_with_benchmark.sh
# ./scripts/linux/build_linux_x86_64_cpp_gpu_with_benchmark.sh $PADDLEINFERENCE_DIRECTORY $PADDLEINFERENCE_VERSION

0 comments on commit 77ee48f

Please sign in to comment.