set_up_docker_and_build_py.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # input
  3. CONTAINER_NAME="${CONTAINER_NAME:-build}"
  4. WITH_GPU="${WITH_GPU:-ON}"
  5. ENABLE_BENCHMARK="${ENABLE_BENCHMARK:-OFF}"
  6. DEBUG="${DEBUG:-OFF}"
  7. PYTHON_VERSION="${PYTHON_VERSION:-3.10.0}"
  8. ENABLE_PADDLE_BACKEND="${ENABLE_PADDLE_BACKEND:-ON}"
  9. ENABLE_ORT_BACKEND="${ENABLE_ORT_BACKEND:-ON}"
  10. ENABLE_OPENVINO_BACKEND="${ENABLE_OPENVINO_BACKEND:-ON}"
  11. ENABLE_TRT_BACKEND="${ENABLE_TRT_BACKEND:-ON}"
  12. TRT_DIRECTORY="${TRT_DIRECTORY:-Default}"
  13. ENABLE_VISION="${ENABLE_VISION:-ON}"
  14. ENABLE_TEXT="${ENABLE_TEXT:-ON}"
  15. if [ "$WITH_GPU" = "OFF" ]; then
  16. ENABLE_TRT_BACKEND="OFF"
  17. fi
  18. if [ "$ENABLE_PADDLE_BACKEND" = "ON" ] && [ -z "$PADDLEINFERENCE_URL" ]; then
  19. if [ "$WITH_GPU" = "ON" ]; then
  20. PADDLEINFERENCE_URL=https://paddle-qa.bj.bcebos.com/paddle-pipeline/GITHUB_Docker_Compile_Test_Cuda118_cudnn860_Trt8522_R1/791e99fc54c36151b9e5f1245e0fc8ae5d8a282b/paddle_inference.tgz
  21. PADDLEINFERENCE_VERSION="3.0.0-rc"
  22. else
  23. PADDLEINFERENCE_URL=https://paddle-qa.bj.bcebos.com/paddle-pipeline/GITHUB_Docker_Compile_Test_CPU_R1/791e99fc54c36151b9e5f1245e0fc8ae5d8a282b/paddle_inference.tgz
  24. PADDLEINFERENCE_VERSION="3.0.0-rc"
  25. fi
  26. fi
  27. DOCKER_IMAGE="ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlepaddle/paddle_manylinux_devel:cuda11.8-cudnn8.6-trt8.5-gcc8.2"
  28. # Set variables
  29. CMAKE_CXX_COMPILER="/usr/local/gcc-8.2/bin/g++"
  30. # Get the current script directory and compute the directory to mount
  31. SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
  32. ULTRAINFER_DIR="$(realpath "$SCRIPT_DIR/../../../")"
  33. # Set the Docker startup command
  34. if [ "$WITH_GPU" = "ON" ]; then
  35. DOCKER_CMD=$(cat << EOF
  36. docker run --gpus all -it --name="${CONTAINER_NAME}" --shm-size=128g --net=host \
  37. -v "${ULTRAINFER_DIR}":/workspace \
  38. -e CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
  39. -e "http_proxy=${http_proxy}" \
  40. -e "https_proxy=${https_proxy}" \
  41. "${DOCKER_IMAGE}" /bin/bash -c "
  42. cd /workspace && \
  43. ldconfig && \
  44. ./ultra-infer/scripts/linux/_build_py.sh --with-gpu "${WITH_GPU}" --enable-benchmark "${ENABLE_BENCHMARK}" --python "${PYTHON_VERSION}" --paddleinference-url "${PADDLEINFERENCE_URL}" --paddleinference-version "${PADDLEINFERENCE_VERSION}" --enable-paddle-backend "${ENABLE_PADDLE_BACKEND}" --enable-ort-backend "${ENABLE_ORT_BACKEND}" --enable-openvino-backend "${ENABLE_OPENVINO_BACKEND}" --enable-trt-backend "${ENABLE_TRT_BACKEND}" --trt-directory "${TRT_DIRECTORY}" --enable-vision "${ENABLE_VISION}" --enable-text "${ENABLE_TEXT}" && \
  45. tail -f /dev/null"
  46. EOF
  47. )
  48. else
  49. DOCKER_CMD=$(cat << EOF
  50. docker run -it --name="${CONTAINER_NAME}" --shm-size=128g --net=host \
  51. -v "${ULTRAINFER_DIR}":/workspace \
  52. -e CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
  53. -e "http_proxy=${http_proxy}" \
  54. -e "https_proxy=${https_proxy}" \
  55. "${DOCKER_IMAGE}" /bin/bash -c "
  56. cd /workspace && \
  57. ./ultra-infer/scripts/linux/_build_py.sh --with-gpu "${WITH_GPU}" --enable-benchmark "${ENABLE_BENCHMARK}" --python "${PYTHON_VERSION}" --paddleinference-url "${PADDLEINFERENCE_URL}" --paddleinference-version "${PADDLEINFERENCE_VERSION}" --enable-paddle-backend "${ENABLE_PADDLE_BACKEND}" --enable-ort-backend "${ENABLE_ORT_BACKEND}" --enable-openvino-backend "${ENABLE_OPENVINO_BACKEND}" --enable-trt-backend "${ENABLE_TRT_BACKEND}" --trt-directory "${TRT_DIRECTORY}" --enable-vision "${ENABLE_VISION}" --enable-text "${ENABLE_TEXT}" && \
  58. tail -f /dev/null"
  59. EOF
  60. )
  61. fi
  62. # If in debug mode, replace --rm with -it and keep the container running
  63. if [ "$DEBUG" = "OFF" ]; then
  64. DOCKER_CMD="${DOCKER_CMD/-it/--rm}"
  65. DOCKER_CMD="${DOCKER_CMD/ && tail -f \/dev\/null/}"
  66. fi
  67. # Check if a Docker container with the same name already exists
  68. if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
  69. echo "Error: A Docker container with the name '${CONTAINER_NAME}' already exists."
  70. echo "Please remove the existing container or choose a different container name."
  71. exit 1
  72. fi
  73. echo "Starting Docker container..."
  74. eval "$DOCKER_CMD"