_build_py.sh 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. set -e
  3. while [[ "$#" -gt 0 ]]; do
  4. case "$1" in
  5. --with-gpu) WITH_GPU="$2"; shift ;;
  6. --enable-benchmark) ENABLE_BENCHMARK="$2"; shift ;;
  7. --python) PYTHON_VERSION="$2"; shift ;;
  8. --enable-ort-backend) ENABLE_ORT_BACKEND="$2"; shift ;;
  9. --enable-openvino-backend) ENABLE_OPENVINO_BACKEND="$2"; shift ;;
  10. --enable-trt-backend) ENABLE_TRT_BACKEND="$2"; shift ;;
  11. --trt-directory) TRT_DIRECTORY="$2"; shift ;;
  12. *) echo "Unknown parameter passed: $1"; exit 1 ;;
  13. esac
  14. shift
  15. done
  16. export DEBIAN_FRONTEND='noninteractive'
  17. export TZ='Asia/Shanghai'
  18. cd /workspace
  19. if [ "$CUDA_VERSION" = "11.8" ]; then
  20. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
  21. fi
  22. yum clean all
  23. yum makecache
  24. yum -y update ca-certificates
  25. yum install -y wget bzip2
  26. yum install -y epel-release
  27. yum install -y patchelf rapidjson-devel
  28. PYTHON_DIR="/opt/_internal/cpython-${PYTHON_VERSION}"
  29. if [ -d "$PYTHON_DIR" ]; then
  30. export LD_LIBRARY_PATH="${PYTHON_DIR}/lib:${LD_LIBRARY_PATH}"
  31. export PATH="${PYTHON_DIR}/bin:${PATH}"
  32. else
  33. echo "Python version ${PYTHON_VERSION} not found in ${PYTHON_DIR}."
  34. exit 1
  35. fi
  36. python -m pip install numpy pandas
  37. cd /workspace/ultra-infer
  38. if [[ "$CUDA_VERSION" = "12.6" || "$CUDA_VERSION" = "12.9" ]]; then
  39. CC=/opt/rh/gcc-toolset-11/root/usr/bin/gcc
  40. CXX=/opt/rh/gcc-toolset-11/root/usr/bin/g++
  41. ENABLE_TRT_BACKEND=OFF
  42. TRT_DIRECTORY=""
  43. else
  44. TRT_VERSION='8.6.1.6'
  45. CUDA_VERSION='11.8'
  46. CUDNN_VERSION='8.6'
  47. if [ "$ENABLE_TRT_BACKEND" = "ON" ] && [ "$TRT_DIRECTORY" = "Default" ]; then
  48. rm -rf "TensorRT-${TRT_VERSION}" "TensorRT-${TRT_VERSION}.Linux.x86_64-gnu.cuda-${CUDA_VERSION}.tar.gz"
  49. http_proxy= https_proxy= wget "https://fastdeploy.bj.bcebos.com/resource/TensorRT/TensorRT-${TRT_VERSION}.Linux.x86_64-gnu.cuda-${CUDA_VERSION}.tar.gz"
  50. tar -xzvf "TensorRT-${TRT_VERSION}.Linux.x86_64-gnu.cuda-${CUDA_VERSION}.tar.gz"
  51. TRT_DIRECTORY="/workspace/ultra-infer/TensorRT-${TRT_VERSION}"
  52. fi
  53. CC=/usr/local/gcc-8.2/bin/gcc
  54. CXX=/usr/local/gcc-8.2/bin/g++
  55. fi
  56. export WITH_GPU="${WITH_GPU}"
  57. export ENABLE_TRT_BACKEND="${ENABLE_TRT_BACKEND}"
  58. export TRT_DIRECTORY="${TRT_DIRECTORY}"
  59. export ENABLE_ORT_BACKEND="${ENABLE_ORT_BACKEND}"
  60. export ENABLE_OPENVINO_BACKEND="${ENABLE_OPENVINO_BACKEND}"
  61. export ENABLE_BENCHMARK="${ENABLE_BENCHMARK}"
  62. export ENABLE_PADDLE_BACKEND=OFF
  63. export ENABLE_VISION=OFF
  64. export ENABLE_TEXT=OFF
  65. export CC=$CC
  66. export CXX=$CXX
  67. cd /workspace/ultra-infer/python
  68. python -m pip install wheel
  69. unset http_proxy https_proxy
  70. rm -rf .setuptools-cmake-build build ultra_infer/libs/third_libs dist
  71. python setup.py build
  72. # HACK
  73. patchelf \
  74. --set-rpath '$ORIGIN/libs/third_libs/onnxruntime/lib:$ORIGIN/libs/third_libs/paddle2onnx/lib:$ORIGIN/libs/third_libs/paddle_inference/paddle/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/cryptopp/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/mklml/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/glog/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/protobuf/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/utf8proc/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/xxhash/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/gflags/lib:$ORIGIN/libs/third_libs/paddle_inference/third_party/install/onednn/lib:$ORIGIN/libs/third_libs/tensorrt/lib:$ORIGIN/libs/third_libs/opencv/lib64:$ORIGIN/libs/third_libs/openvino/runtime/lib:$ORIGIN/libs/third_libs/openvino/runtime/3rdparty/tbb/lib' \
  75. build/lib.*/ultra_infer/ultra_infer_main*.so
  76. python setup.py bdist_wheel