Skip to content

Commit 170bc96

Browse files
authored
libtorch: add option to build singular images (pytorch#643)
1 parent 3a5db41 commit 170bc96

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

libtorch/build_all_docker.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
TOPDIR=$(git rev-parse --show-toplevel)
6+
7+
for CUDA_VERSION in 11.2 11.1 11.0 10.2 10.1 cpu; do
8+
CUDA_VERSION="${CUDA_VERSION}" conda/build_docker.sh
9+
done

libtorch/build_docker.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
export DOCKER_BUILDKIT=1
4+
TOPDIR=$(git rev-parse --show-toplevel)
5+
6+
CUDA_VERSION=${CUDA_VERSION:-10.2}
7+
8+
case ${CUDA_VERSION} in
9+
cpu)
10+
BASE_TARGET=base
11+
DOCKER_TAG=cpu
12+
;;
13+
*)
14+
BASE_TARGET=cuda${CUDA_VERSION}
15+
DOCKER_TAG=cuda${CUDA_VERSION}
16+
;;
17+
esac
18+
19+
(
20+
set -x
21+
docker build \
22+
--target final \
23+
--build-arg "BASE_TARGET=${BASE_TARGET}" \
24+
--build-arg "CUDA_VERSION=${CUDA_VERSION}" \
25+
-t "pytorch/libtorch-cxx11-builder:${DOCKER_TAG}" \
26+
-f "${TOPDIR}/libtorch/ubuntu16.04/Dockerfile" \
27+
${TOPDIR}
28+
)

libtorch/ubuntu16.04/Dockerfile

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ARG BASE_TARGET=base
12
FROM nvidia/cuda:9.2-devel-ubuntu16.04 as base
23

34
RUN apt-get clean && apt-get update
@@ -17,48 +18,42 @@ RUN bash ./install_mkl.sh && rm install_mkl.sh
1718
FROM base as cuda
1819
ADD ./common/install_cuda.sh install_cuda.sh
1920
ADD ./common/install_magma.sh install_magma.sh
21+
ENV CUDA_HOME /usr/local/cuda
2022

21-
FROM cuda as cuda92
23+
FROM base as conda
24+
ADD ./common/install_conda.sh install_conda.sh
25+
RUN bash ./install_conda.sh && rm install_conda.sh
26+
RUN /opt/conda/bin/conda install -y cmake=3.14
27+
28+
FROM cuda as cuda9.2
2229
RUN bash ./install_cuda.sh 9.2
2330
RUN bash ./install_magma.sh 9.2
2431

25-
FROM cuda as cuda101
32+
FROM cuda as cuda10.1
2633
RUN bash ./install_cuda.sh 10.1
2734
RUN bash ./install_magma.sh 10.1
2835

29-
FROM cuda as cuda102
36+
FROM cuda as cuda10.2
3037
RUN bash ./install_cuda.sh 10.2
3138
RUN bash ./install_magma.sh 10.2
3239

33-
FROM cuda as cuda110
40+
FROM cuda as cuda11.0
3441
RUN bash ./install_cuda.sh 11.0
3542
RUN bash ./install_magma.sh 11.0
3643

37-
FROM cuda as cuda111
44+
FROM cuda as cuda11.1
3845
RUN bash ./install_cuda.sh 11.1
3946
RUN bash ./install_magma.sh 11.1
4047

41-
FROM cuda as cuda112
48+
FROM cuda as cuda11.2
4249
RUN bash ./install_cuda.sh 11.2
4350
RUN bash ./install_magma.sh 11.2
4451

45-
FROM base as final
52+
FROM ${BASE_TARGET} as final
4653
# Install patchelf
4754
ADD ./common/install_patchelf.sh install_patchelf.sh
4855
RUN bash ./install_patchelf.sh && rm install_patchelf.sh
49-
56+
COPY --from=intel /opt/intel /opt/intel
5057
# Install Anaconda
58+
COPY --from=conda /opt/conda /opt/conda
5159
ENV PATH /opt/conda/bin:$PATH
52-
ADD ./common/install_conda.sh install_conda.sh
53-
RUN bash ./install_conda.sh && rm install_conda.sh
54-
RUN /opt/conda/bin/conda install -y cmake=3.14
55-
56-
RUN rm -rf /usr/local/cuda-*
57-
COPY --from=cuda92 /usr/local/cuda-9.2 /usr/local/cuda-9.2
58-
COPY --from=cuda101 /usr/local/cuda-10.1 /usr/local/cuda-10.1
59-
COPY --from=cuda102 /usr/local/cuda-10.2 /usr/local/cuda-10.2
60-
COPY --from=cuda110 /usr/local/cuda-11.0 /usr/local/cuda-11.0
61-
COPY --from=cuda111 /usr/local/cuda-11.1 /usr/local/cuda-11.1
62-
COPY --from=cuda112 /usr/local/cuda-11.2 /usr/local/cuda-11.2
63-
COPY --from=intel /opt/intel /opt/intel
64-
ENV CUDA_HOME /usr/local/cuda

0 commit comments

Comments
 (0)