set_up_docker_and_build_py.sh 3.6 KB

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