Skip to content

Commit

Permalink
- build user image with ubi8-minimal base image (llvm#1185)
Browse files Browse the repository at this point in the history
- install onnx into lib instead of lib64
- fix time zone setup in container
- download jsoniter jar from maven repo
- run check-mlir on s390x but ignore error for now
- run check-onnx-backend-signature
- unshallow and rename origin to upstream for onnx-mlir-dev
  image to be published

Signed-off-by: Gong Su <gong_su@hotmail.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
  • Loading branch information
gongsu832 and AlexandreEichenberger authored Feb 26, 2022
1 parent 28c8ec7 commit e53ef4c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 70 deletions.
5 changes: 4 additions & 1 deletion .buildbot/jenkins-build-llvm-project.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
LLVM_PROJECT_SHA1_REGEX = 'git checkout ([0-9a-f]+)'
LLVM_PROJECT_DOCKERFILE = 'docker/Dockerfile.llvm-project'
LLVM_PROJECT_GITHUB_URL = 'https://api.github.com/repos/llvm/llvm-project'
BASE_IMAGE = { 'static': 'ubuntu:focal',
'shared': 'registry.access.redhat.com/ubi8-minimal:latest' }
LLVM_PROJECT_IMAGE = { 'static': docker_static_image_name,
'shared': docker_shared_image_name }
BUILD_SHARED_LIBS = { 'static': 'off',
Expand Down Expand Up @@ -339,13 +341,14 @@ def setup_private_llvm(image_type, exp):
decode = True,
rm = True,
buildargs = {
'BASE_IMAGE': BASE_IMAGE[image_type],
'NPROC': NPROC,
'BUILD_SHARED_LIBS': BUILD_SHARED_LIBS[image_type],
'LLVM_PROJECT_SHA1': exp['llvm_project_sha1'],
'LLVM_PROJECT_SHA1_DATE': exp['llvm_project_sha1_date'],
'LLVM_PROJECT_DOCKERFILE_SHA1': exp['llvm_project_dockerfile_sha1'],
GITHUB_REPO_NAME2 + '_PR_NUMBER': github_pr_number,
GITHUB_REPO_NAME2 + '_PR_NUMBER2': github_pr_number2
GITHUB_REPO_NAME2 + '_PR_NUMBER2': github_pr_number2,
}):

if 'stream' in line:
Expand Down
100 changes: 62 additions & 38 deletions docker/Dockerfile.llvm-project
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,75 @@ LABEL llvm_project_dockerfile_sha1=${LLVM_PROJECT_DOCKERFILE_SHA1}
LABEL onnx_mlir_pr_number=${ONNX_MLIR_PR_NUMBER}
LABEL onnx_mlir_pr_number2=${ONNX_MLIR_PR_NUMBER2}

ARG NPROC=4
ARG WORK_DIR=/workdir
WORKDIR ${WORK_DIR}

# Install tools needed
RUN DEBIAN_FRONTEND=noninteractive TZ="America/New_York" \
apt-get update -qq \
&& apt-get install -qq -y --no-install-recommends tzdata \
&& apt-get install -qq -y --no-install-recommends \
autoconf automake ca-certificates cmake default-jdk-headless \
gcc g++ git libncurses-dev libtool make maven ninja-build \
openjdk-11-jdk-headless python3 python3-dev python3-distutils \
python3-numpy python3-pip python3-pybind11 python3-pytest-xdist \
python3-setuptools python3-typing-extensions wget zlib1g-dev \
&& ln -sf /usr/bin/python3 /usr/bin/python \
&& ln -sf /usr/bin/pytest-3 /usr/bin/pytest \
&& rm -rf /var/lib/apt/lists/*
RUN distro=$(cat /etc/os-release|grep -Po '(?<=^ID=").*(?=")|(?<=^ID=)[^"].*[^"]') \
&& TZ="America/New_York" \
&& if [ "${distro}" = "debian" ] || [ "${distro}" = "ubuntu" ]; then \
DEBIAN_FRONTEND=noninteractive && \
apt-get update -qq && \
apt-get install -qq -y --no-install-recommends tzdata && \
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get install -qq -y --no-install-recommends \
autoconf automake ca-certificates cmake curl \
default-jdk-headless gcc g++ git libncurses-dev \
libtool make maven ninja-build openjdk-11-jdk-headless \
python3 python3-dev python3-distutils python3-numpy \
python3-pip python3-pytest-xdist python3-setuptools \
python3-typing-extensions zlib1g-dev && \
rm -rf /var/lib/apt/lists/* && \
ln -sf /usr/bin/pytest-3 /usr/bin/pytest; \
elif [ "${distro}" = "rhel" ] || [ "${distro}" = "fedora" ]; then \
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
([ -x /usr/bin/microdnf ] && microdnf install -y yum) && \
yum install -q -y \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \
yum update -q -y && \
yum install -q -y \
autoconf automake ca-certificates cmake diffutils \
file java-11-openjdk-devel java-11-openjdk-headless \
gcc gcc-c++ git libtool make ncurses-devel \
python39 python39-devel python39-numpy python39-pip \
python39-setuptools python39-wheel zlib-devel && \
# Use same versions as those in ubuntu:focal
pip3 install -q \
Cython pytest==4.6.9 pytest-forked==1.1.3 \
pytest-xdist==1.31.0 typing-extensions==3.7.4.1 && \
rm -rf /var/cache/dnf/* && \
# Install ninja
git clone -b v1.10.2 https://github.com/ninja-build/ninja.git && \
cd ninja && mkdir -p build && cd build && \
cmake .. && \
make -j${NPROC} install && \
cd ${WORK_DIR} && rm -rf ninja; \
fi \
&& ln -sf /usr/bin/python3 /usr/bin/python

# Clone and build llvm-project
COPY utils/clone-mlir.sh /tmp
RUN . /tmp/clone-mlir.sh && rm -f /tmp/clone-mlir.sh

ARG NPROC=2
ARG BUILD_SHARED_LIBS=OFF

# Install protobuf 3.14.0
RUN git clone -b v3.14.0 --recursive https://github.com/google/protobuf.git \
# Install protobuf
ARG PROTOBUF_VERSION=3.14.0
RUN git clone -b v${PROTOBUF_VERSION} --recursive https://github.com/google/protobuf.git \
&& cd protobuf && ./autogen.sh \
&& ./configure --enable-static=$([[ "${BUILD_SHARED_LIBS}" = "OFF" ]] && \
echo yes || echo no) \
&& ./configure --enable-static=no \
&& make -j${NPROC} install && ldconfig \
&& cd .. && rm -rf protobuf
&& cd python && python setup.py install \
&& cd ../.. && rm -rf protobuf

# Install jsoniter 0.9.23
RUN git clone -b 0.9.23 https://github.com/json-iterator/java.git jsoniter \
&& mvn -Dmaven.artifact.threads=${NPROC} \
-Dmaven.repo.local=.m2 \
-Dmaven.javadoc.skip=true \
-Dmaven.source.skip=true \
-Dmaven.test.skip=true \
-q -f jsoniter package \
&& cp jsoniter/target/jsoniter-0.9.23.jar /usr/share/java/ \
&& rm -rf .m2 jsoniter
# Install jsoniter
ARG JSONITER_VERSION=0.9.23
RUN JSONITER_URL=https://repo1.maven.org/maven2/com/jsoniter/jsoniter/${JSONITER_VERSION} \
&& JSONITER_FILE=jsoniter-${JSONITER_VERSION}.jar \
&& curl -s ${JSONITER_URL}/${JSONITER_FILE} -o /usr/share/java/${JSONITER_FILE}

# Build llvm-project and run tests
RUN cd llvm-project && mkdir build && cd build \
# Clone and build llvm-project and run tests
ARG BUILD_SHARED_LIBS=OFF
RUN git clone -n https://github.com/llvm/llvm-project.git \
&& cd llvm-project \
&& git checkout ${LLVM_PROJECT_SHA1} \
&& mkdir -p build && cd build \
&& cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_TARGETS_TO_BUILD="host" \
Expand All @@ -67,8 +91,8 @@ RUN cd llvm-project && mkdir build && cd build \
-DLLVM_ENABLE_RTTI=ON \
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \
&& cmake --build . --parallel ${NPROC} -- ${MAKEFLAGS} \
&& ([ "$(uname -m)" = "s390x" ] || \
cmake --build . --parallel ${NPROC} --target check-mlir) \
&& (cmake --build . --parallel ${NPROC} --target check-mlir || \
[ "$(uname -m)" = "s390x" ]) \
&& rm -rf /tmp/* \
&& echo "llvm-project commit $(git rev-parse HEAD) successfully built"

Expand Down
51 changes: 33 additions & 18 deletions docker/Dockerfile.onnx-mlir
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE} AS onnx-mlir-test

# Label the base image so it can be cleaned up after becoming dangling
# Label the base image so it can be cleaned up after becoming dangling
ARG ONNX_MLIR_PR_NUMBER
ARG ONNX_MLIR_PR_NUMBER2
LABEL onnx_mlir_pr_number=${ONNX_MLIR_PR_NUMBER}
Expand All @@ -14,15 +14,17 @@ WORKDIR ${WORK_DIR}
COPY . onnx-mlir

# Setup onnx
#ARG THIRD_PARTY_ONNX_SHA1=b2a20a9d07678e89ae9346243035e194b63e0e8a
#RUN pip3 install git+git://github.com/onnx/onnx.git@${THIRD_PARTY_ONNX_SHA1} \
# && rm -rf /root/.cache
# Install into lib instead of lib64 since everything else is in lib
RUN ONNX_ROOT=${WORK_DIR}/onnx-mlir/third_party/onnx \
&& INSTALL_LIB=$(python3 -c "import re; import site; \
print(list(filter(lambda site: not re.search('lib64', site), \
site.getsitepackages()))[0])") \
&& cd ${ONNX_ROOT} \
&& python3 setup.py -q install \
&& python3 setup.py -q install --install-lib=${INSTALL_LIB} \
&& rm -rf .eggs .setuptools-cmake-build build dist onnx.egg-info

ARG NPROC=2
ARG NPROC=4
ARG TEST_MCPU

RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
&& ONNX_MLIR_ROOT=${WORK_DIR}/onnx-mlir \
Expand All @@ -39,31 +41,44 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
&& make -j${NPROC} \
&& make -j${NPROC} LIT_OPTS=-v check-onnx-lit \
# User image is built with SIMD (currently on s390x only)
&& TEST_MCPU=$([ "$(uname -m)" = "s390x" ] && echo z14 || \
[ "$(uname -m)" = "x86_64" ] && echo || \
[ "$(uname -m)" = "ppc64le" ] && echo || echo) \
&& TEST_MCPU=${TEST_MCPU:-$([ "$(uname -m)" = "s390x" ] && echo z14 || \
[ "$(uname -m)" = "x86_64" ] && echo || \
[ "$(uname -m)" = "ppc64le" ] && echo || echo)} \
&& TEST_ARGS="-mcpu=${TEST_MCPU}" \
&& make NPROC=${NPROC} \
CTEST_PARALLEL_LEVEL=${NPROC} \
TEST_MCPU=${TEST_MCPU} \
TEST_ARGS="${TEST_ARGS}" \
-j${NPROC} -f CMakeFiles/Makefile2 \
-j${NPROC} -f CMakeFiles/Makefile2 \
check-onnx-backend \
check-onnx-backend-dynamic \
check-onnx-backend-constant \
check-onnx-backend-jni \
check-onnx-backend-dynamic-jni \
check-onnx-backend-constant-jni \
check-onnx-backend-signature \
check-onnx-backend-jni \
check-onnx-backend-dynamic-jni \
check-onnx-backend-constant-jni \
check-onnx-numerical \
&& make check-docs \
&& make -j${NPROC} install \
&& echo -e "/usr/local/lib" > \
/etc/ld.so.conf.d/onnx-mlir.conf && ldconfig \
# Clean up
&& cd ${WORK_DIR} \
&& apt-get purge --autoremove -qq -y \
autoconf automake cmake git libtool make \
maven ninja-build python3 wget \
&& rm -rf /tmp/* /var/lib/apt/lists/* \
/usr/bin/python llvm-project onnx-mlir
&& distro=$(cat /etc/os-release|grep -Po '(?<=^ID=).*'|sed 's/\"//g') \
&& if [ "${distro}" = "debian" ] || [ "${distro}" = "ubuntu" ]; then \
apt-get purge --autoremove -qq -y \
autoconf automake cmake curl git libtool \
make ninja-build python3 && \
rm -rf /var/lib/apt/lists/*; \
elif [ "${distro}" = "rhel" ] || [ "${distro}" = "fedora" ]; then \
pip3 uninstall -q -y Cython pybind11 pytest pytest-forked \
pytest-xdist typing-extensions && \
yum remove -q -y \
adwaita-icon-theme autoconf automake cmake diffutils file \
git libtool make python39 && \
rm -rf /var/cache/dnf/* /usr/local/bin/ninja; \
fi \
&& rm -rf /tmp/* /usr/bin/python llvm-project onnx-mlir

# Copy from onnx-mlir-test to squash removed source layer and
# remove dependency on base image (onnx-mlir-llvm-shared)
Expand Down
26 changes: 17 additions & 9 deletions docker/Dockerfile.onnx-mlir-dev
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ WORKDIR ${WORK_DIR}
COPY . onnx-mlir

# Setup onnx
#ARG THIRD_PARTY_ONNX_SHA1=b2a20a9d07678e89ae9346243035e194b63e0e8a
#RUN pip3 install git+git://github.com/onnx/onnx.git@${THIRD_PARTY_ONNX_SHA1} \
# && rm -rf /root/.cache
# Install into lib instead of lib64 since everything else is in lib
RUN ONNX_ROOT=${WORK_DIR}/onnx-mlir/third_party/onnx \
&& INSTALL_LIB=$(python3 -c "import re; import site; \
print(list(filter(lambda site: not re.search('lib64', site), \
site.getsitepackages()))[0])") \
&& cd ${ONNX_ROOT} \
&& python3 setup.py -q install \
&& python3 setup.py -q install --install-lib=${INSTALL_LIB} \
&& rm -rf .eggs .setuptools-cmake-build build dist onnx.egg-info

ARG NPROC=2
ARG NPROC=4

RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
&& ONNX_MLIR_ROOT=${WORK_DIR}/onnx-mlir \
Expand All @@ -42,15 +43,22 @@ RUN LLVM_PROJECT_ROOT=${WORK_DIR}/llvm-project \
CTEST_PARALLEL_LEVEL=${NPROC} \
TEST_MCPU=${TEST_MCPU} \
TEST_ARGS="${TEST_ARGS}" \
-j${NPROC} -f CMakeFiles/Makefile2 \
-j${NPROC} -f CMakeFiles/Makefile2 \
check-onnx-backend \
check-onnx-backend-dynamic \
check-onnx-backend-constant \
check-onnx-backend-jni \
check-onnx-backend-dynamic-jni \
check-onnx-backend-constant-jni \
check-onnx-backend-signature \
check-onnx-backend-jni \
check-onnx-backend-dynamic-jni \
check-onnx-backend-constant-jni \
check-onnx-numerical \
&& make check-docs \
# When building for push event to publish the image, unshallow and
# rename origin to upstream to make the repo a bit more dev friendly.
&& if [ "${ONNX_MLIR_PR_NUMBER}" != "${ONNX_MLIR_PR_NUMBER2}" ]; then \
git fetch --unshallow && \
git remote rename origin upstream; \
fi \
&& rm -rf /tmp/*

# Copy from onnx-mlir-dev-test to squash removed source layer and
Expand Down
2 changes: 1 addition & 1 deletion docs/BuildOnLinuxOSX.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Firstly, install MLIR (as a part of LLVM-Project):

[same-as-file]: <> (utils/clone-mlir.sh)
``` bash
git clone https://github.com/llvm/llvm-project.git
git clone -n https://github.com/llvm/llvm-project.git
# Check out a specific branch that is known to work with ONNX-MLIR.
cd llvm-project && git checkout d7f0083dcae45e6bf774af23533a2d5e18aaf253 && cd ..
```
Expand Down
4 changes: 2 additions & 2 deletions docs/BuildOnWindows.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Install MLIR (as a part of LLVM-Project):

[same-as-file]: <> (utils/clone-mlir.sh)
```shell
git clone https://github.com/llvm/llvm-project.git
git clone -n https://github.com/llvm/llvm-project.git
# Check out a specific branch that is known to work with ONNX-MLIR.
cd llvm-project && git checkout d7f0083dcae45e6bf774af23533a2d5e18aaf253 && cd ..
```
Expand Down Expand Up @@ -99,4 +99,4 @@ call cmake %root_dir%\onnx-mlir -G "Ninja" ^

call cmake --build . --config Release --target onnx-mlir
```
After the above commands succeed, an `onnx-mlir` executable should appear in the `Debug/bin` or `Release/bin` directory.
After the above commands succeed, an `onnx-mlir` executable should appear in the `Debug/bin` or `Release/bin` directory.
2 changes: 1 addition & 1 deletion utils/clone-mlir.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
git clone https://github.com/llvm/llvm-project.git
git clone -n https://github.com/llvm/llvm-project.git
# Check out a specific branch that is known to work with ONNX-MLIR.
cd llvm-project && git checkout d7f0083dcae45e6bf774af23533a2d5e18aaf253 && cd ..

0 comments on commit e53ef4c

Please sign in to comment.