Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit b1dd13c

Browse files
committed
Greatly simplify qemu setup
1 parent 36c87c3 commit b1dd13c

26 files changed

+108
-1038
lines changed

ci/README.md

Lines changed: 21 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -111,90 +111,37 @@ significantly. You can set this directory explicitly by setting CCACHE_DIR envir
111111
variable. All ccache instances are currently set to be 10 Gigabytes max in size.
112112

113113

114-
## Testing with QEMU
115-
To run the unit tests under qemu:
116-
```
117-
./build.py -p armv7 && ./build.py -p test.arm_qemu ./runtime_functions.py run_ut_py3_qemu
118-
```
119-
120-
To get a shell on the container and debug issues with the emulator itself, we build the container
121-
and then execute it interactively. We can afterwards use port 2222 on the host to connect with SSH.
122-
123-
124-
```
125-
ci/build.py -p test.arm_qemu -b && docker run -p2222:2222 -ti mxnetci/build.test.arm_qemu
126-
```
114+
## Testing with ARM / Edge devices with QEMU
127115

128-
Then from another terminal:
116+
We build on [QEMU](https://www.qemu.org/) and Linux [Kernel Support for
117+
miscellaneous Binary
118+
Formats](https://www.kernel.org/doc/html/v5.6/admin-guide/binfmt-misc.html) for
119+
testing MXNet on edge devices. Test can be invoked with the same syntax as for
120+
non-virtualized platforms:
129121

130122
```
131-
ssh -o StrictHostKeyChecking=no -p 2222 qemu@localhost
123+
./build.py -p armv7
124+
./build.py -p test.armv7 /work/runtime_functions.sh unittest_ubuntu_python3_armv7
132125
```
133126

134-
There are two pre-configured users: `root` and `qemu` both without passwords.
135-
136-
137-
### Example of reproducing a test result with QEMU on ARM
138-
139-
140-
You might want to enable a debug build first:
141-
142-
```
143-
$ git diff
144-
diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh
145-
index 39631f9..666ceea 100755
146-
--- a/ci/docker/runtime_functions.sh
147-
+++ b/ci/docker/runtime_functions.sh
148-
@@ -172,6 +172,7 @@ build_armv7() {
149-
-DUSE_LAPACK=OFF \
150-
-DBUILD_CPP_EXAMPLES=OFF \
151-
-Dmxnet_LINKER_LIBS=-lgfortran \
152-
+ -DCMAKE_BUILD_TYPE=Debug \
153-
-G Ninja /work/mxnet
154-
155-
ninja -v
127+
For the test step to succeed, you must run Linux kernel 4.8 or later and have qemu installed.
156128

129+
On Debian and Ubuntu systems, run the following command to install the dependencies:
157130
```
131+
sudo apt install binfmt-support qemu-user-static
158132
159-
Then we build the project for armv7, the test container and start QEMU inside docker:
160-
161-
```
162-
ci/build.py -p armv7
163-
ci/build.py -p test.arm_qemu -b && docker run -p2222:2222 -ti mxnetci/build.test.arm_qemu
133+
# Use qemu-binfmt-conf.sh to register all binary types with the kernel
134+
wget https://raw.githubusercontent.com/qemu/qemu/stable-4.1/scripts/qemu-binfmt-conf.sh
135+
chmod +x qemu-binfmt-conf.sh
136+
sudo ./qemu-binfmt-conf.sh --persistent yes --qemu-suffix "-static" --qemu-path "/usr/bin" --systemd ALL
164137
```
165138

166-
167-
168-
At this point we copy artifacts and sources to the VM, in another terminal (host) do the following:
139+
If you run into segmentation faults at the beginning of the emulated tests, you
140+
probably have a ancient version of Qemu on your system (or found a bug in
141+
upstream Qemu). In that situation, you can rely on the
142+
`multiarch/qemu-user-static` Docker project to register a set of up-to-date Qemu
143+
binaries from their Docker image with your kernel:
169144

170145
```
171-
# Copy mxnet sources to the VM
172-
rsync --delete -e 'ssh -p2222' --exclude='.git/' -zvaP ./ qemu@localhost:mxnet
173-
174-
175-
# Ssh into the vm
176-
ssh -p2222 qemu@localhost
177-
178-
cd mxnet
179-
180-
# Execute a single failing C++ test
181-
build/tests/mxnet_unit_tests --gtest_filter="ACTIVATION_PERF.ExecuteBidirectional"
182-
183-
# To install MXNet:
184-
sudo pip3 install --upgrade --force-reinstall build/mxnet-1.3.1-py2.py3-none-any.whl
185-
186-
# Execute a single python test:
187-
188-
nosetests-3.4 -v -s tests/python/unittest/test_ndarray.py
189-
190-
191-
# Debug with cgdb
192-
sudo apt install -y libstdc++6-6-dbg
193-
cgdb build/tests/mxnet_unit_tests
194-
195-
(gdb) !pwd
196-
/home/qemu/mxnet
197-
(gdb) set substitute-path /work /home/qemu
198-
(gdb) set substitute-path /build/gcc-6-6mK9AW/gcc-6-6.3.0/build/arm-linux-gnueabihf/libstdc++-v3/include/ /usr/include/c++/6/
199-
(gdb) r --gtest_filter="ACTIVATION_PERF.ExecuteBidirectional"
146+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
200147
```

ci/dev_menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def provision_virtualenv(venv_path=DEFAULT_PYENV):
167167
('[Docker] Python3 ARMv7 unittests (QEMU)',
168168
[
169169
"ci/build.py -p armv7",
170-
"ci/build.py -p test.arm_qemu ./runtime_functions.py run_ut_py3_qemu"
170+
"ci/build.py -p test.armv7 /work/runtime_functions.sh unittest_ubuntu_python3_armv7"
171171
]),
172172
('Clean (RESET HARD) repository (Warning! erases local changes / DATA LOSS)',
173173
Confirm("ci/docker/runtime_functions.sh clean_repo"))

ci/docker/Dockerfile.build.android_armv7

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ RUN git clone --recursive -b v0.3.9 https://github.com/xianyi/OpenBLAS.git && \
4646
mkdir /usr/local/openblas-android && \
4747
cd /usr/local/OpenBLAS && \
4848
export TOOLCHAIN=/usr/local/android-ndk-r19/toolchains/llvm/prebuilt/linux-x86_64 && \
49-
make NOFORTRAN=1 ARM_SOFTFP_ABI=1 \
49+
make NOFORTRAN=1 ARM_SOFTFP_ABI=1 NO_SHARED=1 \
5050
LDFLAGS="-L/usr/local/android-ndk-r19/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -lm" \
5151
CC=$TOOLCHAIN/bin/armv7a-linux-androideabi16-clang AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar && \
52-
make PREFIX=/usr/local/openblas-android install && \
52+
make PREFIX=/usr/local/openblas-android NO_SHARED=1 install && \
5353
cd /usr/local && \
5454
rm -rf OpenBLAS
5555
ENV OpenBLAS_HOME=/usr/local/openblas-android

ci/docker/Dockerfile.build.android_armv8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ RUN git clone --recursive -b v0.3.9 https://github.com/xianyi/OpenBLAS.git && \
4646
mkdir /usr/local/openblas-android && \
4747
cd /usr/local/OpenBLAS && \
4848
export TOOLCHAIN=/usr/local/android-ndk-r19/toolchains/llvm/prebuilt/linux-x86_64 && \
49-
make NOFORTRAN=1 \
49+
make NOFORTRAN=1 NO_SHARED=1 \
5050
LDFLAGS="-L/usr/local/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x -lm" \
5151
CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang AR=$TOOLCHAIN/bin/aarch64-linux-android-ar && \
52-
make PREFIX=/usr/local/openblas-android install && \
52+
make PREFIX=/usr/local/openblas-android NO_SHARED=1 install && \
5353
cd /usr/local && \
5454
rm -rf OpenBLAS
5555
ENV OpenBLAS_HOME=/usr/local/openblas-android

ci/docker/Dockerfile.build.armv6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ENV CMAKE_TOOLCHAIN_FILE=/usr/local/armv6-eabihf--glibc--stable-2020.02-2/share/
5050

5151
RUN git clone --recursive -b v0.3.9 https://github.com/xianyi/OpenBLAS.git && \
5252
cd /usr/local/OpenBLAS && \
53-
make NOFORTRAN=1 CC=/usr/local/armv6-eabihf--glibc--stable-2020.02-2/bin/arm-linux-gcc && \
54-
make PREFIX=/usr/local/armv6-eabihf--glibc--stable-2020.02-2/arm-buildroot-linux-gnueabihf/sysroot install && \
53+
make NOFORTRAN=1 NO_SHARED=1 CC=/usr/local/armv6-eabihf--glibc--stable-2020.02-2/bin/arm-linux-gcc && \
54+
make PREFIX=/usr/local/armv6-eabihf--glibc--stable-2020.02-2/arm-buildroot-linux-gnueabihf/sysroot NO_SHARED=1 install && \
5555
cd /usr/local && \
5656
rm -rf OpenBLAS
5757

ci/docker/Dockerfile.build.armv7

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ENV CMAKE_TOOLCHAIN_FILE=/usr/local/arm-linux-gnueabihf-toolchain.cmake
4545

4646
RUN git clone --recursive -b v0.3.9 https://github.com/xianyi/OpenBLAS.git && \
4747
cd /usr/local/OpenBLAS && \
48-
make NOFORTRAN=1 CC=arm-linux-gnueabihf-gcc && \
49-
make PREFIX=/usr/local/arm-linux-gnueabihf install && \
48+
make NOFORTRAN=1 NO_SHARED=1 CC=arm-linux-gnueabihf-gcc && \
49+
make PREFIX=/usr/local/arm-linux-gnueabihf NO_SHARED=1 install && \
5050
cd /usr/local && \
5151
rm -rf OpenBLAS
5252

ci/docker/Dockerfile.build.armv8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ENV CMAKE_TOOLCHAIN_FILE=/usr/aarch64-linux-gnu-toolchain.cmake
4545

4646
RUN git clone --recursive -b v0.3.9 https://github.com/xianyi/OpenBLAS.git && \
4747
cd /usr/local/OpenBLAS && \
48-
make NOFORTRAN=1 CC=aarch64-linux-gnu-gcc && \
49-
make PREFIX=/usr/aarch64-linux-gnu install && \
48+
make NOFORTRAN=1 NO_SHARED=1 CC=aarch64-linux-gnu-gcc && \
49+
make PREFIX=/usr/aarch64-linux-gnu NO_SHARED=1 install && \
5050
cd /usr/local && \
5151
rm -rf OpenBLAS
5252

ci/docker/Dockerfile.build.test.arm_qemu renamed to ci/docker/Dockerfile.build.test.armv7

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,26 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
#
19-
# Dockerfile to build and run MXNet on Ubuntu 16.04 for CPU
19+
# Dockerfile to test MXNet on Ubuntu 20.04 ARMv7 CPU
2020

21-
FROM ubuntu:16.04
21+
FROM arm32v7/ubuntu:20.04
2222

23-
WORKDIR /work
23+
WORKDIR /usr/local
2424

25-
RUN apt-get update
26-
COPY install/ubuntu_python.sh /work/
27-
COPY install/requirements /work/
28-
RUN /work/ubuntu_python.sh
29-
30-
COPY install/ubuntu_arm_qemu.sh /work
31-
RUN /work/ubuntu_arm_qemu.sh
32-
33-
COPY install/ubuntu_arm_qemu_bin.sh /work
34-
RUN /work/ubuntu_arm_qemu_bin.sh
25+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
26+
python3 \
27+
python3-pip \
28+
python3-numpy \
29+
python3-scipy \
30+
python3-nose \
31+
python3-nose-timer \
32+
python3-requests \
33+
&& rm -rf /var/lib/apt/lists/*
3534

3635
ARG USER_ID=0
3736
ARG GROUP_ID=0
3837
COPY install/ubuntu_adduser.sh /work/
3938
RUN /work/ubuntu_adduser.sh
4039

4140
COPY runtime_functions.sh /work/
42-
COPY qemu/* /work/
43-
44-
# SSH to the Qemu VM
45-
EXPOSE 2222/tcp
46-
47-
CMD ["./runtime_functions.py","run_qemu_interactive"]
41+
WORKDIR /work/mxnet
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/usr/bin/env bash
2-
1+
# -*- mode: dockerfile -*-
32
# Licensed to the Apache Software Foundation (ASF) under one
43
# or more contributor license agreements. See the NOTICE file
54
# distributed with this work for additional information
@@ -16,22 +15,27 @@
1615
# KIND, either express or implied. See the License for the
1716
# specific language governing permissions and limitations
1817
# under the License.
18+
#
19+
# Dockerfile to test MXNet on Ubuntu 20.04 ARMv8 CPU
20+
21+
FROM arm64v8/ubuntu:20.04
1922

20-
# build and install are separated so changes to build don't invalidate
21-
# the whole docker cache for the image
23+
WORKDIR /usr/local
2224

23-
set -exuo pipefail
25+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
26+
python3 \
27+
python3-pip \
28+
python3-numpy \
29+
python3-scipy \
30+
python3-nose \
31+
python3-nose-timer \
32+
python3-requests \
33+
&& rm -rf /var/lib/apt/lists/*
2434

25-
apt-get install -y \
26-
cmake \
27-
curl \
28-
wget \
29-
git \
30-
qemu \
31-
qemu-system-arm \
32-
unzip \
33-
bzip2 \
34-
vim-nox \
35-
toilet
35+
ARG USER_ID=0
36+
ARG GROUP_ID=0
37+
COPY install/ubuntu_adduser.sh /work/
38+
RUN /work/ubuntu_adduser.sh
3639

37-
pip3 install ipython
40+
COPY runtime_functions.sh /work/
41+
WORKDIR /work/mxnet

ci/docker/install/ubuntu_arm_qemu_bin.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

ci/docker/qemu/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)