set_up_docker_and_build_py.sh 2.7 KB

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