set_up_docker_and_build_cpp.sh 3.8 KB

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