xref: /aosp_15_r20/external/pytorch/.ci/docker/manywheel/Dockerfile (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1*da0073e9SAndroid Build Coastguard Worker# syntax = docker/dockerfile:experimental
2*da0073e9SAndroid Build Coastguard WorkerARG ROCM_VERSION=3.7
3*da0073e9SAndroid Build Coastguard WorkerARG BASE_CUDA_VERSION=11.8
4*da0073e9SAndroid Build Coastguard Worker
5*da0073e9SAndroid Build Coastguard WorkerARG GPU_IMAGE=centos:7
6*da0073e9SAndroid Build Coastguard WorkerFROM centos:7 as base
7*da0073e9SAndroid Build Coastguard Worker
8*da0073e9SAndroid Build Coastguard WorkerENV LC_ALL en_US.UTF-8
9*da0073e9SAndroid Build Coastguard WorkerENV LANG en_US.UTF-8
10*da0073e9SAndroid Build Coastguard WorkerENV LANGUAGE en_US.UTF-8
11*da0073e9SAndroid Build Coastguard Worker
12*da0073e9SAndroid Build Coastguard WorkerARG DEVTOOLSET_VERSION=9
13*da0073e9SAndroid Build Coastguard Worker# Note: This is required patch since CentOS have reached EOL
14*da0073e9SAndroid Build Coastguard Worker# otherwise any yum install setp will fail
15*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
16*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
17*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
18*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y wget curl perl util-linux xz bzip2 git patch which perl zlib-devel
19*da0073e9SAndroid Build Coastguard Worker# Just add everything as a safe.directory for git since these will be used in multiple places with git
20*da0073e9SAndroid Build Coastguard WorkerRUN git config --global --add safe.directory '*'
21*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y yum-utils centos-release-scl
22*da0073e9SAndroid Build Coastguard WorkerRUN yum-config-manager --enable rhel-server-rhscl-7-rpms
23*da0073e9SAndroid Build Coastguard Worker# Note: After running yum-config-manager --enable rhel-server-rhscl-7-rpms
24*da0073e9SAndroid Build Coastguard Worker# patch is required once again. Somehow this steps adds mirror.centos.org
25*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
26*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
27*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
28*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y devtoolset-${DEVTOOLSET_VERSION}-gcc devtoolset-${DEVTOOLSET_VERSION}-gcc-c++ devtoolset-${DEVTOOLSET_VERSION}-gcc-gfortran devtoolset-${DEVTOOLSET_VERSION}-binutils
29*da0073e9SAndroid Build Coastguard WorkerENV PATH=/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/bin:$PATH
30*da0073e9SAndroid Build Coastguard WorkerENV LD_LIBRARY_PATH=/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib:$LD_LIBRARY_PATH
31*da0073e9SAndroid Build Coastguard Worker
32*da0073e9SAndroid Build Coastguard WorkerRUN yum --enablerepo=extras install -y epel-release
33*da0073e9SAndroid Build Coastguard Worker
34*da0073e9SAndroid Build Coastguard Worker# cmake-3.18.4 from pip
35*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y python3-pip && \
36*da0073e9SAndroid Build Coastguard Worker    python3 -mpip install cmake==3.18.4 && \
37*da0073e9SAndroid Build Coastguard Worker    ln -s /usr/local/bin/cmake /usr/bin/cmake
38*da0073e9SAndroid Build Coastguard Worker
39*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y autoconf aclocal automake make sudo
40*da0073e9SAndroid Build Coastguard Worker
41*da0073e9SAndroid Build Coastguard WorkerFROM base as openssl
42*da0073e9SAndroid Build Coastguard Worker# Install openssl (this must precede `build python` step)
43*da0073e9SAndroid Build Coastguard Worker# (In order to have a proper SSL module, Python is compiled
44*da0073e9SAndroid Build Coastguard Worker# against a recent openssl [see env vars above], which is linked
45*da0073e9SAndroid Build Coastguard Worker# statically. We delete openssl afterwards.)
46*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_openssl.sh install_openssl.sh
47*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_openssl.sh && rm install_openssl.sh
48*da0073e9SAndroid Build Coastguard Worker
49*da0073e9SAndroid Build Coastguard Worker# EPEL for cmake
50*da0073e9SAndroid Build Coastguard WorkerFROM base as patchelf
51*da0073e9SAndroid Build Coastguard Worker# Install patchelf
52*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_patchelf.sh install_patchelf.sh
53*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_patchelf.sh && rm install_patchelf.sh
54*da0073e9SAndroid Build Coastguard WorkerRUN cp $(which patchelf) /patchelf
55*da0073e9SAndroid Build Coastguard Worker
56*da0073e9SAndroid Build Coastguard WorkerFROM patchelf as python
57*da0073e9SAndroid Build Coastguard Worker# build python
58*da0073e9SAndroid Build Coastguard WorkerCOPY manywheel/build_scripts /build_scripts
59*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_cpython.sh /build_scripts/install_cpython.sh
60*da0073e9SAndroid Build Coastguard WorkerRUN bash build_scripts/build.sh && rm -r build_scripts
61*da0073e9SAndroid Build Coastguard Worker
62*da0073e9SAndroid Build Coastguard WorkerFROM base as cuda
63*da0073e9SAndroid Build Coastguard WorkerARG BASE_CUDA_VERSION=10.2
64*da0073e9SAndroid Build Coastguard Worker# Install CUDA
65*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_cuda.sh install_cuda.sh
66*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_cuda.sh ${BASE_CUDA_VERSION} && rm install_cuda.sh
67*da0073e9SAndroid Build Coastguard Worker
68*da0073e9SAndroid Build Coastguard WorkerFROM base as intel
69*da0073e9SAndroid Build Coastguard Worker# MKL
70*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_mkl.sh install_mkl.sh
71*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_mkl.sh && rm install_mkl.sh
72*da0073e9SAndroid Build Coastguard Worker
73*da0073e9SAndroid Build Coastguard WorkerFROM base as magma
74*da0073e9SAndroid Build Coastguard WorkerARG BASE_CUDA_VERSION=10.2
75*da0073e9SAndroid Build Coastguard Worker# Install magma
76*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_magma.sh install_magma.sh
77*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_magma.sh ${BASE_CUDA_VERSION} && rm install_magma.sh
78*da0073e9SAndroid Build Coastguard Worker
79*da0073e9SAndroid Build Coastguard WorkerFROM base as jni
80*da0073e9SAndroid Build Coastguard Worker# Install java jni header
81*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_jni.sh install_jni.sh
82*da0073e9SAndroid Build Coastguard WorkerADD ./java/jni.h jni.h
83*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_jni.sh && rm install_jni.sh
84*da0073e9SAndroid Build Coastguard Worker
85*da0073e9SAndroid Build Coastguard WorkerFROM base as libpng
86*da0073e9SAndroid Build Coastguard Worker# Install libpng
87*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_libpng.sh install_libpng.sh
88*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_libpng.sh && rm install_libpng.sh
89*da0073e9SAndroid Build Coastguard Worker
90*da0073e9SAndroid Build Coastguard WorkerFROM ${GPU_IMAGE} as common
91*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
92*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
93*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
94*da0073e9SAndroid Build Coastguard WorkerENV LC_ALL en_US.UTF-8
95*da0073e9SAndroid Build Coastguard WorkerENV LANG en_US.UTF-8
96*da0073e9SAndroid Build Coastguard WorkerENV LANGUAGE en_US.UTF-8
97*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y \
98*da0073e9SAndroid Build Coastguard Worker        aclocal \
99*da0073e9SAndroid Build Coastguard Worker        autoconf \
100*da0073e9SAndroid Build Coastguard Worker        automake \
101*da0073e9SAndroid Build Coastguard Worker        bison \
102*da0073e9SAndroid Build Coastguard Worker        bzip2 \
103*da0073e9SAndroid Build Coastguard Worker        curl \
104*da0073e9SAndroid Build Coastguard Worker        diffutils \
105*da0073e9SAndroid Build Coastguard Worker        file \
106*da0073e9SAndroid Build Coastguard Worker        git \
107*da0073e9SAndroid Build Coastguard Worker        make \
108*da0073e9SAndroid Build Coastguard Worker        patch \
109*da0073e9SAndroid Build Coastguard Worker        perl \
110*da0073e9SAndroid Build Coastguard Worker        unzip \
111*da0073e9SAndroid Build Coastguard Worker        util-linux \
112*da0073e9SAndroid Build Coastguard Worker        wget \
113*da0073e9SAndroid Build Coastguard Worker        which \
114*da0073e9SAndroid Build Coastguard Worker        xz \
115*da0073e9SAndroid Build Coastguard Worker        yasm
116*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y \
117*da0073e9SAndroid Build Coastguard Worker    https://repo.ius.io/ius-release-el7.rpm \
118*da0073e9SAndroid Build Coastguard Worker    https://ossci-linux.s3.amazonaws.com/epel-release-7-14.noarch.rpm
119*da0073e9SAndroid Build Coastguard Worker
120*da0073e9SAndroid Build Coastguard WorkerRUN yum swap -y git git236-core
121*da0073e9SAndroid Build Coastguard Worker# git236+ would refuse to run git commands in repos owned by other users
122*da0073e9SAndroid Build Coastguard Worker# Which causes version check to fail, as pytorch repo is bind-mounted into the image
123*da0073e9SAndroid Build Coastguard Worker# Override this behaviour by treating every folder as safe
124*da0073e9SAndroid Build Coastguard Worker# For more details see https://github.com/pytorch/pytorch/issues/78659#issuecomment-1144107327
125*da0073e9SAndroid Build Coastguard WorkerRUN git config --global --add safe.directory "*"
126*da0073e9SAndroid Build Coastguard Worker
127*da0073e9SAndroid Build Coastguard WorkerENV SSL_CERT_FILE=/opt/_internal/certs.pem
128*da0073e9SAndroid Build Coastguard Worker# Install LLVM version
129*da0073e9SAndroid Build Coastguard WorkerCOPY --from=openssl            /opt/openssl                          /opt/openssl
130*da0073e9SAndroid Build Coastguard WorkerCOPY --from=python             /opt/python                           /opt/python
131*da0073e9SAndroid Build Coastguard WorkerCOPY --from=python             /opt/_internal                        /opt/_internal
132*da0073e9SAndroid Build Coastguard WorkerCOPY --from=python             /opt/python/cp39-cp39/bin/auditwheel /usr/local/bin/auditwheel
133*da0073e9SAndroid Build Coastguard WorkerCOPY --from=intel              /opt/intel                            /opt/intel
134*da0073e9SAndroid Build Coastguard WorkerCOPY --from=patchelf           /usr/local/bin/patchelf               /usr/local/bin/patchelf
135*da0073e9SAndroid Build Coastguard WorkerCOPY --from=jni                /usr/local/include/jni.h              /usr/local/include/jni.h
136*da0073e9SAndroid Build Coastguard WorkerCOPY --from=libpng             /usr/local/bin/png*                   /usr/local/bin/
137*da0073e9SAndroid Build Coastguard WorkerCOPY --from=libpng             /usr/local/bin/libpng*                /usr/local/bin/
138*da0073e9SAndroid Build Coastguard WorkerCOPY --from=libpng             /usr/local/include/png*               /usr/local/include/
139*da0073e9SAndroid Build Coastguard WorkerCOPY --from=libpng             /usr/local/include/libpng*            /usr/local/include/
140*da0073e9SAndroid Build Coastguard WorkerCOPY --from=libpng             /usr/local/lib/libpng*                /usr/local/lib/
141*da0073e9SAndroid Build Coastguard WorkerCOPY --from=libpng             /usr/local/lib/pkgconfig              /usr/local/lib/pkgconfig
142*da0073e9SAndroid Build Coastguard Worker
143*da0073e9SAndroid Build Coastguard WorkerFROM common as cpu_final
144*da0073e9SAndroid Build Coastguard WorkerARG BASE_CUDA_VERSION=10.1
145*da0073e9SAndroid Build Coastguard WorkerARG DEVTOOLSET_VERSION=9
146*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
147*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
148*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
149*da0073e9SAndroid Build Coastguard Worker
150*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y yum-utils centos-release-scl
151*da0073e9SAndroid Build Coastguard WorkerRUN yum-config-manager --enable rhel-server-rhscl-7-rpms
152*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
153*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
154*da0073e9SAndroid Build Coastguard WorkerRUN sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
155*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y devtoolset-${DEVTOOLSET_VERSION}-gcc devtoolset-${DEVTOOLSET_VERSION}-gcc-c++ devtoolset-${DEVTOOLSET_VERSION}-gcc-gfortran devtoolset-${DEVTOOLSET_VERSION}-binutils
156*da0073e9SAndroid Build Coastguard WorkerENV PATH=/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/bin:$PATH
157*da0073e9SAndroid Build Coastguard WorkerENV LD_LIBRARY_PATH=/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib:$LD_LIBRARY_PATH
158*da0073e9SAndroid Build Coastguard Worker
159*da0073e9SAndroid Build Coastguard Worker# cmake is already installed inside the rocm base image, so remove if present
160*da0073e9SAndroid Build Coastguard WorkerRUN rpm -e cmake || true
161*da0073e9SAndroid Build Coastguard Worker# cmake-3.18.4 from pip
162*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y python3-pip && \
163*da0073e9SAndroid Build Coastguard Worker    python3 -mpip install cmake==3.18.4 && \
164*da0073e9SAndroid Build Coastguard Worker    ln -s /usr/local/bin/cmake /usr/bin/cmake
165*da0073e9SAndroid Build Coastguard Worker
166*da0073e9SAndroid Build Coastguard Worker# ninja
167*da0073e9SAndroid Build Coastguard WorkerRUN yum install -y ninja-build
168*da0073e9SAndroid Build Coastguard Worker
169*da0073e9SAndroid Build Coastguard WorkerFROM cpu_final as cuda_final
170*da0073e9SAndroid Build Coastguard WorkerRUN rm -rf /usr/local/cuda-${BASE_CUDA_VERSION}
171*da0073e9SAndroid Build Coastguard WorkerCOPY --from=cuda     /usr/local/cuda-${BASE_CUDA_VERSION}  /usr/local/cuda-${BASE_CUDA_VERSION}
172*da0073e9SAndroid Build Coastguard WorkerCOPY --from=magma    /usr/local/cuda-${BASE_CUDA_VERSION}  /usr/local/cuda-${BASE_CUDA_VERSION}
173*da0073e9SAndroid Build Coastguard WorkerRUN ln -sf /usr/local/cuda-${BASE_CUDA_VERSION} /usr/local/cuda
174*da0073e9SAndroid Build Coastguard WorkerENV PATH=/usr/local/cuda/bin:$PATH
175*da0073e9SAndroid Build Coastguard Worker
176*da0073e9SAndroid Build Coastguard WorkerFROM cpu_final as rocm_final
177*da0073e9SAndroid Build Coastguard WorkerARG ROCM_VERSION=3.7
178*da0073e9SAndroid Build Coastguard WorkerARG PYTORCH_ROCM_ARCH
179*da0073e9SAndroid Build Coastguard WorkerENV PYTORCH_ROCM_ARCH ${PYTORCH_ROCM_ARCH}
180*da0073e9SAndroid Build Coastguard Worker# Adding ROCM_PATH env var so that LoadHip.cmake (even with logic updated for ROCm6.0)
181*da0073e9SAndroid Build Coastguard Worker# find HIP works for ROCm5.7. Not needed for ROCm6.0 and above.
182*da0073e9SAndroid Build Coastguard Worker# Remove below when ROCm5.7 is not in support matrix anymore.
183*da0073e9SAndroid Build Coastguard WorkerENV ROCM_PATH /opt/rocm
184*da0073e9SAndroid Build Coastguard WorkerENV MKLROOT /opt/intel
185*da0073e9SAndroid Build Coastguard Worker# No need to install ROCm as base docker image should have full ROCm install
186*da0073e9SAndroid Build Coastguard Worker#ADD ./common/install_rocm.sh install_rocm.sh
187*da0073e9SAndroid Build Coastguard Worker#RUN ROCM_VERSION=${ROCM_VERSION} bash ./install_rocm.sh && rm install_rocm.sh
188*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_rocm_drm.sh install_rocm_drm.sh
189*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_rocm_drm.sh && rm install_rocm_drm.sh
190*da0073e9SAndroid Build Coastguard Worker# cmake3 is needed for the MIOpen build
191*da0073e9SAndroid Build Coastguard WorkerRUN ln -sf /usr/local/bin/cmake /usr/bin/cmake3
192*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_rocm_magma.sh install_rocm_magma.sh
193*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_rocm_magma.sh && rm install_rocm_magma.sh
194*da0073e9SAndroid Build Coastguard WorkerADD ./common/install_miopen.sh install_miopen.sh
195*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_miopen.sh ${ROCM_VERSION} && rm install_miopen.sh
196*da0073e9SAndroid Build Coastguard Worker
197*da0073e9SAndroid Build Coastguard Worker# Install AOTriton
198*da0073e9SAndroid Build Coastguard WorkerCOPY ./common/common_utils.sh common_utils.sh
199*da0073e9SAndroid Build Coastguard WorkerCOPY ./aotriton_version.txt aotriton_version.txt
200*da0073e9SAndroid Build Coastguard WorkerCOPY ./common/install_aotriton.sh install_aotriton.sh
201*da0073e9SAndroid Build Coastguard WorkerRUN bash ./install_aotriton.sh /opt/rocm && rm install_aotriton.sh aotriton_version.txt
202*da0073e9SAndroid Build Coastguard WorkerENV AOTRITON_INSTALLED_PREFIX /opt/rocm/aotriton
203