Skip to content

Commit e023400

Browse files
rraminenjithunnair-amd
authored andcommitted
[SOW MS3] Centos stream9 PyTorch image support (#1090)
* changes to build Centos stream 9 images * Added scripts for centos and centos stream images * Added an extra line * Add ninja installation * Optimized code * Fixes * Add comment * Optimized code * Added AMDGPU mapping for ROCm 5.2 and invalid-url for rocm_baseurl Co-authored-by: Jithun Nair <[email protected]>
1 parent 1577328 commit e023400

File tree

6 files changed

+187
-17
lines changed

6 files changed

+187
-17
lines changed

.ci/docker/build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ if [[ "$image" == *cuda* && ${OS} == "ubuntu" ]]; then
459459
fi
460460
fi
461461

462+
if [[ "$image" == *centos9* ]]; then
463+
DOCKERFILE_NAME="Dockerfile.centos.stream"
464+
else
465+
DOCKERFILE_NAME="Dockerfile"
466+
fi
467+
462468
# Build image
463469
docker build \
464470
--no-cache \
@@ -502,7 +508,7 @@ docker build \
502508
--build-arg "ACL=${ACL:-}" \
503509
--build-arg "SKIP_SCCACHE_INSTALL=${SKIP_SCCACHE_INSTALL:-}" \
504510
--build-arg "SKIP_LLVM_SRC_BUILD_INSTALL=${SKIP_LLVM_SRC_BUILD_INSTALL:-}" \
505-
-f $(dirname ${DOCKERFILE})/Dockerfile \
511+
-f $(dirname ${DOCKERFILE})/${DOCKERFILE_NAME} \
506512
-t "$tmp_tag" \
507513
"$@" \
508514
.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
ARG CENTOS_VERSION
2+
3+
FROM quay.io/centos/centos:stream${CENTOS_VERSION}
4+
5+
6+
# Set AMD gpu targets to build for
7+
ARG PYTORCH_ROCM_ARCH
8+
ENV PYTORCH_ROCM_ARCH ${PYTORCH_ROCM_ARCH}
9+
10+
# Install required packages to build Caffe2
11+
12+
# Install common dependencies (so that this step can be cached separately)
13+
ARG EC2
14+
ADD ./common/install_base.sh install_base.sh
15+
RUN bash ./install_base.sh && rm install_base.sh
16+
17+
#Install langpack
18+
RUN yum install -y glibc-langpack-en
19+
20+
# Update CentOS git version
21+
RUN yum -y remove git
22+
RUN yum -y remove git-*
23+
RUN yum install -y git
24+
25+
# Install devtoolset
26+
RUN dnf install -y rpmdevtools
27+
ENV BASH_ENV "/etc/profile"
28+
29+
# Install ninja
30+
RUN dnf --enablerepo=crb install -y ninja-build
31+
32+
# (optional) Install non-default glibc version
33+
ARG GLIBC_VERSION
34+
ADD ./common/install_glibc.sh install_glibc.sh
35+
RUN if [ -n "${GLIBC_VERSION}" ]; then bash ./install_glibc.sh; fi
36+
RUN rm install_glibc.sh
37+
38+
# Install user
39+
ADD ./common/install_user.sh install_user.sh
40+
RUN bash ./install_user.sh && rm install_user.sh
41+
42+
# Install conda and other packages (e.g., numpy, pytest)
43+
ENV PATH /opt/conda/bin:$PATH
44+
ARG ANACONDA_PYTHON_VERSION
45+
ARG CONDA_CMAKE
46+
ADD requirements-ci.txt /opt/conda/requirements-ci.txt
47+
ADD ./common/install_conda.sh install_conda.sh
48+
RUN bash ./install_conda.sh && rm install_conda.sh
49+
RUN rm /opt/conda/requirements-ci.txt
50+
51+
# (optional) Install protobuf for ONNX
52+
ARG PROTOBUF
53+
ADD ./common/install_protobuf.sh install_protobuf.sh
54+
RUN if [ -n "${PROTOBUF}" ]; then bash ./install_protobuf.sh; fi
55+
RUN rm install_protobuf.sh
56+
ENV INSTALLED_PROTOBUF ${PROTOBUF}
57+
58+
# (optional) Install database packages like LMDB and LevelDB
59+
ARG DB
60+
ADD ./common/install_db.sh install_db.sh
61+
RUN if [ -n "${DB}" ]; then bash ./install_db.sh; fi
62+
RUN rm install_db.sh
63+
ENV INSTALLED_DB ${DB}
64+
65+
# (optional) Install vision packages like OpenCV and ffmpeg
66+
ARG VISION
67+
ADD ./common/install_vision.sh install_vision.sh
68+
RUN if [ -n "${VISION}" ]; then bash ./install_vision.sh; fi
69+
RUN rm install_vision.sh
70+
ENV INSTALLED_VISION ${VISION}
71+
72+
# Install rocm
73+
ARG ROCM_VERSION
74+
ADD ./common/install_rocm.sh install_rocm.sh
75+
RUN bash ./install_rocm.sh
76+
RUN rm install_rocm.sh
77+
ENV PATH /opt/rocm/bin:$PATH
78+
ENV PATH /opt/rocm/hcc/bin:$PATH
79+
ENV PATH /opt/rocm/hip/bin:$PATH
80+
ENV PATH /opt/rocm/opencl/bin:$PATH
81+
ENV PATH /opt/rocm/llvm/bin:$PATH
82+
ENV MAGMA_HOME /opt/rocm/magma
83+
ENV LANG en_US.utf8
84+
ENV LC_ALL en_US.utf8
85+
86+
# (optional) Install non-default CMake version
87+
ARG CMAKE_VERSION
88+
ADD ./common/install_cmake.sh install_cmake.sh
89+
RUN if [ -n "${CMAKE_VERSION}" ]; then bash ./install_cmake.sh; fi
90+
RUN rm install_cmake.sh
91+
92+
# (optional) Install non-default Ninja version
93+
ARG NINJA_VERSION
94+
ADD ./common/install_ninja.sh install_ninja.sh
95+
RUN if [ -n "${NINJA_VERSION}" ]; then bash ./install_ninja.sh; fi
96+
RUN rm install_ninja.sh
97+
98+
# Install ccache/sccache (do this last, so we get priority in PATH)
99+
ADD ./common/install_cache.sh install_cache.sh
100+
ENV PATH /opt/cache/bin:$PATH
101+
RUN bash ./install_cache.sh && rm install_cache.sh
102+
103+
# Include BUILD_ENVIRONMENT environment variable in image
104+
ARG BUILD_ENVIRONMENT
105+
ENV BUILD_ENVIRONMENT ${BUILD_ENVIRONMENT}
106+
107+
USER jenkins
108+
CMD ["bash"]

.ci/docker/common/install_base.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,21 @@ install_ubuntu() {
9090
install_centos() {
9191
# Need EPEL for many packages we depend on.
9292
# See http://fedoraproject.org/wiki/EPEL
93-
yum --enablerepo=extras install -y epel-release
93+
# extras repo is not there for CentOS 9 and epel-release is already part of repo list
94+
if [[ $OS_VERSION == 9 ]]; then
95+
yum install -y epel-release
96+
ALLOW_ERASE="--allowerasing"
97+
else
98+
yum --enablerepo=extras install -y epel-release
99+
ALLOW_ERASE=""
100+
fi
94101

95102
ccache_deps="asciidoc docbook-dtds docbook-style-xsl libxslt"
96103
numpy_deps="gcc-gfortran"
97104
# Note: protobuf-c-{compiler,devel} on CentOS are too old to be used
98105
# for Caffe2. That said, we still install them to make sure the build
99106
# system opts to build/use protoc and libprotobuf from third-party.
100-
yum install -y \
107+
yum install -y $ALLOW_ERASE \
101108
$ccache_deps \
102109
$numpy_deps \
103110
autoconf \
@@ -114,24 +121,33 @@ install_centos() {
114121
glibc-headers \
115122
glog-devel \
116123
libstdc++-devel \
117-
libsndfile-devel \
118124
make \
119-
opencv-devel \
120125
sudo \
121126
wget \
122127
vim \
123128
unzip \
124129
gdb
125130

131+
if [[ $OS_VERSION == 9 ]]
132+
then
133+
dnf --enablerepo=crb -y install libsndfile-devel
134+
else
135+
yum install -y \
136+
opencv-devel \
137+
libsndfile-devel
138+
fi
139+
126140
# Cleanup
127141
yum clean all
128142
rm -rf /var/cache/yum
129143
rm -rf /var/lib/yum/yumdb
130144
rm -rf /var/lib/yum/history
131145
}
132146

133-
# Install base packages depending on the base OS
134147
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
148+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
149+
150+
# Install base packages depending on the base OS
135151
case "$ID" in
136152
ubuntu)
137153
install_ubuntu

.ci/docker/common/install_db.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ install_ubuntu() {
1313
install_centos() {
1414
# Need EPEL for many packages we depend on.
1515
# See http://fedoraproject.org/wiki/EPEL
16-
yum --enablerepo=extras install -y epel-release
16+
if [[ $OS_VERSION == 9 ]]; then
17+
yum install -y epel-release
18+
else
19+
yum --enablerepo=extras install -y epel-release
20+
fi
21+
22+
yum install -y \
23+
hiredis-devel \
24+
leveldb-devel
25+
26+
if [[ $OS_VERSION == 9 ]]; then
27+
dnf --enablerepo=crb -y install lmdb-devel snappy-devel
28+
else
29+
yum install -y \
30+
lmdb-devel \
31+
snappy-devel
32+
fi
1733

1834
# Cleanup
1935
yum clean all
@@ -22,6 +38,8 @@ install_centos() {
2238
rm -rf /var/lib/yum/history
2339
}
2440

41+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
42+
2543
# Install base packages depending on the base OS
2644
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
2745
case "$ID" in

.ci/docker/common/install_rocm.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ install_centos() {
7272
yum update -y
7373
yum install -y kmod
7474
yum install -y wget
75-
yum install -y openblas-devel
75+
76+
if [[ $OS_VERSION == 9 ]]; then
77+
dnf install -y openblas-serial
78+
dnf install -y dkms kernel-headers kernel-devel
79+
else
80+
yum install -y openblas-devel
81+
yum install -y dkms kernel-headers-`uname -r` kernel-devel-`uname -r`
82+
fi
7683

7784
yum install -y epel-release
78-
yum install -y dkms kernel-headers-`uname -r` kernel-devel-`uname -r`
7985

8086
# Add amdgpu repository
8187
local amdgpu_baseurl
@@ -91,17 +97,25 @@ install_centos() {
9197
echo "gpgcheck=1" >> /etc/yum.repos.d/amdgpu.repo
9298
echo "gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key" >> /etc/yum.repos.d/amdgpu.repo
9399

94-
local rocm_baseurl="http://repo.radeon.com/rocm/yum/${ROCM_VERSION}"
100+
if [[ $OS_VERSION == 9 ]]; then
101+
local rocm_baseurl="invalid-url"
102+
else
103+
local rocm_baseurl="http://repo.radeon.com/rocm/yum/${ROCM_VERSION}/main"
104+
fi
95105
echo "[ROCm]" > /etc/yum.repos.d/rocm.repo
96106
echo "name=ROCm" >> /etc/yum.repos.d/rocm.repo
97107
echo "baseurl=${rocm_baseurl}" >> /etc/yum.repos.d/rocm.repo
98108
echo "enabled=1" >> /etc/yum.repos.d/rocm.repo
99109
echo "gpgcheck=1" >> /etc/yum.repos.d/rocm.repo
100110
echo "gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key" >> /etc/yum.repos.d/rocm.repo
101111

102-
yum update -y
103-
104-
yum install -y \
112+
if [[ $OS_VERSION == 9 ]]; then
113+
yum update -y --nogpgcheck
114+
dnf --enablerepo=crb install -y perl-File-BaseDir
115+
yum install -y --nogpgcheck rocm-ml-sdk rocm-developer-tools
116+
else
117+
yum update -y
118+
yum install -y \
105119
rocm-dev \
106120
rocm-utils \
107121
rocm-libs \
@@ -132,6 +146,8 @@ install_centos() {
132146
rm -rf /var/lib/yum/history
133147
}
134148

149+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
150+
135151
# Install Python packages depending on the base OS
136152
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
137153
case "$ID" in

.ci/docker/common/install_vision.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ install_ubuntu() {
1515
install_centos() {
1616
# Need EPEL for many packages we depend on.
1717
# See http://fedoraproject.org/wiki/EPEL
18-
yum --enablerepo=extras install -y epel-release
19-
20-
yum install -y \
21-
opencv-devel
18+
if [[ $OS_VERSION == 9 ]]; then
19+
yum install -y epel-release
20+
else
21+
yum --enablerepo=extras install -y epel-release
22+
yum install -y \
23+
opencv-devel \
24+
ffmpeg-devel
25+
fi
2226

2327
# Cleanup
2428
yum clean all
@@ -27,6 +31,8 @@ install_centos() {
2731
rm -rf /var/lib/yum/history
2832
}
2933

34+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
35+
3036
# Install base packages depending on the base OS
3137
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
3238
case "$ID" in

0 commit comments

Comments
 (0)