blob: 769e716024087a952f9a1c19cb1360fbc8473bb0 [file] [log] [blame]
James Conroy3c6e9ed2021-11-24 15:17:49 +00001FROM ubuntu:18.04
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +05302ENV TERM linux
3ENV DEBIAN_FRONTEND noninteractive
4
5# Forward system proxy setting
6# ARG proxy
7# ENV http_proxy $proxy
8# ENV https_proxy $proxy
9
10# Basic apt update
11RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends locales ca-certificates && rm -rf /var/lib/apt/lists/*
12
13# Set the locale to en_US.UTF-8, because the Yocto build fails without any locale set.
14RUN locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
15ENV LANG en_US.UTF-8
16ENV LC_ALL en_US.UTF-8
17
18# Again, off the certificare
19RUN echo "check_certificate = off" >> ~/.wgetrc
20RUN echo "[global] \n\
21trusted-host = pypi.python.org \n \
22\t pypi.org \n \
23\t files.pythonhosted.org" >> /etc/pip.conf
24
25# Get basic packages
26RUN apt-get update && apt-get install -y \
27 apparmor \
28 aufs-tools \
29 automake \
30 bash-completion \
31 btrfs-tools \
32 build-essential \
33 cmake \
34 createrepo \
35 curl \
36 dpkg-sig \
37 g++ \
38 gcc \
39 git \
40 iptables \
41 jq \
42 libapparmor-dev \
43 libc6-dev \
44 libcap-dev \
45 libsystemd-dev \
46 libyaml-dev \
47 mercurial \
48 net-tools \
49 parallel \
50 pkg-config \
51 python-dev \
52 python-mock \
53 python-pip \
54 python-setuptools \
55 python-websocket \
56 golang-go \
57 iproute2 \
58 iputils-ping \
59 vim-common \
60 vim \
61 wget \
62 libtool \
63 unzip \
64 scons \
65 curl \
66 autoconf \
67 libtool \
68 build-essential \
James Conroy3aa29852021-12-24 14:46:23 +000069 libssl-dev \
70 g++ && rm -rf /var/lib/apt/lists/*
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +053071
72# Install Cross-compiling ToolChain
73RUN apt-get update && apt-get install -y crossbuild-essential-arm64
74
James Conroy3aa29852021-12-24 14:46:23 +000075# Install Cmake 3.19
76RUN cd $HOME && \
77 wget -O cmake-3.19.0.tar.gz https://cmake.org/files/v3.19/cmake-3.19.0.tar.gz && \
78 tar -xzf cmake-3.19.0.tar.gz && \
79 cd $HOME/cmake-3.19.0 && \
80 ./bootstrap && \
81 make && \
82 make install
83
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +053084# Build and install Google's Protobuf library
85# Download and Extract
86RUN mkdir -p $HOME/google && \
87 cd $HOME/google && \
Keith Mok34b9aba2021-03-18 21:42:16 -070088 wget https://github.com/protocolbuffers/protobuf/releases/download/v3.12.0/protobuf-all-3.12.0.tar.gz && \
89 tar -zxvf protobuf-all-3.12.0.tar.gz
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +053090
91# Build a native (x86_64) version
Keith Mok34b9aba2021-03-18 21:42:16 -070092RUN cd $HOME/google/protobuf-3.12.0 && \
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +053093 mkdir x86_build && cd x86_build && \
94 ../configure --prefix=$HOME/armnn-devenv/google/x86_64_pb_install && \
Keith Mok34b9aba2021-03-18 21:42:16 -070095 make install -j$(nproc)
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +053096
97# Build the arm64 version of the protobuf libraries
Keith Mok34b9aba2021-03-18 21:42:16 -070098RUN cd $HOME/google/protobuf-3.12.0 && \
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +053099 mkdir arm64_build && cd arm64_build && \
100 export CC=aarch64-linux-gnu-gcc && \
101 export CXX=aarch64-linux-gnu-g++ && \
102 ../configure --host=aarch64-linux \
103 --prefix=$HOME/armnn-devenv/google/arm64_pb_install \
104 --with-protoc=$HOME/armnn-devenv/google/x86_64_pb_install/bin/protoc && \
Keith Mok34b9aba2021-03-18 21:42:16 -0700105 make install -j$(nproc)
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530106
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530107# Dep Error - Bug ARMNN
108RUN apt-get update && apt-get install -y \
109 python-numpy
110
111# Setup Env
112# ENV PATH=$HOME/armnn-devenv/google/x86_64_pb_install/bin/:$PATH
113# ENV LD_LIBRARY_PATH=$HOME/armnn-devenv/google/x86_64_pb_install/lib/:$LD_LIBRARY_PATH
114
Keith Mok34b9aba2021-03-18 21:42:16 -0700115# Download ArmNN
James Conroy3c6e9ed2021-11-24 15:17:49 +0000116RUN cd $HOME/armnn-devenv && git clone "https://review.mlplatform.org/ml/armnn" && \
James Conroy3aa29852021-12-24 14:46:23 +0000117 cd armnn && git checkout master
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530118
119# Build Compute Library
Keith Mok34b9aba2021-03-18 21:42:16 -0700120RUN cd $HOME/armnn-devenv/ && git clone https://review.mlplatform.org/ml/ComputeLibrary && \
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530121 cd ComputeLibrary && \
Keith Mok34b9aba2021-03-18 21:42:16 -0700122 git checkout $($HOME/armnn-devenv/armnn/scripts/get_compute_library.sh -p) && \
James Conroy3aa29852021-12-24 14:46:23 +0000123 scons Werror=0 arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags="-fPIC" -j$(nproc)
Keith Mok34b9aba2021-03-18 21:42:16 -0700124
James Conroy3aa29852021-12-24 14:46:23 +0000125# Download Tensorflow (Checkout latest tested version of TF using get_tensorflow.sh)
126RUN cd $HOME/armnn-devenv && \
127 git clone https://github.com/tensorflow/tensorflow.git && \
Keith Mok34b9aba2021-03-18 21:42:16 -0700128 cd tensorflow && \
James Conroy3aa29852021-12-24 14:46:23 +0000129 git checkout $($HOME/armnn-devenv/armnn/scripts/get_tensorflow.sh -p)
Keith Mok34b9aba2021-03-18 21:42:16 -0700130
James Conroy3aa29852021-12-24 14:46:23 +0000131# Build TF Lite
132RUN cd $HOME/armnn-devenv && \
133 curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz && \
134 mkdir tflite-toolchains && \
135 tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C tflite-toolchains && \
136 mkdir -p tflite/build && \
137 cd tflite/build && \
138 ARMCC_PREFIX=$HOME/armnn-devenv/tflite-toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu- && \
139 ARMCC_FLAGS="-funsafe-math-optimizations" && \
140 cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
141 -DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
142 -DCMAKE_C_FLAGS="${ARMCC_FLAGS}" -DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
143 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_SYSTEM_NAME=Linux \
144 -DTFLITE_ENABLE_XNNPACK=OFF \
145 -DCMAKE_SYSTEM_PROCESSOR=aarch64 \
146 $HOME/armnn-devenv/tensorflow/tensorflow/lite/ && \
147 cmake --build .
148
149# Download Flatbuffers
Keith Mok34b9aba2021-03-18 21:42:16 -0700150RUN cd $HOME/armnn-devenv && \
151 wget -O flatbuffers-1.12.0.tar.gz https://github.com/google/flatbuffers/archive/v1.12.0.tar.gz && \
152 tar xf flatbuffers-1.12.0.tar.gz && \
153 cd flatbuffers-1.12.0 && \
154 rm -f CMakeCache.txt
155
James Conroy3aa29852021-12-24 14:46:23 +0000156# Build native x86_64 version of Flatbuffers
Keith Mok34b9aba2021-03-18 21:42:16 -0700157RUN cd $HOME/armnn-devenv && cd flatbuffers-1.12.0 && \
158 mkdir build && \
159 cd build && \
160 cmake .. -DFLATBUFFERS_BUILD_FLATC=1 \
161 -DCMAKE_INSTALL_PREFIX:PATH=$HOME/armnn-devenv/flatbuffers \
162 -DFLATBUFFERS_BUILD_TESTS=0 && \
163 make all install -j$(nproc)
164
James Conroy3aa29852021-12-24 14:46:23 +0000165# Build arm64 version of Flatbuffers
Keith Mok34b9aba2021-03-18 21:42:16 -0700166RUN cd $HOME/armnn-devenv&& cd flatbuffers-1.12.0 && \
167 mkdir build-arm64 && \
168 cd build-arm64 && \
169 CXXFLAGS="-fPIC" cmake .. -DCMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc \
170 -DCMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++ \
171 -DFLATBUFFERS_BUILD_FLATC=1 \
172 -DCMAKE_INSTALL_PREFIX:PATH=$HOME/armnn-devenv/flatbuffers-arm64 \
173 -DFLATBUFFERS_BUILD_TESTS=0 && \
174 make all install -j$(nproc)
175
176# Build onnx
177RUN cd $HOME/armnn-devenv && git clone https://github.com/onnx/onnx.git && \
178 cd onnx && \
179 git fetch https://github.com/onnx/onnx.git 553df22c67bee5f0fe6599cff60f1afc6748c635 && git checkout FETCH_HEAD && \
180 LD_LIBRARY_PATH=$HOME/armnn-devenv/google/x86_64_pb_install/lib:$LD_LIBRARY_PATH \
181 $HOME/armnn-devenv/google/x86_64_pb_install/bin/protoc \
182 onnx/onnx.proto --proto_path=. --proto_path=../google/x86_64_pb_install/include --cpp_out $HOME/armnn-devenv/onnx
183
James Conroy3aa29852021-12-24 14:46:23 +0000184# Generate TF Lite Schema
Keith Mok34b9aba2021-03-18 21:42:16 -0700185RUN cd $HOME/armnn-devenv && \
Keith Mok34b9aba2021-03-18 21:42:16 -0700186 cd tflite && \
187 cp ../tensorflow/tensorflow/lite/schema/schema.fbs . && \
188 ../flatbuffers-1.12.0/build/flatc -c --gen-object-api --reflect-types --reflect-names schema.fbs
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530189
190# Build ArmNN
Keith Mok34b9aba2021-03-18 21:42:16 -0700191RUN cd $HOME/armnn-devenv && \
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530192 cd armnn && mkdir build && cd build && \
193 export CXX=aarch64-linux-gnu-g++ && \
194 export CC=aarch64-linux-gnu-gcc && \
195 cmake .. \
Keith Mok34b9aba2021-03-18 21:42:16 -0700196 -DCMAKE_CXX_FLAGS=-w \
197 -DBUILD_TESTS=1 \
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530198 -DARMCOMPUTE_ROOT=$HOME/armnn-devenv/ComputeLibrary \
199 -DARMCOMPUTE_BUILD_DIR=$HOME/armnn-devenv/ComputeLibrary/build/ \
Jegathesan Shanmugambdba2722020-03-26 22:47:37 +0530200 -DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \
Keith Mok34b9aba2021-03-18 21:42:16 -0700201 -DONNX_GENERATED_SOURCES=$HOME/armnn-devenv/onnx \
202 -DBUILD_ONNX_PARSER=1 \
Keith Mok34b9aba2021-03-18 21:42:16 -0700203 -DBUILD_TF_LITE_PARSER=1 \
James Conroy3aa29852021-12-24 14:46:23 +0000204 -DBUILD_ARMNN_TFLITE_DELEGATE=1 \
205 -DTENSORFLOW_ROOT=$HOME/armnn-devenv/tensorflow \
206 -DTFLITE_LIB_ROOT=$HOME/armnn-devenv/tflite/build \
207 -DTF_LITE_SCHEMA_INCLUDE_PATH=$HOME/armnn-devenv/tflite \
Keith Mok34b9aba2021-03-18 21:42:16 -0700208 -DFLATBUFFERS_ROOT=$HOME/armnn-devenv/flatbuffers-arm64 \
209 -DFLATC_DIR=$HOME/armnn-devenv/flatbuffers-1.12.0/build \
210 -DPROTOBUF_ROOT=$HOME/armnn-devenv/google/x86_64_pb_install \
211 -DPROTOBUF_LIBRARY_DEBUG=$HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so.23.0.0 \
212 -DPROTOBUF_LIBRARY_RELEASE=$HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so.23.0.0 && \
213 make -j$(nproc)