2022-08-19 09:30:13 +08:00
FROM nvcr.io/nvidia/tensorrt:22.04-py3
2022-01-25 15:11:50 +08:00
2022-08-19 09:30:13 +08:00
ARG CUDA = 11 .3
2022-01-25 15:11:50 +08:00
ARG PYTHON_VERSION = 3 .8
2022-08-19 09:30:13 +08:00
ARG TORCH_VERSION = 1 .10.0
ARG TORCHVISION_VERSION = 0 .11.0
2022-01-25 15:11:50 +08:00
ARG ONNXRUNTIME_VERSION = 1 .8.1
2022-08-19 09:30:13 +08:00
ARG PPLCV_VERSION = 0 .7.0
2022-01-25 15:11:50 +08:00
ENV FORCE_CUDA = "1"
2022-11-10 11:18:56 +08:00
ARG MMCV_VERSION = ">=2.0.0rc2"
2022-11-04 15:18:02 +08:00
ARG MMENGINE_VERSION = ">=0.3.0"
2022-01-25 15:11:50 +08:00
ENV DEBIAN_FRONTEND = noninteractive
2022-03-17 21:25:25 +08:00
### change the system source for installing libs
ARG USE_SRC_INSIDE = false
RUN if [ ${ USE_SRC_INSIDE } = = true ] ; \
then \
sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list ; \
sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list ; \
echo "Use aliyun source for installing libs" ; \
else \
echo "Keep the download source unchanged" ; \
fi
2022-01-25 15:11:50 +08:00
### update apt and install libs
RUN apt-get update && \
apt-get install -y vim libsm6 libxext6 libxrender-dev libgl1-mesa-glx git wget libssl-dev libopencv-dev libspdlog-dev --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x ~/miniconda.sh && \
2023-01-09 23:50:15 -08:00
bash ~/miniconda.sh -b -p /opt/conda && \
2022-01-25 15:11:50 +08:00
rm ~/miniconda.sh && \
/opt/conda/bin/conda install -y python = ${ PYTHON_VERSION } conda-build pyyaml numpy ipython cython typing typing_extensions mkl mkl-include ninja && \
2022-11-09 10:14:35 +08:00
/opt/conda/bin/conda clean -ya
2022-11-08 19:46:56 +08:00
2022-12-06 14:00:13 +08:00
### change the pip source for installing packages
RUN if [ ${ USE_SRC_INSIDE } = = true ] ; \
then \
/opt/conda/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple; \
echo "pip using tsinghua source" ; \
else \
echo "Keep pip the download source unchanged" ; \
fi
2022-11-08 19:46:56 +08:00
### install pytorch openmim
2022-11-08 22:47:51 +08:00
RUN /opt/conda/bin/conda install pytorch = = ${ TORCH_VERSION } torchvision = = ${ TORCHVISION_VERSION } cudatoolkit = ${ CUDA } -c pytorch -c conda-forge -y \
2022-11-08 19:46:56 +08:00
&& /opt/conda/bin/pip install --no-cache-dir openmim
2022-01-25 15:11:50 +08:00
2022-11-03 16:51:16 +08:00
### pytorch mmcv onnxruntime
2022-11-08 19:46:56 +08:00
RUN /opt/conda/bin/mim install --no-cache-dir "mmcv" ${ MMCV_VERSION } onnxruntime-gpu= = ${ ONNXRUNTIME_VERSION } mmengine${ MMENGINE_VERSION }
2022-01-25 15:11:50 +08:00
2022-11-03 16:46:36 +08:00
ENV PATH /opt/conda/bin:$PATH
2022-01-25 15:11:50 +08:00
WORKDIR /root/workspace
2022-11-08 19:46:56 +08:00
2022-01-25 15:11:50 +08:00
### get onnxruntime
RUN wget https://github.com/microsoft/onnxruntime/releases/download/v${ ONNXRUNTIME_VERSION } /onnxruntime-linux-x64-${ ONNXRUNTIME_VERSION } .tgz \
2022-11-03 16:46:36 +08:00
&& tar -zxvf onnxruntime-linux-x64-${ ONNXRUNTIME_VERSION } .tgz
2022-01-25 15:11:50 +08:00
### cp trt from pip to conda
RUN cp -r /usr/local/lib/python${ PYTHON_VERSION } /dist-packages/tensorrt* /opt/conda/lib/python${ PYTHON_VERSION } /site-packages/
### install mmdeploy
ENV ONNXRUNTIME_DIR = /root/workspace/onnxruntime-linux-x64-${ ONNXRUNTIME_VERSION }
ENV TENSORRT_DIR = /workspace/tensorrt
ARG VERSION
2023-04-06 12:07:42 +08:00
RUN git clone -b main https://github.com/open-mmlab/mmdeploy && \
2022-01-25 15:11:50 +08:00
cd mmdeploy && \
2023-04-06 12:07:42 +08:00
if [ -z ${ VERSION } ] ; then echo "No MMDeploy version passed in, building on main" ; else git checkout tags/v${ VERSION } -b tag_v${ VERSION } ; fi && \
2022-01-25 15:11:50 +08:00
git submodule update --init --recursive && \
2022-03-19 09:05:12 +08:00
mkdir -p build && \
2022-01-25 15:11:50 +08:00
cd build && \
2022-03-19 09:05:12 +08:00
cmake -DMMDEPLOY_TARGET_BACKENDS= "ort;trt" .. && \
2022-01-25 15:11:50 +08:00
make -j$( nproc) && \
cd .. && \
2022-11-08 16:19:39 +08:00
/opt/conda/bin/mim install -e .
2022-01-25 15:11:50 +08:00
### build sdk
2022-03-19 09:05:12 +08:00
RUN git clone https://github.com/openppl-public/ppl.cv.git && \
2022-01-25 15:11:50 +08:00
cd ppl.cv && \
2022-03-19 09:05:12 +08:00
git checkout tags/v${ PPLCV_VERSION } -b v${ PPLCV_VERSION } && \
2022-01-25 15:11:50 +08:00
./build.sh cuda
2022-02-16 09:24:29 +05:30
2022-03-19 09:05:12 +08:00
ENV BACKUP_LD_LIBRARY_PATH = $LD_LIBRARY_PATH
2022-08-19 09:30:13 +08:00
ENV LD_LIBRARY_PATH = /usr/local/cuda/compat/lib.real/:$LD_LIBRARY_PATH
2022-03-19 09:05:12 +08:00
2022-01-25 15:11:50 +08:00
RUN cd /root/workspace/mmdeploy && \
2022-03-19 09:05:12 +08:00
rm -rf build/CM* build/cmake-install.cmake build/Makefile build/csrc && \
2022-01-25 15:11:50 +08:00
mkdir -p build && cd build && \
cmake .. \
-DMMDEPLOY_BUILD_SDK= ON \
2022-08-19 09:30:13 +08:00
-DMMDEPLOY_BUILD_EXAMPLES= ON \
2022-01-25 15:11:50 +08:00
-DCMAKE_CXX_COMPILER= g++ \
-Dpplcv_DIR= /root/workspace/ppl.cv/cuda-build/install/lib/cmake/ppl \
-DTENSORRT_DIR= ${ TENSORRT_DIR } \
2022-04-18 15:38:34 +08:00
-DONNXRUNTIME_DIR= ${ ONNXRUNTIME_DIR } \
2022-01-25 15:11:50 +08:00
-DMMDEPLOY_BUILD_SDK_PYTHON_API= ON \
-DMMDEPLOY_TARGET_DEVICES= "cuda;cpu" \
2022-04-18 15:38:34 +08:00
-DMMDEPLOY_TARGET_BACKENDS= "ort;trt" \
2022-01-25 15:11:50 +08:00
-DMMDEPLOY_CODEBASES= all && \
2022-03-19 09:05:12 +08:00
make -j$( nproc) && make install && \
2022-08-19 09:30:13 +08:00
export SPDLOG_LEVEL = warn && \
2023-04-06 12:07:42 +08:00
if [ -z ${ VERSION } ] ; then echo "Built MMDeploy for GPU devices successfully!" ; else echo " Built MMDeploy version v ${ VERSION } for GPU devices successfully! " ; fi
2022-01-25 15:11:50 +08:00
2022-03-19 09:05:12 +08:00
ENV LD_LIBRARY_PATH = " /root/workspace/mmdeploy/build/lib: ${ BACKUP_LD_LIBRARY_PATH } "