From 35252cd34f063472066ad0aa7e39db3aa8133640 Mon Sep 17 00:00:00 2001 From: Weiming Zhao Date: Fri, 3 Dec 2021 20:22:16 -0800 Subject: [PATCH] Refactor Dockerfile --- .github/actions/build/build_in_docker.sh | 2 +- utils/docker/Dockerfile | 168 ++++++++++++++--------- utils/docker/build_image.sh | 4 +- utils/docker/start_docker_cpu.sh | 2 +- 4 files changed, 110 insertions(+), 66 deletions(-) diff --git a/.github/actions/build/build_in_docker.sh b/.github/actions/build/build_in_docker.sh index 3a5c5485f..968d94518 100755 --- a/.github/actions/build/build_in_docker.sh +++ b/.github/actions/build/build_in_docker.sh @@ -1,7 +1,7 @@ #!/bin/bash -xe REPO="registry-intl.us-west-1.aliyuncs.com/computation/halo" -VER="0.7.6" +VER="0.7.7" FLAVOR="devel" MOUNT_DIR="$PWD" diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile index 2727d73f7..fac780edc 100644 --- a/utils/docker/Dockerfile +++ b/utils/docker/Dockerfile @@ -1,6 +1,103 @@ +# syntax=docker/dockerfile:experimental # Build this image: docker build -t halo:[version] . ARG BASE_IMAGE + +# cmake +FROM ubuntu:18.04 AS cmake +ARG CMAKE_VERSION=3.14.5 +RUN apt-get update && apt-get install -y curl gcc g++ make zlib1g zlib1g-dev libcurl4-openssl-dev git && \ + gcc --version && \ + mkdir /tmp/cmake && \ + cd /tmp/cmake && \ + curl -L https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz -o cmake.tar.gz && \ + tar zxf cmake.tar.gz && \ + cd cmake-${CMAKE_VERSION} && \ + ./bootstrap --system-curl --parallel=48 && \ + make -j all && \ + make install DESTDIR=/tmp/cmake/install && \ + make install && \ + tar -C /tmp/cmake/install -cf /tmp/cmake.tar usr && \ + rm -fr /tmp/cmake + +# binutils +FROM cmake AS binutils +ARG BINUTILS_VERSION=2.35 +RUN mkdir /tmp/binutils && \ + cd /tmp/binutils && \ + curl -s http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz | tar xvz && \ + cd binutils-${BINUTILS_VERSION} && \ + ./configure && \ + make -j all && \ + make install DESTDIR=/tmp/binutils/install && \ + tar -C /tmp/binutils/install -cf /tmp/binutils.tar usr && \ + rm -rf /tmp/binutils + +# valgrind +FROM cmake AS valgrind +ARG VALGRIND_VERSION=3.18.1 +RUN mkdir /tmp/valgrind && \ + cd /tmp/valgrind && \ + curl -o valgrind.tar.bz2 ftp://sourceware.org/pub/valgrind/valgrind-${VALGRIND_VERSION}.tar.bz2 && \ + tar jxf valgrind.tar.bz2 && \ + cd valgrind-${VALGRIND_VERSION} && \ + ./configure && \ + make -j all && \ + make install DESTDIR=/tmp/valgrind/install && \ + tar -C /tmp/valgrind/install -cf /tmp/valgrid.tar usr && \ + rm -rf /tmp/valgrind + +# Build Protobuf (static) +FROM cmake AS pb +RUN git -C /tmp clone --depth=1 https://github.com/protocolbuffers/protobuf.git -b v3.9.1 && \ + cd /tmp/protobuf/cmake && \ + cmake -G "Unix Makefiles" -Dprotobuf_BUILD_TESTS=OFF \ + -Dprotobuf_BUILD_SHARED_LIBS=OFF \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON . && \ + make -j && make install DESTDIR=/tmp/protobuf/install && \ + tar -C /tmp/protobuf/install -cf /tmp/protobuf.tar usr && \ + rm -fr /tmp/protobuf + +# Build Flatbuffer +FROM cmake as fb +RUN git -C /tmp clone --depth=1 https://github.com/google/flatbuffers.git -b v1.12.0 && \ + cd /tmp/flatbuffers && \ + cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_SHAREDLIB=OFF && \ + make -j && make install DESTDIR=/tmp/flatbuffers/install && \ + tar -C /tmp/flatbuffers/install -cf /tmp/flatbuffers.tar usr && \ + rm -fr /tmp/flatbuffers + +# Build glog +FROM cmake AS glog +RUN git -C /tmp clone --depth=1 https://github.com/google/glog.git -b v0.4.0 && \ + cd /tmp/glog && \ + cmake -H. -Bbuild -G "Unix Makefiles" && \ + cd build && \ + make -j && make install DESTDIR=/tmp/glog/install && \ + tar -C /tmp/glog/install -cf /tmp/glog.tar usr && \ + rm -fr /tmp/glog + +# Build DNNL +FROM cmake as dnnl +RUN git -C /tmp clone --depth=1 https://github.com/oneapi-src/oneDNN.git --branch v1.7 && \ + cd /tmp/oneDNN && \ + cmake -G "Unix Makefiles" -DDNNL_BUILD_EXAMPLES=OFF -DDNNL_BUILD_TESTS=OFF -DDNNL_ENABLE_PRIMITIVE_CACHE=ON -DCMAKE_INSTALL_PREFIX=/opt/dnnl && \ + make -j && make install DESTDIR=/tmp/oneDNN/install && \ + tar -C /tmp/oneDNN/install -cf /tmp/dnnl.tar opt && \ + rm -fr /tmp/oneDNN + +# Build XNNPack +FROM cmake as xnnpack +RUN git -C /tmp clone https://github.com/google/XNNPACK.git && \ + cd /tmp/XNNPACK && git checkout -b tmp 90db69f681ea9abd1ced813c17c00007f14ce58b && \ + mkdir /tmp/xnn_build && cd /tmp/xnn_build && \ + cmake -G "Unix Makefiles" ../XNNPACK -DXNNPACK_LIBRARY_TYPE=static -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DXNNPACK_BUILD_TESTS=OFF -DXNNPACK_BUILD_BENCHMARKS=OFF -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/opt/XNNPACK && \ + make -j && make install DESTDIR=/tmp/XNNPACK/install && \ + tar -C /tmp/XNNPACK/install -cf /tmp/xnnpack.tar opt && \ + rm -fr /tmp/XNNPACK /mp/xnn_build + FROM ${BASE_IMAGE} # Redeclare the argument @@ -125,58 +222,19 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ RUN pip3 install wheel numpy six jupyter enum34 mock h5py pillow # Update binutils -ARG BINUTILS_VERSION=2.35 -RUN mkdir /tmp/binutils && \ - cd /tmp/binutils && \ - wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz && \ - tar zxf binutils-${BINUTILS_VERSION}.tar.gz && \ - cd binutils-${BINUTILS_VERSION} && \ - ./configure && \ - make -j all && \ - make install && \ - rm -rf /tmp/binutils +RUN --mount=from=binutils,target=/pkg,source=/tmp tar -C / -xf /pkg/binutils.tar # Install cmake -ARG CMAKE_VERSION=3.14.5 -RUN mkdir /tmp/cmake && \ - cd /tmp/cmake && \ - wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz && \ - tar zxf cmake-${CMAKE_VERSION}.tar.gz && \ - cd cmake-${CMAKE_VERSION} && \ - ./bootstrap --system-curl --parallel=48 && \ - make -j all && \ - make install && \ - rm -rf /tmp/cmake +RUN --mount=from=cmake,target=/pkg,source=/tmp tar -C / -xf /pkg/cmake.tar # Install valgrind -ARG VALGRIND_VERSION=3.13.0 -RUN mkdir /tmp/valgrind && \ - cd /tmp/valgrind && \ - wget ftp://sourceware.org/pub/valgrind/valgrind-${VALGRIND_VERSION}.tar.bz2 && \ - tar jxf valgrind-${VALGRIND_VERSION}.tar.bz2 && \ - cd valgrind-${VALGRIND_VERSION} && \ - ./configure && \ - make -j all && \ - make install && \ - rm -rf /tmp/valgrind +RUN --mount=from=valgrind,target=/pkg,source=/tmp tar -C / -xf /pkg/valgrid.tar # INSTALL Protobuf (static) -RUN cd /tmp && \ - git clone --depth=1 https://github.com/protocolbuffers/protobuf.git -b v3.9.1 && \ - cd protobuf/cmake && \ - cmake -G Ninja . -Dprotobuf_BUILD_TESTS=OFF \ - -Dprotobuf_BUILD_SHARED_LIBS=OFF \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON && \ - ninja install && \ - rm -fr /tmp/protobuf +RUN --mount=from=pb,target=/pkg,source=/tmp tar -C / -xf /pkg/protobuf.tar # INSTALL glog -RUN cd /tmp && \ - git clone --depth=1 https://github.com/google/glog.git -b v0.4.0 && \ - cd glog && \ - cmake -H. -Bbuild -G "Unix Makefiles" && cmake --build build && \ - cmake --build build --target install && ldconfig && \ - rm -fr /tmp/glog +RUN --mount=from=glog,target=/pkg,source=/tmp tar -C / -xf /pkg/glog.tar # Install GCC-10 RUN add-apt-repository ppa:ubuntu-toolchain-r/test && \ @@ -185,10 +243,7 @@ RUN add-apt-repository ppa:ubuntu-toolchain-r/test && \ apt-get clean && apt-get purge && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Build & Install DNNL (MKLDNN) -RUN cd /tmp && git clone --depth=1 https://github.com/oneapi-src/oneDNN.git --branch v1.7 && \ - cd /tmp/oneDNN && \ - cmake -G Ninja -DDNNL_BUILD_EXAMPLES=OFF -DDNNL_BUILD_TESTS=OFF -DDNNL_ENABLE_PRIMITIVE_CACHE=ON -DCMAKE_INSTALL_PREFIX=/opt/dnnl && \ - ninja install +RUN --mount=from=dnnl,target=/pkg,source=/tmp tar -C / -xf /pkg/dnnl.tar # Install Parallel RUN apt-get update && \ @@ -196,24 +251,13 @@ RUN apt-get update && \ apt-get clean && apt-get purge && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Install Eigen -RUN cd /tmp && wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.bz2 && \ - tar jxvf eigen-3.4.0.tar.bz2 && mv eigen-3.4.0 /opt +RUN curl -s https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.bz2 | tar -C /opt -xvj # Install XNNPack -RUN cd /tmp && git clone https://github.com/google/XNNPACK.git && \ - cd /tmp/XNNPACK && git checkout -b tmp 90db69f681ea9abd1ced813c17c00007f14ce58b && \ - mkdir /tmp/xnn_build_static && cd /tmp/xnn_build_static && \ - cmake -G Ninja ../XNNPACK -DXNNPACK_LIBRARY_TYPE=static -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DXNNPACK_BUILD_TESTS=OFF -DXNNPACK_BUILD_BENCHMARKS=OFF -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=/opt/XNNPACK && \ - ninja install +RUN --mount=from=xnnpack,target=/pkg,source=/tmp tar -C / -xf /pkg/xnnpack.tar # Install Flatbuffer -RUN cd /tmp && \ - git clone --depth=1 https://github.com/google/flatbuffers.git -b v1.12.0 && \ - cd flatbuffers && \ - cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_SHAREDLIB=ON && make -j && make install && \ - rm -fr /tmp/flatbuffers +RUN --mount=from=fb,target=/pkg,source=/tmp tar -C / -xf /pkg/flatbuffers.tar # INSATLL ONEAPI RUN if [[ ! "${BASE_IMAGE}" =~ "nvidia" ]]; then wget https://registrationcenter-download.intel.com/akdlm/irc_nas/17769/l_BaseKit_p_2021.2.0.2883_offline.sh && \ diff --git a/utils/docker/build_image.sh b/utils/docker/build_image.sh index fe0bc99be..512ee2683 100755 --- a/utils/docker/build_image.sh +++ b/utils/docker/build_image.sh @@ -1,6 +1,6 @@ #!/bin/bash -xe -VER="0.7.6" +VER="0.7.7" FLAVOR="devel" NAMESPACE="registry-intl.us-west-1.aliyuncs.com/computation" @@ -10,6 +10,6 @@ base_image_cpu="ubuntu:18.04" #docker build --build-arg BASE_IMAGE=${base_image_cpu} \ # -t $NAMESPACE/halo:$VER-$FLAVOR-x86_64-ubuntu18.04 . -docker build --build-arg BASE_IMAGE=${base_image_gpu} \ +DOCKER_BUILDKIT=1 docker build --build-arg BASE_IMAGE=${base_image_gpu} \ -t $NAMESPACE/halo:$VER-$FLAVOR-cuda11.4.2-cudnn8-ubuntu18.04 . diff --git a/utils/docker/start_docker_cpu.sh b/utils/docker/start_docker_cpu.sh index 5267a1e04..7d6a53715 100755 --- a/utils/docker/start_docker_cpu.sh +++ b/utils/docker/start_docker_cpu.sh @@ -1,6 +1,6 @@ #!/bin/bash -xe -VER="0.7.6" +VER="0.7.7" FLAVOR="devel" NAMESPACE="registry-intl.us-west-1.aliyuncs.com/computation"