|
| 1 | + |
| 2 | +ARG BASE_IMAGE=gitlab-master.nvidia.com:5005/dl/dgx/cuda:12.6-devel-ubuntu22.04--24.10 |
| 3 | +ARG ONNXRUNTIME_VERSION=1.19.2 |
| 4 | +ARG ONNXRUNTIME_REPO=https://github.com/microsoft/onnxruntime |
| 5 | +ARG ONNXRUNTIME_BUILD_CONFIG=Release |
| 6 | + |
| 7 | +ARG ONNXRUNTIME_OPENVINO_VERSION=2024.4.0 |
| 8 | + |
| 9 | +FROM ${BASE_IMAGE} |
| 10 | +WORKDIR /workspace |
| 11 | + |
| 12 | +# Ensure apt-get won't prompt for selecting options |
| 13 | +ENV DEBIAN_FRONTEND=noninteractive |
| 14 | + |
| 15 | +# The Onnx Runtime dockerfile is the collection of steps in |
| 16 | +# https://github.com/microsoft/onnxruntime/tree/master/dockerfiles |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common wget zip ca-certificates build-essential curl libcurl4-openssl-dev libssl-dev patchelf python3-dev python3-pip git gnupg gnupg1 |
| 21 | + |
| 22 | +# Install dependencies from |
| 23 | +# onnxruntime/dockerfiles/scripts/install_common_deps.sh. |
| 24 | +RUN apt update -q=2 \ |
| 25 | + && apt install -y gpg wget \ |
| 26 | + && wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null \ |
| 27 | + && . /etc/os-release \ |
| 28 | + && echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $UBUNTU_CODENAME main" | tee /etc/apt/sources.list.d/kitware.list >/dev/null \ |
| 29 | + && apt-get update -q=2 \ |
| 30 | + && apt-get install -y --no-install-recommends cmake=3.27.7* cmake-data=3.27.7* \ |
| 31 | + && cmake --version |
| 32 | + |
| 33 | + |
| 34 | +# Allow configure to pick up cuDNN where it expects it. |
| 35 | +# (Note: $CUDNN_VERSION is defined by base image) |
| 36 | +RUN _CUDNN_VERSION=$(echo $CUDNN_VERSION | cut -d. -f1-2) && mkdir -p /usr/local/cudnn-$_CUDNN_VERSION/cuda/include && ln -s /usr/include/cudnn.h /usr/local/cudnn-$_CUDNN_VERSION/cuda/include/cudnn.h && mkdir -p /usr/local/cudnn-$_CUDNN_VERSION/cuda/lib64 && ln -s /etc/alternatives/libcudnn_so /usr/local/cudnn-$_CUDNN_VERSION/cuda/lib64/libcudnn.so |
| 37 | + |
| 38 | +# Install OpenVINO |
| 39 | +ARG ONNXRUNTIME_OPENVINO_VERSION |
| 40 | +ENV INTEL_OPENVINO_DIR /opt/intel/openvino_${ONNXRUNTIME_OPENVINO_VERSION} |
| 41 | + |
| 42 | +ARG OPENVINO_SHORT_VERSION=2024.4 |
| 43 | +ARG OPENVINO_VERSION_WITH_BUILD_NUMBER=2024.4.0.16579.c3152d32c9c |
| 44 | + |
| 45 | +# Step 1: Download and install core components |
| 46 | +# Ref: https://docs.openvino.ai/2024/get-started/install-openvino/install-openvino-archive-linux.html#step-1-download-and-install-the-openvino-core-components |
| 47 | +RUN curl -L https://storage.openvinotoolkit.org/repositories/openvino/packages/${OPENVINO_SHORT_VERSION}/linux/l_openvino_toolkit_ubuntu22_${OPENVINO_VERSION_WITH_BUILD_NUMBER}_x86_64.tgz --output openvino_${ONNXRUNTIME_OPENVINO_VERSION}.tgz && tar -xf openvino_${ONNXRUNTIME_OPENVINO_VERSION}.tgz && mkdir -p ${INTEL_OPENVINO_DIR} && mv l_openvino_toolkit_ubuntu22_${OPENVINO_VERSION_WITH_BUILD_NUMBER}_x86_64/* ${INTEL_OPENVINO_DIR} && rm openvino_${ONNXRUNTIME_OPENVINO_VERSION}.tgz && (cd ${INTEL_OPENVINO_DIR}/install_dependencies && ./install_openvino_dependencies.sh -y) && ln -s ${INTEL_OPENVINO_DIR} ${INTEL_OPENVINO_DIR}/../openvino_`echo ${ONNXRUNTIME_OPENVINO_VERSION} | awk '{print substr($0,0,4)}'` |
| 48 | + |
| 49 | +# Step 2: Configure the environment |
| 50 | +# Ref: https://docs.openvino.ai/2024/get-started/install-openvino/install-openvino-archive-linux.html#step-2-configure-the-environment |
| 51 | +ENV OpenVINO_DIR=$INTEL_OPENVINO_DIR/runtime/cmake |
| 52 | +ENV LD_LIBRARY_PATH $INTEL_OPENVINO_DIR/runtime/lib/intel64:$LD_LIBRARY_PATH |
| 53 | +ENV PKG_CONFIG_PATH=$INTEL_OPENVINO_DIR/runtime/lib/intel64/pkgconfig |
| 54 | +ENV PYTHONPATH $INTEL_OPENVINO_DIR/python/python3.10:$INTEL_OPENVINO_DIR/python/python3:$PYTHONPATH |
| 55 | + |
| 56 | +# |
| 57 | +# ONNX Runtime build |
| 58 | +# |
| 59 | +ARG ONNXRUNTIME_VERSION |
| 60 | +ARG ONNXRUNTIME_REPO |
| 61 | +ARG ONNXRUNTIME_BUILD_CONFIG |
| 62 | + |
| 63 | +RUN git clone -b rel-${ONNXRUNTIME_VERSION} --recursive ${ONNXRUNTIME_REPO} onnxruntime && (cd onnxruntime && git submodule update --init --recursive) |
| 64 | + |
| 65 | +WORKDIR /workspace/onnxruntime |
| 66 | +ARG COMMON_BUILD_ARGS="--config ${ONNXRUNTIME_BUILD_CONFIG} --skip_submodule_sync --parallel --build_shared_lib --build_dir /workspace/build --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES='75;80;86;90' " |
| 67 | + |
| 68 | +RUN ./build.sh ${COMMON_BUILD_ARGS} --update --build --use_cuda --cuda_home "/usr/lib" --cudnn_home "/usr/lib" --use_tensorrt --use_tensorrt_builtin_parser --tensorrt_home "/usr/src/tensorrt" --use_openvino CPU |
| 69 | + |
| 70 | +# |
| 71 | +# Copy all artifacts needed by the backend to /opt/onnxruntime |
| 72 | +# |
| 73 | +WORKDIR /opt/onnxruntime |
| 74 | + |
| 75 | +RUN mkdir -p /opt/onnxruntime && cp /workspace/onnxruntime/LICENSE /opt/onnxruntime && cat /workspace/onnxruntime/cmake/external/onnx/VERSION_NUMBER > /opt/onnxruntime/ort_onnx_version.txt |
| 76 | + |
| 77 | +# ONNX Runtime headers, libraries and binaries |
| 78 | +RUN mkdir -p /opt/onnxruntime/include && cp /workspace/onnxruntime/include/onnxruntime/core/session/onnxruntime_c_api.h /opt/onnxruntime/include && cp /workspace/onnxruntime/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h /opt/onnxruntime/include && cp /workspace/onnxruntime/include/onnxruntime/core/providers/cpu/cpu_provider_factory.h /opt/onnxruntime/include |
| 79 | + |
| 80 | +RUN mkdir -p /opt/onnxruntime/lib && cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/libonnxruntime_providers_shared.so /opt/onnxruntime/lib && cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/libonnxruntime.so /opt/onnxruntime/lib |
| 81 | + |
| 82 | +RUN mkdir -p /opt/onnxruntime/bin && cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/onnxruntime_perf_test /opt/onnxruntime/bin && cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/onnx_test_runner /opt/onnxruntime/bin && (cd /opt/onnxruntime/bin && chmod a+x *) |
| 83 | + |
| 84 | +RUN cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/libonnxruntime_providers_cuda.so /opt/onnxruntime/lib |
| 85 | + |
| 86 | +# TensorRT specific headers and libraries |
| 87 | +RUN cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/libonnxruntime_providers_tensorrt.so /opt/onnxruntime/lib |
| 88 | + |
| 89 | +# OpenVino specific headers and libraries |
| 90 | +RUN cp -r ${INTEL_OPENVINO_DIR}/docs/licensing /opt/onnxruntime/LICENSE.openvino |
| 91 | + |
| 92 | +RUN cp /workspace/onnxruntime/include/onnxruntime/core/providers/openvino/openvino_provider_factory.h /opt/onnxruntime/include |
| 93 | + |
| 94 | +RUN apt-get update && apt-get install -y --no-install-recommends libtbb2 |
| 95 | + |
| 96 | +RUN cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/libonnxruntime_providers_openvino.so /opt/onnxruntime/lib && cp ${INTEL_OPENVINO_DIR}/runtime/lib/intel64/libopenvino.so.${ONNXRUNTIME_OPENVINO_VERSION} /opt/onnxruntime/lib && cp ${INTEL_OPENVINO_DIR}/runtime/lib/intel64/libopenvino_c.so.${ONNXRUNTIME_OPENVINO_VERSION} /opt/onnxruntime/lib && cp ${INTEL_OPENVINO_DIR}/runtime/lib/intel64/libopenvino_intel_cpu_plugin.so /opt/onnxruntime/lib && cp ${INTEL_OPENVINO_DIR}/runtime/lib/intel64/libopenvino_ir_frontend.so.${ONNXRUNTIME_OPENVINO_VERSION} /opt/onnxruntime/lib && cp ${INTEL_OPENVINO_DIR}/runtime/lib/intel64/libopenvino_onnx_frontend.so.${ONNXRUNTIME_OPENVINO_VERSION} /opt/onnxruntime/lib && cp /usr/lib/x86_64-linux-gnu/libtbb.so.* /opt/onnxruntime/lib |
| 97 | + |
| 98 | +RUN OV_SHORT_VERSION=`echo ${ONNXRUNTIME_OPENVINO_VERSION} | awk '{ split($0,a,"."); print substr(a[1],3) a[2] a[3] }'` && (cd /opt/onnxruntime/lib && chmod a-x * && ln -s libopenvino.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino.so.${OV_SHORT_VERSION} && ln -s libopenvino.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino.so && ln -s libopenvino_c.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino_c.so.${OV_SHORT_VERSION} && ln -s libopenvino_c.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino_c.so && ln -s libopenvino_ir_frontend.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino_ir_frontend.so.${OV_SHORT_VERSION} && ln -s libopenvino_ir_frontend.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino_ir_frontend.so && ln -s libopenvino_onnx_frontend.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino_onnx_frontend.so.${OV_SHORT_VERSION} && ln -s libopenvino_onnx_frontend.so.${ONNXRUNTIME_OPENVINO_VERSION} libopenvino_onnx_frontend.so) |
| 99 | + |
| 100 | +RUN cd /opt/onnxruntime/lib && ln -s libonnxruntime.so libonnxruntime.so.1 && ln -s libonnxruntime.so.1 libonnxruntime.so.${ONNXRUNTIME_VERSION} |
| 101 | + |
| 102 | +RUN cd /opt/onnxruntime/lib && for i in `find . -mindepth 1 -maxdepth 1 -type f -name '*\.so*'`; do patchelf --set-rpath '$ORIGIN' $i; done |
| 103 | + |
| 104 | +# For testing copy ONNX custom op library and model |
| 105 | + |
| 106 | +RUN mkdir -p /opt/onnxruntime/test && cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/libcustom_op_library.so /opt/onnxruntime/test && cp /workspace/build/${ONNXRUNTIME_BUILD_CONFIG}/testdata/custom_op_library/custom_op_test.onnx /opt/onnxruntime/test |
0 commit comments