poros.cmake 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. include(ExternalProject)
  15. if(NOT ENABLE_TRT_BACKEND)
  16. message(FATAL_ERROR "While ENABLE_POROS_BACKEND, requires ENABLE_TRT_BACKEND=ON, but now its OFF.")
  17. endif()
  18. set(POROS_PROJECT "extern_poros")
  19. set(POROS_PREFIX_DIR ${THIRD_PARTY_PATH}/poros)
  20. set(POROS_SOURCE_DIR
  21. ${THIRD_PARTY_PATH}/poros/src/${POROS_PROJECT})
  22. set(POROS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/poros)
  23. set(POROS_INC_DIR
  24. "${POROS_INSTALL_DIR}/include"
  25. CACHE PATH "poros include directory." FORCE)
  26. set(POROS_LIB_DIR
  27. "${POROS_INSTALL_DIR}/lib/"
  28. CACHE PATH "poros lib directory." FORCE)
  29. set(CMAKE_BUILD_RPATH "${CMAKE_BUILD_RPATH}"
  30. "${POROS_LIB_DIR}")
  31. include_directories(${POROS_INC_DIR})
  32. if(WIN32)
  33. message(FATAL_ERROR "Poros Backend doesn't support Windows now.")
  34. elseif(APPLE)
  35. message(FATAL_ERROR "Poros Backend doesn't support Mac OSX now.")
  36. else()
  37. set(POROS_COMPILE_LIB
  38. "${POROS_INSTALL_DIR}/lib/libporos.so"
  39. CACHE FILEPATH "poros compile library." FORCE)
  40. endif(WIN32)
  41. set(POROS_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/")
  42. set(POROS_VERSION "0.1.0")
  43. if(WIN32)
  44. message(FATAL_ERROR "Poros Backend doesn't support Windows now.")
  45. elseif(APPLE)
  46. message(FATAL_ERROR "Poros Backend doesn't support Mac OSX now.")
  47. else()
  48. if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
  49. message(FATAL_ERROR "Poros Backend doesn't support linux aarch64 now.")
  50. else()
  51. if(WITH_GPU)
  52. set(POROS_FILE "poros_manylinux_torch1.12.1_cu116_trt8.4_gcc82-${POROS_VERSION}.tar.gz")
  53. else()
  54. message(FATAL_ERROR "Poros currently only provides precompiled packages for the GPU version.")
  55. endif()
  56. endif()
  57. endif()
  58. set(POROS_URL "${POROS_URL_BASE}${POROS_FILE}")
  59. ExternalProject_Add(
  60. ${POROS_PROJECT}
  61. ${EXTERNAL_PROJECT_LOG_ARGS}
  62. URL ${POROS_URL}
  63. PREFIX ${POROS_PREFIX_DIR}
  64. DOWNLOAD_NO_PROGRESS 1
  65. CONFIGURE_COMMAND ""
  66. BUILD_COMMAND ""
  67. UPDATE_COMMAND ""
  68. INSTALL_COMMAND
  69. ${CMAKE_COMMAND} -E copy_directory ${POROS_SOURCE_DIR} ${POROS_INSTALL_DIR}
  70. BUILD_BYPRODUCTS ${POROS_COMPILE_LIB})
  71. add_library(external_poros STATIC IMPORTED GLOBAL)
  72. set_property(TARGET external_poros PROPERTY IMPORTED_LOCATION
  73. ${POROS_COMPILE_LIB})
  74. add_dependencies(external_poros ${POROS_PROJECT})
  75. # Download libtorch.so with ABI=1
  76. set(TORCH_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/")
  77. set(TORCH_FILE "libtorch-cxx11-abi-shared-with-deps-1.12.1-cu116.zip")
  78. set(TORCH_URL "${TORCH_URL_BASE}${TORCH_FILE}")
  79. message(STATUS "Use the default Torch lib from: ${TORCH_URL}")
  80. download_and_decompress(${TORCH_URL} ${CMAKE_CURRENT_BINARY_DIR}/${TORCH_FILE} ${THIRD_PARTY_PATH}/install)
  81. if(EXISTS ${THIRD_PARTY_PATH}/install/torch)
  82. file(REMOVE_RECURSE ${THIRD_PARTY_PATH}/install/torch)
  83. endif()
  84. file(RENAME ${THIRD_PARTY_PATH}/install/libtorch/ ${THIRD_PARTY_PATH}/install/torch)
  85. set(TORCH_INCLUDE_DIRS ${THIRD_PARTY_PATH}/install/torch/include)
  86. find_library(TORCH_LIBRARY torch ${THIRD_PARTY_PATH}/install/torch/lib NO_DEFAULT_PATH)
  87. include_directories(${TORCH_INCLUDE_DIRS})
  88. list(APPEND DEPEND_LIBS ${TORCH_LIBRARY})