set_up_docker_and_build_cpp.sh 2.6 KB

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