From 7bb72e37b21422ca56904b7cc75d2ca832c01327 Mon Sep 17 00:00:00 2001 From: heliqi <1101791222@qq.com> Date: Wed, 22 Jun 2022 01:17:50 -0500 Subject: [PATCH] paddle2onnx update to 0.9.8 (#43742) --- cmake/external/onnxruntime.cmake | 26 +++++-- cmake/external/paddle2onnx.cmake | 77 ++++++++++++------- .../inference/api/demo_ci/CMakeLists.txt | 16 +--- .../inference/tests/infer_ut/CMakeLists.txt | 16 +--- paddle/fluid/pybind/CMakeLists.txt | 15 +--- python/setup.py.in | 4 +- 6 files changed, 76 insertions(+), 78 deletions(-) diff --git a/cmake/external/onnxruntime.cmake b/cmake/external/onnxruntime.cmake index 832761f69d..89e913e187 100644 --- a/cmake/external/onnxruntime.cmake +++ b/cmake/external/onnxruntime.cmake @@ -26,6 +26,7 @@ include(ExternalProject) add_definitions(-DPADDLE_WITH_ONNXRUNTIME) set(ONNXRUNTIME_PROJECT "extern_onnxruntime") +set(ONNXRUNTIME_VERSION "1.10.0") set(ONNXRUNTIME_PREFIX_DIR ${THIRD_PARTY_PATH}/onnxruntime) set(ONNXRUNTIME_SOURCE_DIR ${THIRD_PARTY_PATH}/onnxruntime/src/${ONNXRUNTIME_PROJECT}) @@ -40,21 +41,29 @@ set(CMAKE_BUILD_RPATH "${CMAKE_BUILD_RPATH}" "${ONNXRUNTIME_LIB_DIR}") if(WIN32) set(ONNXRUNTIME_URL - "https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-win-x64-1.10.0.zip" + "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-win-x64-${ONNXRUNTIME_VERSION}.zip" ) elseif(APPLE) set(ONNXRUNTIME_URL - "https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-osx-x86_64-1.10.0.tgz" + "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-osx-x86_64-${ONNXRUNTIME_VERSION}.tgz" ) else() set(ONNXRUNTIME_URL - "https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-linux-x64-1.10.0.tgz" + "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz" ) endif() # For ONNXRUNTIME code to include internal headers. include_directories(${ONNXRUNTIME_INC_DIR}) +set(ONNXRUNTIME_LIB_NEW_NAME "libonnxruntime${CMAKE_SHARED_LIBRARY_SUFFIX}") +if(APPLE) + set(ONNXRUNTIME_LIB_NAME + "libonnxruntime.${ONNXRUNTIME_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") +else() + set(ONNXRUNTIME_LIB_NAME + "libonnxruntime${CMAKE_SHARED_LIBRARY_SUFFIX}.${ONNXRUNTIME_VERSION}") +endif() if(WIN32) set(ONNXRUNTIME_SOURCE_LIB "${ONNXRUNTIME_SOURCE_DIR}/lib/onnxruntime.dll" @@ -67,20 +76,20 @@ if(WIN32) CACHE FILEPATH "ONNXRUNTIME static library." FORCE) elseif(APPLE) set(ONNXRUNTIME_SOURCE_LIB - "${ONNXRUNTIME_SOURCE_DIR}/lib/libonnxruntime.1.10.0.dylib" + "${ONNXRUNTIME_SOURCE_DIR}/lib/${ONNXRUNTIME_LIB_NAME}" CACHE FILEPATH "ONNXRUNTIME source library." FORCE) set(ONNXRUNTIME_LIB - "${ONNXRUNTIME_INSTALL_DIR}/lib/libonnxruntime.1.10.0.dylib" + "${ONNXRUNTIME_INSTALL_DIR}/lib/${ONNXRUNTIME_LIB_NAME}" CACHE FILEPATH "ONNXRUNTIME static library." FORCE) set(ONNXRUNTIME_SHARED_LIB ${ONNXRUNTIME_LIB} CACHE FILEPATH "ONNXRUNTIME shared library." FORCE) else() set(ONNXRUNTIME_SOURCE_LIB - "${ONNXRUNTIME_SOURCE_DIR}/lib/libonnxruntime.so.1.10.0" + "${ONNXRUNTIME_SOURCE_DIR}/lib/${ONNXRUNTIME_LIB_NAME}" CACHE FILEPATH "ONNXRUNTIME source library." FORCE) set(ONNXRUNTIME_LIB - "${ONNXRUNTIME_INSTALL_DIR}/lib/libonnxruntime.so.1.10.0" + "${ONNXRUNTIME_INSTALL_DIR}/lib/${ONNXRUNTIME_LIB_NAME}" CACHE FILEPATH "ONNXRUNTIME static library." FORCE) set(ONNXRUNTIME_SHARED_LIB ${ONNXRUNTIME_LIB} @@ -117,7 +126,8 @@ else() INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${ONNXRUNTIME_SOURCE_LIB} ${ONNXRUNTIME_LIB} && ${CMAKE_COMMAND} -E copy_directory ${ONNXRUNTIME_SOURCE_DIR}/include - ${ONNXRUNTIME_INC_DIR} + ${ONNXRUNTIME_INC_DIR} && ${CMAKE_COMMAND} -E create_symlink + ${ONNXRUNTIME_LIB_NAME} ${ONNXRUNTIME_LIB_DIR}/${ONNXRUNTIME_LIB_NEW_NAME} BUILD_BYPRODUCTS ${ONNXRUNTIME_LIB}) endif() diff --git a/cmake/external/paddle2onnx.cmake b/cmake/external/paddle2onnx.cmake index 0fbd1803c6..5076e1b2cf 100644 --- a/cmake/external/paddle2onnx.cmake +++ b/cmake/external/paddle2onnx.cmake @@ -24,6 +24,7 @@ endif() include(ExternalProject) set(PADDLE2ONNX_PROJECT "extern_paddle2onnx") +set(PADDLE2ONNX_VERSION "0.9.8") set(PADDLE2ONNX_PREFIX_DIR ${THIRD_PARTY_PATH}/paddle2onnx) set(PADDLE2ONNX_SOURCE_DIR ${THIRD_PARTY_PATH}/paddle2onnx/src/${PADDLE2ONNX_PROJECT}) @@ -38,6 +39,15 @@ set(CMAKE_BUILD_RPATH "${CMAKE_BUILD_RPATH}" "${PADDLE2ONNX_LIB_DIR}") # For PADDLE2ONNX code to include internal headers. include_directories(${PADDLE2ONNX_INC_DIR}) +set(PADDLE2ONNX_LIB_NEW_NAME "libpaddle2onnx${CMAKE_SHARED_LIBRARY_SUFFIX}") +if(APPLE) + set(PADDLE2ONNX_LIB_NAME + "libpaddle2onnx.${PADDLE2ONNX_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") +else() + set(PADDLE2ONNX_LIB_NAME + "libpaddle2onnx${CMAKE_SHARED_LIBRARY_SUFFIX}.${PADDLE2ONNX_VERSION}") +endif() + if(WIN32) set(PADDLE2ONNX_LIB "${PADDLE2ONNX_INSTALL_DIR}/lib/paddle2onnx.dll" @@ -45,50 +55,65 @@ if(WIN32) set(PADDLE2ONNX_COMPILE_LIB "${PADDLE2ONNX_INSTALL_DIR}/lib/paddle2onnx.lib" CACHE FILEPATH "paddle2onnx compile library." FORCE) -elseif(APPLE) - set(PADDLE2ONNX_LIB - "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.dylib" - CACHE FILEPATH "PADDLE2ONNX library." FORCE) - set(PADDLE2ONNX_COMPILE_LIB - "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.dylib" - CACHE FILEPATH "paddle2onnx compile library." FORCE) else() + set(PADDLE2ONNX_SOURCE_LIB + "${PADDLE2ONNX_SOURCE_DIR}/lib/${PADDLE2ONNX_LIB_NAME}" + CACHE FILEPATH "PADDLE2ONNX source library." FORCE) set(PADDLE2ONNX_LIB - "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.so" + "${PADDLE2ONNX_LIB_DIR}/${PADDLE2ONNX_LIB_NAME}" CACHE FILEPATH "PADDLE2ONNX library." FORCE) set(PADDLE2ONNX_COMPILE_LIB - "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.so" + ${PADDLE2ONNX_LIB} CACHE FILEPATH "paddle2onnx compile library." FORCE) endif() if(WIN32) set(PADDLE2ONNX_URL - "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v0.9.7/paddle2onnx-win-x64-0.9.7.zip" + "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v${PADDLE2ONNX_VERSION}/paddle2onnx-win-x64-${PADDLE2ONNX_VERSION}.zip" ) elseif(APPLE) set(PADDLE2ONNX_URL - "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v0.9.7/paddle2onnx-osx-x86_64-0.9.7.tgz" + "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v${PADDLE2ONNX_VERSION}/paddle2onnx-osx-x86_64-${PADDLE2ONNX_VERSION}.tgz" ) else() set(PADDLE2ONNX_URL - "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v0.9.7/paddle2onnx-linux-x64-0.9.7.tgz" + "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v${PADDLE2ONNX_VERSION}/paddle2onnx-linux-x64-${PADDLE2ONNX_VERSION}.tgz" ) endif() -ExternalProject_Add( - ${PADDLE2ONNX_PROJECT} - ${EXTERNAL_PROJECT_LOG_ARGS} - URL ${PADDLE2ONNX_URL} - PREFIX ${PADDLE2ONNX_PREFIX_DIR} - DOWNLOAD_NO_PROGRESS 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - UPDATE_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} -E copy_directory ${PADDLE2ONNX_SOURCE_DIR}/lib - ${PADDLE2ONNX_LIB_DIR} && ${CMAKE_COMMAND} -E copy_directory - ${PADDLE2ONNX_SOURCE_DIR}/include ${PADDLE2ONNX_INC_DIR} - BUILD_BYPRODUCTS ${PADDLE2ONNX_COMPILE_LIB}) +if(WIN32) + ExternalProject_Add( + ${PADDLE2ONNX_PROJECT} + ${EXTERNAL_PROJECT_LOG_ARGS} + URL ${PADDLE2ONNX_URL} + PREFIX ${PADDLE2ONNX_PREFIX_DIR} + DOWNLOAD_NO_PROGRESS 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + UPDATE_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} -E copy_directory ${PADDLE2ONNX_SOURCE_DIR}/lib + ${PADDLE2ONNX_LIB_DIR} && ${CMAKE_COMMAND} -E copy_directory + ${PADDLE2ONNX_SOURCE_DIR}/include ${PADDLE2ONNX_INC_DIR} + BUILD_BYPRODUCTS ${PADDLE2ONNX_COMPILE_LIB}) +else() + ExternalProject_Add( + ${PADDLE2ONNX_PROJECT} + ${EXTERNAL_PROJECT_LOG_ARGS} + URL ${PADDLE2ONNX_URL} + PREFIX ${PADDLE2ONNX_PREFIX_DIR} + DOWNLOAD_NO_PROGRESS 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + UPDATE_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} -E copy ${PADDLE2ONNX_SOURCE_LIB} + ${PADDLE2ONNX_COMPILE_LIB} && ${CMAKE_COMMAND} -E copy_directory + ${PADDLE2ONNX_SOURCE_DIR}/include ${PADDLE2ONNX_INC_DIR} && + ${CMAKE_COMMAND} -E create_symlink ${PADDLE2ONNX_LIB_NAME} + ${PADDLE2ONNX_LIB_DIR}/${PADDLE2ONNX_LIB_NEW_NAME} + BUILD_BYPRODUCTS ${PADDLE2ONNX_COMPILE_LIB}) +endif() add_library(paddle2onnx STATIC IMPORTED GLOBAL) set_property(TARGET paddle2onnx PROPERTY IMPORTED_LOCATION diff --git a/paddle/fluid/inference/api/demo_ci/CMakeLists.txt b/paddle/fluid/inference/api/demo_ci/CMakeLists.txt index c58aad36c9..fc23caee65 100644 --- a/paddle/fluid/inference/api/demo_ci/CMakeLists.txt +++ b/paddle/fluid/inference/api/demo_ci/CMakeLists.txt @@ -189,21 +189,7 @@ else() endif() if(WITH_ONNXRUNTIME) - if(WIN32) - set(DEPS - ${DEPS} ${PADDLE_LIB_THIRD_PARTY_PATH}onnxruntime/lib/onnxruntime.lib - paddle2onnx) - elseif(APPLE) - set(DEPS - ${DEPS} - ${PADDLE_LIB_THIRD_PARTY_PATH}onnxruntime/lib/libonnxruntime.1.10.0.dylib - paddle2onnx) - else() - set(DEPS - ${DEPS} - ${PADDLE_LIB_THIRD_PARTY_PATH}onnxruntime/lib/libonnxruntime.so.1.10.0 - paddle2onnx) - endif() + set(DEPS ${DEPS} onnxruntime paddle2onnx) endif() if(NOT WIN32) diff --git a/paddle/fluid/inference/tests/infer_ut/CMakeLists.txt b/paddle/fluid/inference/tests/infer_ut/CMakeLists.txt index e1ef57e3a1..e27cf7ffe1 100644 --- a/paddle/fluid/inference/tests/infer_ut/CMakeLists.txt +++ b/paddle/fluid/inference/tests/infer_ut/CMakeLists.txt @@ -214,21 +214,7 @@ else() endif() if(WITH_ONNXRUNTIME) - if(WIN32) - set(DEPS - ${DEPS} ${PADDLE_LIB_THIRD_PARTY_PATH}onnxruntime/lib/onnxruntime.lib - paddle2onnx) - elseif(APPLE) - set(DEPS - ${DEPS} - ${PADDLE_LIB_THIRD_PARTY_PATH}onnxruntime/lib/libonnxruntime.1.10.0.dylib - paddle2onnx) - else() - set(DEPS - ${DEPS} - ${PADDLE_LIB_THIRD_PARTY_PATH}onnxruntime/lib/libonnxruntime.so.1.10.0 - paddle2onnx) - endif() + set(DEPS ${DEPS} onnxruntime paddle2onnx) endif() if(NOT WIN32) diff --git a/paddle/fluid/pybind/CMakeLists.txt b/paddle/fluid/pybind/CMakeLists.txt index fd6a76a706..310e1a17b1 100755 --- a/paddle/fluid/pybind/CMakeLists.txt +++ b/paddle/fluid/pybind/CMakeLists.txt @@ -380,17 +380,10 @@ if(WITH_PYTHON) # LD_LIBRARY_PATH. This is different with Windows platformm, which search # *.dll in current directory automatically. if(WITH_ONNXRUNTIME) - if(APPLE) - set(PADDLE2ONNX_PYBIND_OUT - ${CMAKE_CURRENT_BINARY_DIR}/libpaddle2onnx.dylib) - set(ONNXRUNTIME_PYBIND_OUT - ${CMAKE_CURRENT_BINARY_DIR}/libonnxruntime.1.10.0.dylib) - else() - set(PADDLE2ONNX_PYBIND_OUT - ${CMAKE_CURRENT_BINARY_DIR}/libpaddle2onnx.so) - set(ONNXRUNTIME_PYBIND_OUT - ${CMAKE_CURRENT_BINARY_DIR}/libonnxruntime.so.1.10.0) - endif() + set(PADDLE2ONNX_PYBIND_OUT + ${CMAKE_CURRENT_BINARY_DIR}/${PADDLE2ONNX_LIB_NAME}) + set(ONNXRUNTIME_PYBIND_OUT + ${CMAKE_CURRENT_BINARY_DIR}/${ONNXRUNTIME_LIB_NAME}) add_custom_command( OUTPUT ${PADDLE2ONNX_PYBIND_OUT} diff --git a/python/setup.py.in b/python/setup.py.in index bbeb1aa447..17cb0ad677 100755 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -538,10 +538,8 @@ if '${WITH_ONNXRUNTIME}' == 'ON': shutil.copy('${PADDLE2ONNX_LIB}', libs_path) if os.name == 'nt': package_data['paddle.libs']+=['paddle2onnx.dll', 'onnxruntime.dll'] - elif sys.platform == 'darwin': - package_data['paddle.libs']+=['libpaddle2onnx.dylib', 'libonnxruntime.1.10.0.dylib'] else: - package_data['paddle.libs']+=['libpaddle2onnx.so', 'libonnxruntime.so.1.10.0'] + package_data['paddle.libs']+=['${PADDLE2ONNX_LIB_NAME}', '${ONNXRUNTIME_LIB_NAME}'] if '${WITH_XPU}' == 'ON': # only change rpath in Release mode, -- GitLab