Skip to content

Commit 287597b

Browse files
authored
[CI] Update ci_minimal docker image to cross-compile TVM to aarch64 (#13776)
This PR is a prerequisite to #13714 and needs to be merged before. It contains the changes to the ci_minimal docker image to support minimal cross-compilation of TVM to aarch64.
1 parent 5878f60 commit 287597b

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

docker/Dockerfile.ci_minimal

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ RUN bash /install/ubuntu_setup_tz.sh
2828
COPY install/ubuntu_install_core.sh /install/ubuntu_install_core.sh
2929
RUN bash /install/ubuntu_install_core.sh
3030

31+
# Install libraries for cross-compiling TVM to Aarch64
32+
COPY install/ubuntu1804_install_aarch64_cross_compile.sh /install/ubuntu1804_install_aarch64_cross_compile.sh
33+
RUN bash /install/ubuntu1804_install_aarch64_cross_compile.sh
34+
3135
COPY install/ubuntu_install_cmake_source.sh /install/ubuntu_install_cmake_source.sh
3236
RUN bash /install/ubuntu_install_cmake_source.sh
3337

@@ -47,6 +51,10 @@ RUN bash /install/ubuntu_install_python_package.sh
4751
COPY install/ubuntu1804_manual_install_llvm.sh /install/ubuntu1804_manual_install_llvm.sh
4852
RUN bash /install/ubuntu1804_manual_install_llvm.sh
4953

54+
# Cross build LLVM to Aarch64
55+
COPY install/ubuntu1804_manual_install_llvm_cross_aarch64.sh /install/ubuntu1804_manual_install_llvm_cross_aarch64.sh
56+
RUN bash /install/ubuntu1804_manual_install_llvm_cross_aarch64.sh
57+
5058
# Rust env (build early; takes a while)
5159
COPY install/ubuntu_install_rust.sh /install/ubuntu_install_rust.sh
5260
RUN bash /install/ubuntu_install_rust.sh
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
set -e
20+
set -u
21+
# Used for debugging RVM build
22+
set -x
23+
set -o pipefail
24+
25+
architecture_type=$(uname -i)
26+
if [ "$architecture_type" != "aarch64" ]; then
27+
# Install gcc and g++ for cross-compiling c++ on ubuntu
28+
apt-get update && apt-install-and-clear -y --no-install-recommends \
29+
g++-aarch64-linux-gnu \
30+
gcc-aarch64-linux-gnu \
31+
32+
# Add Aarch64 packages to the apt sources list
33+
echo >> /etc/apt/sources.list.d/arm64.list
34+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic main restricted" >> /etc/apt/sources.list.d/arm64.list
35+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic-updates main restricted" >> /etc/apt/sources.list.d/arm64.list
36+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic universe" >> /etc/apt/sources.list.d/arm64.list
37+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic-updates universe" >> /etc/apt/sources.list.d/arm64.list
38+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic multiverse" >> /etc/apt/sources.list.d/arm64.list
39+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic-updates multiverse" >> /etc/apt/sources.list.d/arm64.list
40+
echo "deb [arch=arm64] http://ports.ubuntu.com/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list.d/arm64.list
41+
42+
# Fix apt-get update by specifying the amd64 architecture in sources.list
43+
sed -i -e 's/deb /deb [arch=amd64] /g' /etc/apt/sources.list
44+
45+
# Install the required packages for cross-compiling
46+
dpkg --add-architecture arm64
47+
apt-get update && apt-install-and-clear -y --no-install-recommends \
48+
zlib1g-dev:arm64 \
49+
libtinfo-dev:arm64
50+
51+
fi
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
set -e
20+
set -u
21+
set -o pipefail
22+
23+
architecture_type=$(uname -i)
24+
# Cross-build LLVM for aarch64 when not building natively.
25+
if [ "$architecture_type" != "aarch64" ]; then
26+
git clone --depth 1 --branch release/11.x https://github.com/llvm/llvm-project.git
27+
pushd llvm-project
28+
29+
# First build clang-tblgen and llvm-tblgen
30+
mkdir build-host
31+
pushd build-host
32+
cmake \
33+
-G Ninja \
34+
-DCMAKE_BUILD_TYPE=Release \
35+
-DLLVM_ENABLE_ASSERTIONS=ON \
36+
-DLLVM_ENABLE_PROJECTS="llvm;clang;clang-tools-extra" \
37+
../llvm
38+
ninja clang-tblgen llvm-tblgen
39+
popd
40+
41+
# Then cross-compile LLVM for Aarch64
42+
mkdir build
43+
pushd build
44+
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ cmake \
45+
-G Ninja \
46+
-DCMAKE_BUILD_TYPE=Release \
47+
-DCMAKE_INSTALL_PREFIX=/usr/llvm-aarch64 \
48+
-DLLVM_ENABLE_ASSERTIONS=ON \
49+
-DLLVM_ENABLE_PROJECTS="llvm;clang" \
50+
-DCMAKE_SYSTEM_NAME=Linux \
51+
-DLLVM_TABLEGEN=/llvm-project/build-host/bin/llvm-tblgen \
52+
-DCLANG_TABLEGEN=/llvm-project/build-host/bin/clang-tblgen \
53+
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu \
54+
-DLLVM_TARGET_ARCH=AArch64 \
55+
-DCMAKE_CXX_FLAGS='-march=armv8-a -mtune=cortex-a72' \
56+
../llvm
57+
ninja install
58+
popd
59+
popd
60+
rm -rf llvm-project
61+
62+
# This is a hack. Cross-compiling LLVM with gcc will cause the llvm-config to be an Aarch64 executable.
63+
# We need it to be x86 to be able to call it when building TVM. We just copy and use the x86 one instead.
64+
cp /usr/bin/llvm-config /usr/llvm-aarch64/bin/llvm-config
65+
fi

0 commit comments

Comments
 (0)