-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathDockerfile
More file actions
204 lines (161 loc) · 6.47 KB
/
Dockerfile
File metadata and controls
204 lines (161 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
FROM ubuntu:24.04 AS build
ENV DEBIAN_FRONTEND=noninteractive
# Install 'add-apt-repository'
RUN apt-get update \
&& apt-get -qqy install apt-utils software-properties-common
# Build tool
RUN apt-get update \
&& apt-get -qqy install build-essential cmake git fakeroot autoconf automake libtool unzip wget \
devscripts debmake debhelper lcov
RUN apt-get update \
&& apt-get -qqy install zlib1g-dev pkg-config libhdf5-dev
# additonal tools
RUN apt-get update \
&& apt-get -qqy install tree tmux sudo
# add ppa:circletools to install circle-interpreter
RUN add-apt-repository ppa:circletools/nightly -y
# Python
RUN apt-get update \
&& apt-get -qqy install python3 python3-pip python3-venv python3-dev dh-python
# TODO upgrade
ARG VER_TORCH=2.7.0+cpu
ARG VER_ONNX=1.18.0
ARG VER_ONNXRUNTIME=1.21.1
ARG VER_NUMPY=1.26.4
ARG VER_H5PY=3.12.1
# Clean archives (to reduce image size)
RUN apt-get clean -y
#
# For CIRCLE-MLIR
#
ARG NPROC=4
ARG WORK_DIR=/workdir
ARG FLATBUFFERS_HASH=a078130c
ARG ABSEIL_CPP_HASH=d9e4955c65cd4367dd6bf46f4ccb8cd3d100540b
ARG LLVM_PROJECT_HASH=b270525f730be6e7196667925f5a9bfa153262e9
ARG ONNX_MLIR_HASH=d050bf35a2f186e45b0a4037c0a1d0727c69e7e6
WORKDIR ${WORK_DIR}
# prepare python3 virtual-env
# h5py and einops are used in test
RUN python3 -m venv ${WORK_DIR}/venv
RUN ${WORK_DIR}/venv/bin/python3 -m pip install --upgrade pip setuptools
RUN ${WORK_DIR}/venv/bin/python3 -m pip install numpy==${VER_NUMPY} torch==${VER_TORCH} \
-f https://download.pytorch.org/whl/torch
RUN ${WORK_DIR}/venv/bin/python3 -m pip install onnx==${VER_ONNX} onnxruntime==${VER_ONNXRUNTIME} \
h5py==${VER_H5PY} einops
# Download experimental patch file for onnx-mlir
RUN wget https://raw.githubusercontent.com/Samsung/ONE/refs/heads/master/circle-mlir/externals/onnx_mlir_0_5_0_0.diff \
-O ${WORK_DIR}/onnx_mlir_0_5_0_0.diff
# FLATBUFFERS build from source
RUN git clone --recursive https://github.com/google/flatbuffers.git \
&& cd flatbuffers && git checkout ${FLATBUFFERS_HASH}
RUN mkdir flatbuffers-build && cd flatbuffers-build \
&& cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${WORK_DIR} ../flatbuffers \
&& make -j${NPROC} && make install
RUN rm -rf flatbuffers \
&& rm -rf flatbuffers-build
# ABSEIL-CPP build from source
RUN git clone --recursive https://github.com/abseil/abseil-cpp.git \
&& cd abseil-cpp && git checkout ${ABSEIL_CPP_HASH}
RUN mkdir abseil-cpp-build && cd abseil-cpp-build \
&& cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${WORK_DIR} \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON \
../abseil-cpp \
&& make -j${NPROC} && make install
RUN rm -rf abseil-cpp \
&& rm -rf abseil-cpp-build
# NINJA
RUN 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
RUN rm -rf ninja
# bazel to build protobuf from source
ARG BAZEL_ARCH="x86_64"
ARG BAZEL_VERSION=5.2.0
RUN wget -q https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-${BAZEL_ARCH} \
-O /usr/bin/bazel \
&& chmod a+x /usr/bin/bazel
# protobuf build from source
RUN git clone -b v21.12 https://github.com/google/protobuf.git \
&& cd protobuf \
&& git submodule update --init --recursive
RUN cd protobuf \
&& ./autogen.sh \
&& ./configure --with-zlib \
&& make -j${NPROC} && make install && ldconfig
RUN rm -rf protobuf \
&& rm -f /usr/bin/bazel
# Download LLVM and ONNX-MLIR
# NOTE download two huge repos at once to fast fail for network problems
RUN git clone --recursive https://github.com/llvm/llvm-project.git \
&& cd llvm-project && git checkout ${LLVM_PROJECT_HASH}
RUN git clone https://github.com/onnx/onnx-mlir.git \
&& cd onnx-mlir \
&& git checkout ${ONNX_MLIR_HASH} \
&& git submodule update --init --recursive
# LLVM/MLIR build from source
RUN mkdir llvm-project-build && cd llvm-project-build \
&& cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${WORK_DIR} \
-DLLVM_ENABLE_PROJECTS=mlir -DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_RTTI=ON \
-DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link \
-DCMAKE_JOB_POOLS:STRING='compile=4;link=1' \
../llvm-project/llvm
RUN cd llvm-project-build && cmake --build . && cmake --install .
# LLVM/MLIR clean up
RUN rm -rf llvm-project
RUN rm -rf llvm-project-build
# ONNX-MLIR build from source
# Patch to accept INT16 for QuantizeLinear/DequantizeLinear and fix ONNX passes
RUN cd onnx-mlir \
&& patch -p1 < ${WORK_DIR}/onnx_mlir_0_5_0_0.diff
RUN mkdir onnx-mlir-build && cd onnx-mlir-build \
&& cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${WORK_DIR} \
-DMLIR_DIR=${WORK_DIR}/llvm-project-build/lib/cmake/mlir \
-DPython3_ROOT_DIR=${WORK_DIR}/venv/bin \
-DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link \
-DCMAKE_JOB_POOLS:STRING='compile=4;link=1' \
-DONNX_MLIR_BUILD_TESTS=OFF -DONNX_MLIR_ENABLE_STABLEHLO=OFF \
-DONNX_MLIR_ENABLE_JAVA=OFF -DLLVM_ENABLE_ASSERTIONS=ON \
../onnx-mlir
RUN cd onnx-mlir-build && cmake --build . && cmake --install .
# ONNX-MLIR clean up
RUN rm -rf onnx-mlir/.git \
&& rm -rf onnx-mlir/third_party/* \
&& rm -rf onnx-mlir-build/test \
&& rm -rf onnx-mlir-build/Release
RUN find ./onnx-mlir-build -name *.o -exec rm {} \;
RUN find ./onnx-mlir-build -name *.so -exec rm {} \;
# bin cleanup and strip
RUN rm -f ./bin/onnx-mlir-opt \
&& rm -f ./bin/onnx-mlir-reduce
RUN cd ./bin && strip -s *
RUN cd ./lib && strip -s *.so.*git
# more cleanup
RUN rm -f /usr/local/lib/libprotoc.* \
&& rm -rf /usr/local/man \
&& rm -rf /usr/local/doc \
&& rm -rf ./onnx-mlir-build/docs/* \
&& rm -rf ./onnx-mlir-build/third_party/* \
&& rm -f ./onnx-mlir-build/.ninja_* \
&& rm -f ./onnx-mlir-build/build.ninja
# copy from build
FROM ubuntu:24.04
COPY --from=build / /
# Add user account
ARG USER_ACCOUNT=circlemlir
ARG USER_ID=1000
ARG GROUP_ID=${USER_ID}
# NOTE ubuntu:24.04 already has ubuntu user/group as 1000
RUN deluser ubuntu
RUN addgroup --gid ${GROUP_ID} ${USER_ACCOUNT} \
&& adduser --disabled-password --gecos '' --uid ${USER_ID} --gid ${GROUP_ID} ${USER_ACCOUNT} \
&& usermod -aG sudo ${USER_ACCOUNT}
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN echo 'circlemlir ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN echo 'source /workdir/venv/bin/activate' >> /etc/bash.bashrc
USER ${USER_ACCOUNT}
WORKDIR /home/${USER_ACCOUNT}
CMD ["bash"]