|
| 1 | +ARG BASE=21.08 |
| 2 | +ARG BASE_IMG=nvcr.io/nvidia/pytorch:${BASE}-py3 |
| 3 | +FROM ${BASE_IMG} as base |
| 4 | + |
| 5 | +FROM base as trtorch-builder-base |
| 6 | + |
| 7 | +# Removing any bazel or trtorch pre-installed from the base image |
| 8 | + |
| 9 | +RUN rm -rf /opt/pytorch/trtorch /usr/bin/bazel |
| 10 | + |
| 11 | +RUN apt-get update && apt-get install --no-install-recommends -y curl gnupg |
| 12 | +RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/bazel.gpg |
| 13 | +RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list |
| 14 | + |
| 15 | +RUN apt-get update && apt-get install -y --no-install-recommends bazel-4.0.0 |
| 16 | +RUN ln -s /usr/bin/bazel-4.0.0 /usr/bin/bazel |
| 17 | + |
| 18 | +# Workaround for bazel expecting both static and shared versions, we only use shared libraries inside container |
| 19 | +RUN cp /usr/lib/x86_64-linux-gnu/libnvinfer.so /usr/lib/x86_64-linux-gnu/libnvinfer_static.a |
| 20 | + |
| 21 | +RUN apt-get update && apt-get install -y --no-install-recommends locales ninja-build && rm -rf /var/lib/apt/lists/* && locale-gen en_US.UTF-8 |
| 22 | + |
| 23 | +FROM trtorch-builder-base as trtorch-builder |
| 24 | + |
| 25 | +COPY . /workspace/trtorch/src |
| 26 | +WORKDIR /workspace/trtorch/src |
| 27 | +RUN cp ./docker/WORKSPACE.cu.docker WORKSPACE |
| 28 | + |
| 29 | +# This script builds both libtrtorch bin/lib/include tarball and the Pythin wheel, in dist/ |
| 30 | +RUN ./docker/dist-build.sh |
| 31 | + |
| 32 | +FROM base as trtorch |
| 33 | + |
| 34 | +# copy source repo |
| 35 | +COPY . /workspace/trtorch |
| 36 | +COPY --from=trtorch-builder /workspace/trtorch/src/dist/ . |
| 37 | + |
| 38 | +RUN conda init bash |
| 39 | + |
| 40 | +RUN pip3 install ipywidgets --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org |
| 41 | +RUN jupyter nbextension enable --py widgetsnbextension |
| 42 | + |
| 43 | +RUN mkdir -p /opt/trtorch && tar xvf libtrtorch.tar.gz --strip-components 2 -C /opt/trtorch --exclude=LICENSE && pip3 install *.whl && rm -fr /workspace/trtorch/dist/* |
| 44 | + |
| 45 | +ENV LD_LIBRARY_PATH /opt/conda/lib/python3.8/site-packages/torch/lib:/opt/trtorch/lib:${LD_LIBRARY_PATH} |
| 46 | +ENV PATH /opt/trtorch/bin:${PATH} |
| 47 | + |
| 48 | +WORKDIR /workspace/trtorch/ |
| 49 | +CMD /bin/bash |
0 commit comments