diff --git a/onnxruntime/python/tools/tensorrt/perf/build/build_image.py b/onnxruntime/python/tools/tensorrt/perf/build/build_image.py index 2ae64a72d0..b95ad3c0a5 100644 --- a/onnxruntime/python/tools/tensorrt/perf/build/build_image.py +++ b/onnxruntime/python/tools/tensorrt/perf/build/build_image.py @@ -14,9 +14,10 @@ import sys from typing import List, Optional TRT_DOCKER_FILES = { - "8.4": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_6_tensorrt8_4", - "8.5": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_5", - "8.6": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_6", + "8.4.cuda_11_6_cudnn_8": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_6_tensorrt8_4", + "8.5.cuda_11_8_cudnn_8": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_5", + "8.6.cuda_11_8_cudnn_8": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda11_8_tensorrt8_6", + "8.6.cuda_12_3_cudnn_9": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda12_3_tensorrt8_6", "BIN": "tools/ci_build/github/linux/docker/Dockerfile.ubuntu_tensorrt_bin", } @@ -99,18 +100,11 @@ def docker_build_trt(args: argparse.Namespace): :param args: The arguments to this script. """ - if not is_valid_ver_str(args.trt_version, min_comps=2, max_comps=4): - print(f"[ERROR]: Invalid TensorRT version '{args.trt_version}'", file=sys.stderr) - sys.exit(1) - - vers_comps = args.trt_version.split(".") - trt_ver_key = f"{vers_comps[0]}.{vers_comps[1]}" - - if trt_ver_key not in TRT_DOCKER_FILES: + if args.trt_version not in TRT_DOCKER_FILES: print(f"[ERROR]: TensorRT version '{args.trt_version}' is currently unsupported", file=sys.stderr) sys.exit(1) - docker_file = TRT_DOCKER_FILES[trt_ver_key] + docker_file = TRT_DOCKER_FILES[args.trt_version] docker_file_path = os.path.normpath(os.path.join(args.repo_path, docker_file)) if not os.path.isfile(docker_file_path): @@ -144,11 +138,7 @@ def docker_build_trt_bin(args: argparse.Namespace): sys.exit(1) if not is_valid_ver_str(args.tar_cuda_version, 2, 2): - print("[ERROR]: Must specify a valid CUDA version for binary TensorRT installs (e.g., 11.x)", file=sys.stderr) - sys.exit(1) - - if not is_valid_ver_str(args.tar_cudnn_version, 2, 2): - print("[ERROR]: Must specify a valid cuDNN version for binary TensorRT installs (e.g., 8.x)", file=sys.stderr) + print("[ERROR]: Must specify a valid CUDA version for binary TensorRT installs (e.g., 12.4)", file=sys.stderr) sys.exit(1) if not os.path.isfile(docker_file_path): @@ -170,8 +160,6 @@ def docker_build_trt_bin(args: argparse.Namespace): "--build-arg", f"TAR_CUDA_VERSION={args.tar_cuda_version}", "--build-arg", - f"TAR_CUDNN_VERSION={args.tar_cudnn_version}", - "--build-arg", f"TRT_BINS_DIR={args.trt_bins_dir}", "-f", f"{docker_file_path}", @@ -195,7 +183,9 @@ def parse_arguments() -> argparse.Namespace: parser.add_argument("-r", "--repo_path", required=True, help="Path to the onnxruntime repository") parser.add_argument("-i", "--image_name", required=True, help="The resulting Docker image name") parser.add_argument("-b", "--branch", default="main", help="Name of the onnxruntime git branch to checkout") - parser.add_argument("-t", "--trt_version", default="8.6.1.6", help="TensorRT version (e.g., 8.6.1.6)") + parser.add_argument( + "-t", "--trt_version", default="8.6.cuda_11_8_cudnn_8", help="TensorRT version (e.g., 8.6.cuda_11_8_cudnn_8)" + ) parser.add_argument("-a", "--cuda_arch", default="75", help="CUDA architecture (e.g., 75)") # Command-line options for installing TensorRT from binaries. @@ -208,12 +198,7 @@ def parse_arguments() -> argparse.Namespace: parser.add_argument( "--tar_cuda_version", default="", - help="CUDA version (e.g., 11.8) used to find TensorRT EA binary tar.gz package", - ) - parser.add_argument( - "--tar_cudnn_version", - default="", - help="CUDA version (e.g., 8.6) used to find TensorRT EA binary tar.gz package", + help="CUDA version (e.g., 12.4) used to find TensorRT EA binary tar.gz package", ) parser.add_argument("--trt_bins_dir", default="", help="Directory containing TensorRT tar.gz package") parser.add_argument( diff --git a/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-daily-perf-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-daily-perf-pipeline.yml index 9f3a127262..15f558e6f9 100644 --- a/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-daily-perf-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-gpu-tensorrt-daily-perf-pipeline.yml @@ -8,15 +8,16 @@ parameters: - name: TrtVersion displayName: TensorRT Version type: string - default: 8.6.1.6 + default: 8.6.cuda_11_8_cudnn_8 values: - - 8.4.1.5 - - 8.5.1.1 - - 8.6.1.6 + - 8.4.cuda_11_6_cudnn_8 + - 8.5.cuda_11_8_cudnn_8 + - 8.6.cuda_11_8_cudnn_8 + - 8.6.cuda_12_3_cudnn_9 - BIN - name: UseTensorrtOssParser - displayName: Use TensorRT-OSS Parser + displayName: Use TensorRT-OSS Parser (not compatible with BIN) type: boolean default: false @@ -86,11 +87,11 @@ jobs: - script: 'ls -al $(trtBinsDir)' displayName: 'Show available TensorRT .tar.gz packages' - - script: 'cp $(trtBinsDir)/TensorRT-$(trtVersion).Linux.x86_64-gnu.cuda-$(tarCudaVersion).cudnn$(tarCudnnVersion).tar.gz $(Build.SourcesDirectory)/onnxruntime/python/tools/tensorrt/perf/build/' + - script: 'cp $(trtBinsDir)/TensorRT-$(trtVersion).Linux.x86_64-gnu.cuda-$(tarCudaVersion).tar.gz $(Build.SourcesDirectory)/onnxruntime/python/tools/tensorrt/perf/build/' displayName: 'Copy TensorRT .tar.gz package into Docker build directory' - - script: 'python3 $(Build.SourcesDirectory)/onnxruntime/python/tools/tensorrt/perf/build/build_image.py -r $(Build.SourcesDirectory) -i $(image) -b $(branchName) -t $(trtVersion) -a 75 --install_bin --tar_cuda_version=$(tarCudaVersion) --tar_cudnn_version=$(tarCudnnVersion) --trt_bins_dir=.' - displayName: 'Install TensorRT from binaries and build latest ORT Image' + - script: 'python3 $(Build.SourcesDirectory)/onnxruntime/python/tools/tensorrt/perf/build/build_image.py -r $(Build.SourcesDirectory) -i $(image) -b $(branchName) -t $(trtVersion) -a 75 --install_bin --tar_cuda_version=$(tarCudaVersion) --trt_bins_dir=.' + displayName: 'Install TensorRT $(tarTrtVersion) from binaries and build latest ORT Image' workingDirectory: '$(Build.SourcesDirectory)/onnxruntime/python/tools/tensorrt/perf/build' # Build ORT with TensorRT built-in parser diff --git a/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda12_3_tensorrt8_6 b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda12_3_tensorrt8_6 new file mode 100644 index 0000000000..9493480784 --- /dev/null +++ b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_cuda12_3_tensorrt8_6 @@ -0,0 +1,96 @@ +# -------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------- +# Dockerfile to run ONNXRuntime with TensorRT integration + +# Build base image with required system packages +FROM nvidia/cuda:12.3.1-devel-ubuntu20.04 AS base + +# The local directory into which to build and install CMAKE +ARG ONNXRUNTIME_LOCAL_CODE_DIR=/code + +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/src/tensorrt/bin:${ONNXRUNTIME_LOCAL_CODE_DIR}/cmake-3.27.3-linux-x86_64/bin:/opt/miniconda/bin:${PATH} +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update &&\ + apt-get install -y sudo git bash unattended-upgrades wget +RUN unattended-upgrade + +# Install python3 +RUN apt-get install -y --no-install-recommends \ + python3 \ + python3-pip \ + python3-dev \ + python3-wheel &&\ + cd /usr/local/bin &&\ + ln -s /usr/bin/python3 python &&\ + ln -s /usr/bin/pip3 pip; + +RUN pip install --upgrade pip +RUN pip install setuptools>=68.2.2 + +# Install cuDNN v9 +RUN apt-get -y install cudnn9-cuda-12 + +# Install TensorRT +RUN v="8.6.1.6-1+cuda12.0" &&\ + apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub &&\ + apt-get update &&\ + sudo apt-get install -y libnvinfer8=${v} libnvonnxparsers8=${v} libnvparsers8=${v} libnvinfer-plugin8=${v} libnvinfer-lean8=${v} libnvinfer-vc-plugin8=${v} libnvinfer-dispatch8=${v}\ + libnvinfer-headers-dev=${v} libnvinfer-headers-plugin-dev=${v} libnvinfer-dev=${v} libnvonnxparsers-dev=${v} libnvparsers-dev=${v} libnvinfer-plugin-dev=${v} libnvinfer-lean-dev=${v} libnvinfer-vc-plugin-dev=${v} libnvinfer-dispatch-dev=${v}\ + python3-libnvinfer=${v} libnvinfer-samples=${v} tensorrt-dev=${v} tensorrt-libs=${v} + +# Compile trtexec +RUN cd /usr/src/tensorrt/samples/trtexec && make + +# Install Valgrind +RUN apt-get install -y valgrind + +# Build final image from base. Builds ORT. +FROM base as final +ARG BUILD_USER=onnxruntimedev +ARG BUILD_UID=1000 +RUN adduser --gecos 'onnxruntime Build User' --disabled-password $BUILD_USER --uid $BUILD_UID +USER $BUILD_USER + +# ONNX Runtime arguments + +# URL to the github repo from which to clone ORT. +ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime + +# The local directory into which to clone ORT. +ARG ONNXRUNTIME_LOCAL_CODE_DIR=/code + +# The git branch of ORT to checkout and build. +ARG ONNXRUNTIME_BRANCH=main + +# Optional. The specific commit to pull and build from. If not set, the latest commit is used. +ARG ONNXRUNTIME_COMMIT_ID + +# The supported CUDA architecture +ARG CMAKE_CUDA_ARCHITECTURES=75 + +WORKDIR ${ONNXRUNTIME_LOCAL_CODE_DIR} + +# Clone ORT repository with branch +RUN git clone --single-branch --branch ${ONNXRUNTIME_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime &&\ + /bin/sh onnxruntime/dockerfiles/scripts/install_common_deps.sh + +WORKDIR ${ONNXRUNTIME_LOCAL_CODE_DIR}/onnxruntime + +# Reset to a specific commit if specified by build args. +RUN if [ -z "$ONNXRUNTIME_COMMIT_ID" ] ; then echo "Building branch ${ONNXRUNTIME_BRANCH}" ;\ + else echo "Building branch ${ONNXRUNTIME_BRANCH} @ commit ${ONNXRUNTIME_COMMIT_ID}" &&\ + git reset --hard ${ONNXRUNTIME_COMMIT_ID} && git submodule update --recursive ; fi + +# Build ORT +ENV CUDA_MODULE_LOADING "LAZY" +ARG PARSER_CONFIG="" +RUN /bin/sh build.sh ${PARSER_CONFIG} --parallel --build_shared_lib --cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_tensorrt --tensorrt_home /usr/lib/x86_64-linux-gnu/ --config Release --build_wheel --skip_tests --skip_submodule_sync --cmake_extra_defines '"CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'"' + +# Switch to root to continue following steps of CI +USER root + +# Intall ORT wheel +RUN pip install ${ONNXRUNTIME_LOCAL_CODE_DIR}/onnxruntime/build/Linux/Release/dist/*.whl \ No newline at end of file diff --git a/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_tensorrt_bin b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_tensorrt_bin index 21b09b2d89..a26bf88fbb 100644 --- a/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_tensorrt_bin +++ b/tools/ci_build/github/linux/docker/Dockerfile.ubuntu_tensorrt_bin @@ -4,29 +4,15 @@ # -------------------------------------------------------------- # Dockerfile to run ONNXRuntime with TensorRT installed from provided binaries -FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04 +# Build base image with required system packages +FROM nvidia/cuda:12.3.1-devel-ubuntu20.04 AS base +# The local directory into which to build and install CMAKE +ARG ONNXRUNTIME_LOCAL_CODE_DIR=/code -# ONNX Runtime Variables -ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime -ARG ONNXRUNTIME_BRANCH=main -ARG CMAKE_CUDA_ARCHITECTURES=37;50;52;60;61;70;75;80 - -# Must provide version numbers used to build the name of the tar file containing TensorRT binaries. -# See: https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-tar -ARG TAR_TRT_VERSION -ARG TAR_CUDA_VERSION -ARG TAR_CUDNN_VERSION - -# Directory containing TensorRT tar.gz installation package -ARG TRT_BINS_DIR=. - -ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:/code/cmake-3.27.3-linux-x86_64/bin:/opt/miniconda/bin:${PATH} - +ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${ONNXRUNTIME_LOCAL_CODE_DIR}/cmake-3.27.3-linux-x86_64/bin:/opt/miniconda/bin:${PATH} ENV DEBIAN_FRONTEND=noninteractive -COPY ${TRT_BINS_DIR}/TensorRT-${TAR_TRT_VERSION}.Linux.x86_64-gnu.cuda-${TAR_CUDA_VERSION}.cudnn${TAR_CUDNN_VERSION}.tar.gz /TensorRT-${TAR_TRT_VERSION}.tar.gz - RUN apt-get update &&\ apt-get install -y sudo git bash unattended-upgrades wget RUN unattended-upgrade @@ -44,22 +30,77 @@ RUN apt-get install -y --no-install-recommends \ RUN pip install --upgrade pip RUN pip install setuptools>=68.2.2 +# Install cuDNN v9 +RUN apt-get -y install cudnn9-cuda-12 + +# Install TensorRT +# Must provide version numbers used to build the name of the tar file containing TensorRT binaries. +# See: https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-tar +ARG TAR_TRT_VERSION +ARG TAR_CUDA_VERSION + +# Directory containing TensorRT tar.gz installation package +ARG TRT_BINS_DIR=. +COPY ${TRT_BINS_DIR}/TensorRT-${TAR_TRT_VERSION}.Linux.x86_64-gnu.cuda-${TAR_CUDA_VERSION}.tar.gz /TensorRT-${TAR_TRT_VERSION}.tar.gz + # Install TensorRT from tar.gz RUN tar -xzvf /TensorRT-${TAR_TRT_VERSION}.tar.gz RUN cd /TensorRT-${TAR_TRT_VERSION}/python &&\ - python3 -m pip install tensorrt-${TAR_TRT_VERSION}-cp38-none-linux_x86_64.whl + python3 -m pip install tensorrt*cp38*.whl RUN cp -r /TensorRT-${TAR_TRT_VERSION}/lib/* /usr/lib/x86_64-linux-gnu/ RUN cp /TensorRT-${TAR_TRT_VERSION}/include/* /usr/local/include/ RUN cp /TensorRT-${TAR_TRT_VERSION}/bin/* /usr/local/bin/ -WORKDIR /code +# Install Valgrind +RUN apt-get install -y valgrind + +# Build final image from base. Builds ORT. +FROM base as final +ARG BUILD_USER=onnxruntimedev +ARG BUILD_UID=1000 +RUN adduser --gecos 'onnxruntime Build User' --disabled-password $BUILD_USER --uid $BUILD_UID +USER $BUILD_USER + +# ONNX Runtime arguments + +# URL to the github repo from which to clone ORT. +ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime + +# The local directory into which to clone ORT. +ARG ONNXRUNTIME_LOCAL_CODE_DIR=/code + +# The git branch of ORT to checkout and build. +ARG ONNXRUNTIME_BRANCH=main + +# Optional. The specific commit to pull and build from. If not set, the latest commit is used. +ARG ONNXRUNTIME_COMMIT_ID + +# The supported CUDA architecture +ARG CMAKE_CUDA_ARCHITECTURES=75 # Prepare onnxruntime repository & build onnxruntime with TensorRT +WORKDIR ${ONNXRUNTIME_LOCAL_CODE_DIR} + +# Clone ORT repository with branch RUN git clone --single-branch --branch ${ONNXRUNTIME_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime &&\ - /bin/sh onnxruntime/dockerfiles/scripts/install_common_deps.sh &&\ - cd onnxruntime &&\ - /bin/sh build.sh --parallel --build_shared_lib --cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_tensorrt --tensorrt_home /usr/lib/x86_64-linux-gnu/ --config Release --build_wheel --skip_tests --skip_submodule_sync --cmake_extra_defines '"CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'"' &&\ - pip install /code/onnxruntime/build/Linux/Release/dist/*.whl &&\ - cd .. + /bin/sh onnxruntime/dockerfiles/scripts/install_common_deps.sh + +WORKDIR ${ONNXRUNTIME_LOCAL_CODE_DIR}/onnxruntime + +# Reset to a specific commit if specified by build args. +RUN if [ -z "$ONNXRUNTIME_COMMIT_ID" ] ; then echo "Building branch ${ONNXRUNTIME_BRANCH}" ;\ + else echo "Building branch ${ONNXRUNTIME_BRANCH} @ commit ${ONNXRUNTIME_COMMIT_ID}" &&\ + git reset --hard ${ONNXRUNTIME_COMMIT_ID} && git submodule update --recursive ; fi + +# Build ORT +ENV CUDA_MODULE_LOADING "LAZY" +ARG PARSER_CONFIG="" +RUN /bin/sh build.sh ${PARSER_CONFIG} --parallel --build_shared_lib --cuda_home /usr/local/cuda --cudnn_home /usr/lib/x86_64-linux-gnu/ --use_tensorrt --tensorrt_home /usr/lib/x86_64-linux-gnu/ --config Release --build_wheel --skip_tests --skip_submodule_sync --cmake_extra_defines '"CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'"' + +# Switch to root to continue following steps of CI +USER root + +# Intall ORT wheel +RUN pip install ${ONNXRUNTIME_LOCAL_CODE_DIR}/onnxruntime/build/Linux/Release/dist/*.whl \ No newline at end of file