Skip to content

Commit cd830e1

Browse files
[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 ad5bdb1 commit cd830e1

File tree

6 files changed

+197
-23
lines changed

6 files changed

+197
-23
lines changed

.circleci/docker/build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ fi
294294

295295
tmp_tag=$(basename "$(mktemp -u)" | tr '[:upper:]' '[:lower:]')
296296

297+
if [[ "$image" == *centos9* ]]; then
298+
DOCKERFILE_NAME="Dockerfile.centos.stream"
299+
else
300+
DOCKERFILE_NAME="Dockerfile"
301+
fi
302+
297303
# Build image
298304
# TODO: build-arg THRIFT is not turned on for any image, remove it once we confirm
299305
# it's no longer needed.
@@ -330,7 +336,7 @@ docker build \
330336
--build-arg "KATEX=${KATEX:-}" \
331337
--build-arg "ROCM_VERSION=${ROCM_VERSION:-}" \
332338
--build-arg "PYTORCH_ROCM_ARCH=${PYTORCH_ROCM_ARCH:-gfx900;gfx906;gfx908}" \
333-
-f $(dirname ${DOCKERFILE})/Dockerfile \
339+
-f $(dirname ${DOCKERFILE})/${DOCKERFILE_NAME} \
334340
-t "$tmp_tag" \
335341
"$@" \
336342
.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
ADD requirements-ci.txt /opt/conda/requirements-ci.txt
46+
ADD ./common/install_conda.sh install_conda.sh
47+
RUN bash ./install_conda.sh && rm install_conda.sh
48+
RUN rm /opt/conda/requirements-ci.txt
49+
50+
# (optional) Install protobuf for ONNX
51+
ARG PROTOBUF
52+
ADD ./common/install_protobuf.sh install_protobuf.sh
53+
RUN if [ -n "${PROTOBUF}" ]; then bash ./install_protobuf.sh; fi
54+
RUN rm install_protobuf.sh
55+
ENV INSTALLED_PROTOBUF ${PROTOBUF}
56+
57+
# (optional) Install database packages like LMDB and LevelDB
58+
ARG DB
59+
ADD ./common/install_db.sh install_db.sh
60+
RUN if [ -n "${DB}" ]; then bash ./install_db.sh; fi
61+
RUN rm install_db.sh
62+
ENV INSTALLED_DB ${DB}
63+
64+
# (optional) Install vision packages like OpenCV and ffmpeg
65+
ARG VISION
66+
ADD ./common/install_vision.sh install_vision.sh
67+
RUN if [ -n "${VISION}" ]; then bash ./install_vision.sh; fi
68+
RUN rm install_vision.sh
69+
ENV INSTALLED_VISION ${VISION}
70+
71+
# Install rocm
72+
ARG ROCM_VERSION
73+
ADD ./common/install_rocm.sh install_rocm.sh
74+
RUN bash ./install_rocm.sh
75+
RUN rm install_rocm.sh
76+
ENV PATH /opt/rocm/bin:$PATH
77+
ENV PATH /opt/rocm/hcc/bin:$PATH
78+
ENV PATH /opt/rocm/hip/bin:$PATH
79+
ENV PATH /opt/rocm/opencl/bin:$PATH
80+
ENV PATH /opt/rocm/llvm/bin:$PATH
81+
ENV MAGMA_HOME /opt/rocm/magma
82+
ENV LANG en_US.utf8
83+
ENV LC_ALL en_US.utf8
84+
85+
# (optional) Install non-default CMake version
86+
ARG CMAKE_VERSION
87+
ADD ./common/install_cmake.sh install_cmake.sh
88+
RUN if [ -n "${CMAKE_VERSION}" ]; then bash ./install_cmake.sh; fi
89+
RUN rm install_cmake.sh
90+
91+
# (optional) Install non-default Ninja version
92+
ARG NINJA_VERSION
93+
ADD ./common/install_ninja.sh install_ninja.sh
94+
RUN if [ -n "${NINJA_VERSION}" ]; then bash ./install_ninja.sh; fi
95+
RUN rm install_ninja.sh
96+
97+
# Install ccache/sccache (do this last, so we get priority in PATH)
98+
ADD ./common/install_cache.sh install_cache.sh
99+
ENV PATH /opt/cache/bin:$PATH
100+
RUN bash ./install_cache.sh && rm install_cache.sh
101+
102+
# Include BUILD_ENVIRONMENT environment variable in image
103+
ARG BUILD_ENVIRONMENT
104+
ENV BUILD_ENVIRONMENT ${BUILD_ENVIRONMENT}
105+
106+
USER jenkins
107+
CMD ["bash"]

.circleci/docker/common/install_base.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,21 @@ install_ubuntu() {
5757
install_centos() {
5858
# Need EPEL for many packages we depend on.
5959
# See http://fedoraproject.org/wiki/EPEL
60-
yum --enablerepo=extras install -y epel-release
60+
# extras repo is not there for CentOS 9 and epel-release is already part of repo list
61+
if [[ $OS_VERSION == 9 ]]; then
62+
yum install -y epel-release
63+
ALLOW_ERASE="--allowerasing"
64+
else
65+
yum --enablerepo=extras install -y epel-release
66+
ALLOW_ERASE=""
67+
fi
6168

6269
ccache_deps="asciidoc docbook-dtds docbook-style-xsl libxslt"
6370
numpy_deps="gcc-gfortran"
6471
# Note: protobuf-c-{compiler,devel} on CentOS are too old to be used
6572
# for Caffe2. That said, we still install them to make sure the build
6673
# system opts to build/use protoc and libprotobuf from third-party.
67-
yum install -y \
74+
yum install -y $ALLOW_ERASE \
6875
$ccache_deps \
6976
$numpy_deps \
7077
autoconf \
@@ -82,22 +89,31 @@ install_centos() {
8289
glog-devel \
8390
hiredis-devel \
8491
libstdc++-devel \
85-
libsndfile-devel \
8692
make \
87-
opencv-devel \
8893
sudo \
8994
wget \
9095
vim
9196

97+
if [[ $OS_VERSION == 9 ]]
98+
then
99+
dnf --enablerepo=crb -y install libsndfile-devel
100+
else
101+
yum install -y \
102+
opencv-devel \
103+
libsndfile-devel
104+
fi
105+
92106
# Cleanup
93107
yum clean all
94108
rm -rf /var/cache/yum
95109
rm -rf /var/lib/yum/yumdb
96110
rm -rf /var/lib/yum/history
97111
}
98112

99-
# Install base packages depending on the base OS
100113
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
114+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
115+
116+
# Install base packages depending on the base OS
101117
case "$ID" in
102118
ubuntu)
103119
install_ubuntu
@@ -112,7 +128,6 @@ case "$ID" in
112128
esac
113129

114130
# Install Valgrind separately since the apt-get version is too old.
115-
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
116131
if [[ $ID == centos && $OS_VERSION == 7 ]]; then WGET_FLAG="--no-check-certificate" ; else WGET_FLAG=""; fi
117132
mkdir valgrind_build && cd valgrind_build
118133
VALGRIND_VERSION=3.16.1

.circleci/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

.circleci/docker/common/install_rocm.sh

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,24 @@ install_centos() {
9696
yum update -y
9797
yum install -y kmod
9898
yum install -y wget
99-
yum install -y openblas-devel
99+
100+
if [[ $OS_VERSION == 9 ]]; then
101+
dnf install -y openblas-serial
102+
dnf install -y dkms kernel-headers kernel-devel
103+
else
104+
yum install -y openblas-devel
105+
yum install -y dkms kernel-headers-`uname -r` kernel-devel-`uname -r`
106+
fi
100107

101108
yum install -y epel-release
102-
yum install -y dkms kernel-headers-`uname -r` kernel-devel-`uname -r`
103109

104110
if [[ $(ver $ROCM_VERSION) -ge $(ver 4.5) ]]; then
105111
# Add amdgpu repository
106-
local amdgpu_baseurl="https://repo.radeon.com/amdgpu/${AMDGPU_VERSIONS[$ROCM_VERSION]}/rhel/7.9/main/x86_64"
112+
if [[ $OS_VERSION == 9 ]]; then
113+
local amdgpu_baseurl="https://repo.radeon.com/amdgpu/${AMDGPU_VERSIONS[$ROCM_VERSION]}/rhel/9.0/main/x86_64"
114+
else
115+
local amdgpu_baseurl="https://repo.radeon.com/amdgpu/${AMDGPU_VERSIONS[$ROCM_VERSION]}/rhel/7.9/main/x86_64"
116+
fi
107117
echo "[AMDGPU]" > /etc/yum.repos.d/amdgpu.repo
108118
echo "name=AMDGPU" >> /etc/yum.repos.d/amdgpu.repo
109119
echo "baseurl=${amdgpu_baseurl}" >> /etc/yum.repos.d/amdgpu.repo
@@ -112,23 +122,40 @@ install_centos() {
112122
echo "gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key" >> /etc/yum.repos.d/amdgpu.repo
113123
fi
114124

115-
local rocm_baseurl="http://repo.radeon.com/rocm/yum/${ROCM_VERSION}"
125+
if [[ $OS_VERSION == 9 ]]; then
126+
local rocm_baseurl="invalid-url"
127+
else
128+
local rocm_baseurl="http://repo.radeon.com/rocm/yum/${ROCM_VERSION}/main"
129+
fi
116130
echo "[ROCm]" > /etc/yum.repos.d/rocm.repo
117131
echo "name=ROCm" >> /etc/yum.repos.d/rocm.repo
118132
echo "baseurl=${rocm_baseurl}" >> /etc/yum.repos.d/rocm.repo
119133
echo "enabled=1" >> /etc/yum.repos.d/rocm.repo
120134
echo "gpgcheck=1" >> /etc/yum.repos.d/rocm.repo
121135
echo "gpgkey=http://repo.radeon.com/rocm/rocm.gpg.key" >> /etc/yum.repos.d/rocm.repo
122136

123-
yum update -y
124-
125-
yum install -y \
137+
if [[ $OS_VERSION == 9 ]]; then
138+
yum update -y --nogpgcheck
139+
dnf --enablerepo=crb install -y perl-File-BaseDir
140+
yum install -y --nogpgcheck rocm-ml-sdk rocm-developer-tools
141+
else
142+
yum update -y
143+
yum install -y \
126144
rocm-dev \
127145
rocm-utils \
128146
rocm-libs \
129147
rccl \
130148
rocprofiler-dev \
131149
roctracer-dev
150+
fi
151+
152+
# if search fails it will abort this script; use true to avoid case where search fails
153+
MIOPENKERNELS=$(yum -q search miopenkernels | grep miopenkernels- | awk '{print $1}'| grep -F kdb. || true)
154+
if [[ "x${MIOPENKERNELS}" = x ]]; then
155+
echo "miopenkernels package not available"
156+
else
157+
yum install -y ${MIOPENKERNELS}
158+
fi
132159

133160
install_magma
134161

@@ -139,6 +166,8 @@ install_centos() {
139166
rm -rf /var/lib/yum/history
140167
}
141168

169+
OS_VERSION=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
170+
142171
# Install Python packages depending on the base OS
143172
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
144173
case "$ID" in

.circleci/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)