diff --git a/CMakeLists.txt b/CMakeLists.txt index 783130766..ca278fd0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ if(NOT MSVC) set(CMAKE_CXX_FLAGS "-Wno-format") endif(NOT MSVC) -if(UNIX) +if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) include(${PROJECT_SOURCE_DIR}/cmake/patchelf.cmake) endif() @@ -285,7 +285,7 @@ if(ENABLE_TRT_BACKEND) find_package(Python COMPONENTS Interpreter Development REQUIRED) message(STATUS "Copying ${TRT_DIRECTORY}/lib to ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib ...") execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/copy_directory.py ${TRT_DIRECTORY}/lib ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib) - if(UNIX) + if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib COMMAND sh -c "xargs ${PATCHELF_EXE} --set-rpath '$ORIGIN'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib RESULT_VARIABLE result diff --git a/cmake/paddle_inference.cmake b/cmake/paddle_inference.cmake index f51c15bcd..4c4b06b00 100644 --- a/cmake/paddle_inference.cmake +++ b/cmake/paddle_inference.cmake @@ -88,7 +88,7 @@ ExternalProject_Add( ${CMAKE_COMMAND} -E copy_directory ${PADDLEINFERENCE_SOURCE_DIR} ${PADDLEINFERENCE_INSTALL_DIR} BUILD_BYPRODUCTS ${PADDLEINFERENCE_COMPILE_LIB}) -if(UNIX) +if(UNIX AND (NOT APPLE) AND (NOT ANDROID)) add_custom_target(patchelf_paddle_inference ALL COMMAND bash -c "PATCHELF_EXE=${PATCHELF_EXE} python ${PROJECT_SOURCE_DIR}/scripts/patch_paddle_inference.py ${PADDLEINFERENCE_INSTALL_DIR}/paddle/lib/libpaddle_inference.so" DEPENDS ${LIBRARY_NAME}) endif() diff --git a/docs/cn/build_and_install/cpu.md b/docs/cn/build_and_install/cpu.md index 1dff75bd0..619c87842 100644 --- a/docs/cn/build_and_install/cpu.md +++ b/docs/cn/build_and_install/cpu.md @@ -17,7 +17,7 @@ Linux上编译需满足 - gcc/g++ >= 5.4(推荐8.2) - cmake >= 3.18.0 -``` +```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build @@ -39,16 +39,16 @@ Windows编译需要满足条件 在Windows菜单中,找到`x64 Native Tools Command Prompt for VS 2019`打开,执行如下命令 -``` +```bat git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build -cmake .. -G "Visual Studio 16 2019" -A x64 \ - -DENABLE_ORT_BACKEND=ON \ - -DENABLE_PADDLE_BACKEND=ON \ - -DENABLE_OPENVINO_BACKEND=ON \ - -DENABLE_VISION=ON \ - -DCMAKE_INSTALL_PREFIX="D:\Paddle\compiled_fastdeploy" +cmake .. -G "Visual Studio 16 2019" -A x64 ^ + -DENABLE_ORT_BACKEND=ON ^ + -DENABLE_PADDLE_BACKEND=ON ^ + -DENABLE_OPENVINO_BACKEND=ON ^ + -DENABLE_VISION=ON ^ + -DCMAKE_INSTALL_PREFIX="D:\Paddle\compiled_fastdeploy" ^ msbuild fastdeploy.sln /m /p:Configuration=Release /p:Platform=x64 msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64 ``` @@ -68,7 +68,7 @@ msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64 ### Linux & Mac -``` +```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python export ENABLE_ORT_BACKEND=ON @@ -89,7 +89,7 @@ python setup.py bdist_wheel 在Windows菜单中,找到`x64 Native Tools Command Prompt for VS 2019`打开,执行如下命令 -``` +```bat git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python set ENABLE_ORT_BACKEND=ON diff --git a/docs/cn/build_and_install/download_prebuilt_libraries.md b/docs/cn/build_and_install/download_prebuilt_libraries.md index 6326ac0c4..a320b6924 100644 --- a/docs/cn/build_and_install/download_prebuilt_libraries.md +++ b/docs/cn/build_and_install/download_prebuilt_libraries.md @@ -16,12 +16,12 @@ FastDeploy提供各平台预编译库,供开发者直接下载安装使用。 ### Python安装 Release版本(当前最新0.3.0)安装 -``` +```bash pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html ``` 其中推荐使用Conda配置开发环境 -``` +```bash conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2 ``` @@ -45,7 +45,7 @@ Release版本(当前最新0.3.0) ### Python安装 Release版本(当前最新0.3.0)安装 -``` +```bash pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html ``` @@ -57,7 +57,7 @@ Release版本(当前最新0.3.0) | :--- | :--- | :---- | | Linux x64 | [fastdeploy-linux-x64-0.3.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-0.3.0.tgz) | g++ 8.2编译产出 | | Windows x64 | [fastdeploy-win-x64-0.3.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-0.3.0.zip) | Visual Studio 16 2019编译产出 | -| Mac OSX x64 | [fastdeploy-osx-x86_64-0.3.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-0.3.0.tgz) | - | -| Mac OSX arm64 | [fastdeploy-osx-arm64-0.3.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-0.3.0.tgz) | - | +| Mac OSX x64 | [fastdeploy-osx-x86_64-0.3.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-0.3.0.tgz) | clang++ 10.0.0编译产出| +| Mac OSX arm64 | [fastdeploy-osx-arm64-0.3.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-0.3.0.tgz) | clang++ 13.0.0编译产出 | | Linux aarch64 | [fastdeploy-linux-aarch64-0.3.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-0.3.0.tgz) | g++ 6.3.0编译产出 | diff --git a/docs/cn/build_and_install/gpu.md b/docs/cn/build_and_install/gpu.md index d33a1f586..ef98cad3c 100644 --- a/docs/cn/build_and_install/gpu.md +++ b/docs/cn/build_and_install/gpu.md @@ -22,7 +22,7 @@ Linux上编译需满足 - cuda >= 11.2 - cudnn >= 8.2 -``` +```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build @@ -50,19 +50,19 @@ Windows编译需要满足条件 在Windows菜单中,找到`x64 Native Tools Command Prompt for VS 2019`打开,执行如下命令 -``` +```bat git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build -cmake .. -G "Visual Studio 16 2019" -A x64 \ - -DENABLE_ORT_BACKEND=ON \ - -DENABLE_PADDLE_BACKEND=ON \ - -DENABLE_OPENVINO_BACKEND=ON \ - -DENABLE_TRT_BACKEND=ON - -DENABLE_VISION=ON \ - -DWITH_GPU=ON \ - -DTRT_DIRECTORY="D:\Paddle\TensorRT-8.4.1.5" \ - -DCUDA_DIRECTORY="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2" \ +cmake .. -G "Visual Studio 16 2019" -A x64 ^ + -DENABLE_ORT_BACKEND=ON ^ + -DENABLE_PADDLE_BACKEND=ON ^ + -DENABLE_OPENVINO_BACKEND=ON ^ + -DENABLE_TRT_BACKEND=ON ^ + -DENABLE_VISION=ON ^ + -DWITH_GPU=ON ^ + -DTRT_DIRECTORY="D:\Paddle\TensorRT-8.4.1.5" ^ + -DCUDA_DIRECTORY="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2" ^ -DCMAKE_INSTALL_PREFIX="D:\Paddle\compiled_fastdeploy" msbuild fastdeploy.sln /m /p:Configuration=Release /p:Platform=x64 msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64 @@ -86,7 +86,7 @@ msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64 所有编译选项通过环境变量导入 -``` +```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python export ENABLE_ORT_BACKEND=ON @@ -113,7 +113,7 @@ python setup.py bdist_wheel 在Windows菜单中,找到`x64 Native Tools Command Prompt for VS 2019`打开,执行如下命令 -``` +```bat git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python export ENABLE_ORT_BACKEND=ON diff --git a/docs/cn/build_and_install/jetson.md b/docs/cn/build_and_install/jetson.md index c868dadae..4163f77bc 100644 --- a/docs/cn/build_and_install/jetson.md +++ b/docs/cn/build_and_install/jetson.md @@ -10,7 +10,7 @@ FastDeploy当前在Jetson仅支持ONNX Runtime CPU和TensorRT GPU两种后端推 - cmake >= 3.10.0 - jetpack >= 4.6.1 -``` +```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy mkdir build && cd build @@ -34,7 +34,7 @@ make install 所有编译选项通过环境变量导入 -``` +```bash git clone https://github.com/PaddlePaddle/FastDeploy.git cd FastDeploy/python export BUILD_ON_JETSON=ON diff --git a/docs/cn/faq/tensorrt_tricks.md b/docs/cn/faq/tensorrt_tricks.md index 285489d84..37d2a07aa 100644 --- a/docs/cn/faq/tensorrt_tricks.md +++ b/docs/cn/faq/tensorrt_tricks.md @@ -1,7 +1,7 @@ # TensorRT使用问题 ## 1. 运行TensorRT过程中,出现如下日志提示 -``` +```bash [WARNING] fastdeploy/backends/tensorrt/trt_backend.cc(552)::CreateTrtEngineFromOnnx Cannot build engine right now, because there's dynamic input shape exists, list as below, [WARNING] fastdeploy/backends/tensorrt/trt_backend.cc(556)::CreateTrtEngineFromOnnx Input 0: TensorInfo(name: image, shape: [-1, 3, 320, 320], dtype: FDDataType::FP32) [WARNING] fastdeploy/backends/tensorrt/trt_backend.cc(556)::CreateTrtEngineFromOnnx Input 1: TensorInfo(name: scale_factor, shape: [1, 2], dtype: FDDataType::FP32) diff --git a/docs/cn/quick_start/models/cpp.md b/docs/cn/quick_start/models/cpp.md index e5fe7697f..b99f12299 100644 --- a/docs/cn/quick_start/models/cpp.md +++ b/docs/cn/quick_start/models/cpp.md @@ -6,7 +6,7 @@ ## 1. 获取模型和测试图像 -``` +```bash wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz wget https://bj.bcebos.com/fastdeploy/tests/test_det.jpg tar xvf ppyoloe_crn_l_300e_coco.tgz @@ -16,7 +16,7 @@ tar xvf ppyoloe_crn_l_300e_coco.tgz 如下C++代码保存为`infer_demo.cc` -``` c++ +```c++ #include "fastdeploy/vision.h" int main() { std::string model_file = "ppyoloe_crn_l_300e_coco/model.pdmodel"; @@ -49,11 +49,11 @@ FastDeploy中包含多个依赖库,直接采用`g++`或编译器编译较为 假设下载或准备的FastDeploy C++ SDK在`/Paddle/Download`目录下,且目录名为`fastdeploy_cpp_sdk`,在开发者的项目中只需添加如下代码,即可引入`FASTDEPLOY_INCS`和`FASTDEPLOY_LIBS`两个变量,分别表示依赖的头文件和库文件 -``` shell +```cmake include(/Paddle/Download/fastdeploy_cpp_sdk/FastDeploy.cmake) ``` -``` +```cmake PROJECT(infer_demo C CXX) CMAKE_MINIMUM_REQUIRED (VERSION 3.10) @@ -74,23 +74,23 @@ target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) 打开命令行终端,进入`infer_demo.cc`和`CmakeLists.txt`所在的目录,执行如下命令 -``` +```bash mkdir build & cd build cmake .. make -j ``` 编译完成后,使用如下命令执行可得到预测结果 -``` +```bash ./infer_demo ``` 执行时如提示`error while loading shared libraries: libxxx.so: cannot open shared object file: No such file...`,说明程序执行时没有找到FastDeploy的库路径,可通过执行如下命令,将FastDeploy的库路径添加到环境变量之后,重新执行二进制程序。 -``` +```bash source /Path/to/fastdeploy_cpp_sdk/fastdeploy_init.sh ``` 执行完屏幕会输出如下日志 -``` +```bash DetectionResult: [xmin, ymin, xmax, ymax, score, label_id] 415.047180,89.311569, 506.009613, 283.863098, 0.950423, 0 163.665710,81.914932, 198.585342, 166.760895, 0.896433, 0 @@ -110,7 +110,7 @@ DetectionResult: [xmin, ymin, xmax, ymax, score, label_id] 上面的编译过程适用于Linux/Mac,Windows上编译流程如下 在Windows菜单中,找到`x64 Native Tools Command Prompt for VS 2019`打开,进入`infer_demo.cc`和`CMakeLists.txt`所在目录,执行如下命令 -``` +```bat mkdir build cd build cmake .. -G "Visual Studio 16 2019" -A x64 @@ -118,7 +118,7 @@ msbuild infer_demo.sln /m /p:Configuration=Release /p:Platform=x64 ``` 执行完后,即会在`build/Release`目录下生成`infer_demo.exe`程序,使用如下命令执行可得到预测结果 -``` +```bat Release\infer_demo.exe ``` diff --git a/python/scripts/process_libraries.py.in b/python/scripts/process_libraries.py.in index 66581e4f0..f647e3d65 100644 --- a/python/scripts/process_libraries.py.in +++ b/python/scripts/process_libraries.py.in @@ -74,6 +74,7 @@ def process_on_linux(current_dir): def process_on_mac(current_dir): fd_libs = list() libs_path = os.path.join(current_dir, "fastdeploy", "libs") + cmake_build_dir = os.path.join(current_dir, ".setuptools-cmake-build") for f in os.listdir(libs_path): filename = os.path.join(libs_path, f) if not os.path.isfile(filename): @@ -82,41 +83,48 @@ def process_on_mac(current_dir): f.count(".so") > 0): fd_libs.append(filename) + commands = list() pre_commands = list() for lib in fd_libs: - pre_commands.append( - "install_name_tool -delete_rpath '@loader_path/libs' " + lib) + if lib.count("fastdeploy_main") > 0: + pre_commands.append( + "install_name_tool -delete_rpath {} ".format(cmake_build_dir) + lib) + commands.append("install_name_tool -id @loader_path " + lib) + commands.append("install_name_tool -add_rpath @loader_path " + lib) - commands = list() third_libs_path = os.path.join(libs_path, "third_libs") - all_libs_paths = [third_libs_path] + user_specified_dirs + cmake_third_libs_path = os.path.join(cmake_build_dir, "third_libs", "install") + all_libs_paths = [cmake_third_libs_path] + user_specified_dirs for path in all_libs_paths: for root, dirs, files in os.walk(path): for d in dirs: if d not in ["lib", "lib64"]: continue - rel_path = os.path.relpath(os.path.join(root, d), libs_path) + rel_path = os.path.relpath(os.path.join(root, d), cmake_third_libs_path) if path in user_specified_dirs: # Note(zhoushunjie): Use the absolute path for user_specified_dirs - rpath = os.path.join(root, d) + need_delete_rpath = os.path.join(root, d) + need_add_rpath = os.path.join(root, d) else: - rpath = "$loader_path/" + rel_path + need_delete_rpath = os.path.join(root, d) + need_add_rpath = "@loader_path/third_libs/" + rel_path for lib in fd_libs: - pre_commands.append( - "install_name_tool -delete_rpath '@loader_path/{}' {}".format( - rpath, lib)) - commands.append("install_name_tool -add_rpath 'loader_path/{}' {}". - format(rpath, lib)) + if lib.count("fastdeploy_main") > 0: + pre_commands.append( + "install_name_tool -delete_rpath {} {}".format(need_delete_rpath, lib)) + commands.append( + "install_name_tool -add_rpath {} {}".format(need_add_rpath, lib)) - for cmd in pre_commands: + for command in pre_commands: try: - subprocess.Popen(cmd, shell=True) + os.system(command) except: - print("Skip execute command:", cmd) + print("Skip execute command: " + command) - for cmd in commands: - assert subprocess.Popen( - cmd, shell=True) != 0, "Execute command failed: {}".format(cmd) + for command in commands: + assert os.system( + command) == 0, "command execute failed! command: {}".format( + command) def process_on_windows(current_dir): libs_path = os.path.join(current_dir, "fastdeploy", "libs")