Skip to content

Commit 40a3160

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 f2f5b5d commit 40a3160

File tree

6 files changed

+193
-21
lines changed

6 files changed

+193
-21
lines changed

.ci/docker/build.sh

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

361+
if [[ "$image" == *centos9* ]]; then
362+
DOCKERFILE_NAME="Dockerfile.centos.stream"
363+
else
364+
DOCKERFILE_NAME="Dockerfile"
365+
fi
366+
361367
# Build image
362368
DOCKER_BUILDKIT=1 docker build \
363369
--no-cache \
@@ -398,7 +404,7 @@ DOCKER_BUILDKIT=1 docker build \
398404
--build-arg "EXECUTORCH=${EXECUTORCH}" \
399405
--build-arg "BASEKIT_VERSION=${BASEKIT_VERSION}" \
400406
--build-arg "ACL=${ACL:-}" \
401-
-f $(dirname ${DOCKERFILE})/Dockerfile \
407+
-f $(dirname ${DOCKERFILE})/${DOCKERFILE_NAME} \
402408
-t "$tmp_tag" \
403409
"$@" \
404410
.
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 \
@@ -115,24 +122,33 @@ install_centos() {
115122
glog-devel \
116123
hiredis-devel \
117124
libstdc++-devel \
118-
libsndfile-devel \
119125
make \
120-
opencv-devel \
121126
sudo \
122127
wget \
123128
vim \
124129
unzip \
125130
gdb
126131

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

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

.ci/docker/common/install_db.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ install_ubuntu() {
1818
install_centos() {
1919
# Need EPEL for many packages we depend on.
2020
# See http://fedoraproject.org/wiki/EPEL
21-
yum --enablerepo=extras install -y epel-release
21+
if [[ $OS_VERSION == 9 ]]; then
22+
yum install -y epel-release
23+
else
24+
yum --enablerepo=extras install -y epel-release
25+
fi
2226

2327
yum install -y \
2428
hiredis-devel \
25-
leveldb-devel \
26-
lmdb-devel \
27-
snappy-devel
29+
leveldb-devel
30+
31+
if [[ $OS_VERSION == 9 ]]; then
32+
dnf --enablerepo=crb -y install lmdb-devel snappy-devel
33+
else
34+
yum install -y \
35+
lmdb-devel \
36+
snappy-devel
37+
fi
2838

2939
# Cleanup
3040
yum clean all
@@ -33,6 +43,8 @@ install_centos() {
3343
rm -rf /var/lib/yum/history
3444
}
3545

46+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
47+
3648
# Install base packages depending on the base OS
3749
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
3850
case "$ID" in

.ci/docker/common/install_rocm.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,16 @@ install_centos() {
9898
yum update -y
9999
yum install -y kmod
100100
yum install -y wget
101-
yum install -y openblas-devel
101+
102+
if [[ $OS_VERSION == 9 ]]; then
103+
dnf install -y openblas-serial
104+
dnf install -y dkms kernel-headers kernel-devel
105+
else
106+
yum install -y openblas-devel
107+
yum install -y dkms kernel-headers-`uname -r` kernel-devel-`uname -r`
108+
fi
102109

103110
yum install -y epel-release
104-
yum install -y dkms kernel-headers-`uname -r` kernel-devel-`uname -r`
105111

106112
if [[ $(ver $ROCM_VERSION) -ge $(ver 4.5) ]]; then
107113
# Add amdgpu repository
@@ -123,23 +129,40 @@ install_centos() {
123129
echo "gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key" >> /etc/yum.repos.d/amdgpu.repo
124130
fi
125131

126-
local rocm_baseurl="http://repo.radeon.com/rocm/yum/${ROCM_VERSION}"
132+
if [[ $OS_VERSION == 9 ]]; then
133+
local rocm_baseurl="invalid-url"
134+
else
135+
local rocm_baseurl="http://repo.radeon.com/rocm/yum/${ROCM_VERSION}/main"
136+
fi
127137
echo "[ROCm]" > /etc/yum.repos.d/rocm.repo
128138
echo "name=ROCm" >> /etc/yum.repos.d/rocm.repo
129139
echo "baseurl=${rocm_baseurl}" >> /etc/yum.repos.d/rocm.repo
130140
echo "enabled=1" >> /etc/yum.repos.d/rocm.repo
131141
echo "gpgcheck=1" >> /etc/yum.repos.d/rocm.repo
132142
echo "gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key" >> /etc/yum.repos.d/rocm.repo
133143

134-
yum update -y
135-
136-
yum install -y \
144+
if [[ $OS_VERSION == 9 ]]; then
145+
yum update -y --nogpgcheck
146+
dnf --enablerepo=crb install -y perl-File-BaseDir
147+
yum install -y --nogpgcheck rocm-ml-sdk rocm-developer-tools
148+
else
149+
yum update -y
150+
yum install -y \
137151
rocm-dev \
138152
rocm-utils \
139153
rocm-libs \
140154
rccl \
141155
rocprofiler-dev \
142156
roctracer-dev
157+
fi
158+
159+
# if search fails it will abort this script; use true to avoid case where search fails
160+
MIOPENKERNELS=$(yum -q search miopenkernels | grep miopenkernels- | awk '{print $1}'| grep -F kdb. || true)
161+
if [[ "x${MIOPENKERNELS}" = x ]]; then
162+
echo "miopenkernels package not available"
163+
else
164+
yum install -y ${MIOPENKERNELS}
165+
fi
143166

144167
# precompiled miopen kernels; search for all unversioned packages
145168
# if search fails it will abort this script; use true to avoid case where search fails
@@ -174,6 +197,8 @@ install_centos() {
174197
rm -rf /var/lib/yum/history
175198
}
176199

200+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
201+
177202
# Install Python packages depending on the base OS
178203
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
179204
case "$ID" in

.ci/docker/common/install_vision.sh

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

2528
# Cleanup
2629
yum clean all
@@ -29,6 +32,8 @@ install_centos() {
2932
rm -rf /var/lib/yum/history
3033
}
3134

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

0 commit comments

Comments
 (0)