Building aarch64 compatible pip package
utexasnew opened this issue · 13 comments
I have followed the instructions located in the docs: https://docs.larq.dev/compute-engine/build/docker/ to build a manylinux2010 compatible pip package.
My question is now how to build the pip package for aarch64 systems? I have tried a simple addition of --config=aarch64 to the bazel build command but that was unsuccessful. Any guidance will surely be appreciated.
Hi @utexasnew ,
We currently don't support aarch64 builds of our converter package.
In theory, adding --config=aarch64
to bazel build build_pip_pkg
should do the trick, but when I try to do this locally then I get compile errors for some llvm-related files that are part of the tensorflow converter. This is not something we can easily fix because these errors are not caused by 'our' files.
If you are only looking to compile the python interpreter tool (and not the converter) then you might be able to get it to work by removing these lines:
compute-engine/larq_compute_engine/BUILD
Line 24 in 48bb86b
and remove "convert_saved_model" from this line:
Finally, remove the ${TMPDIR}/larq_compute_engine/mlir/*.so
part of both of these lines (but leave the ${TMPDIR}/larq_compute_engine/tflite/python/*.so
part):
compute-engine/build_pip_pkg.sh
Lines 80 to 81 in 48bb86b
This way you should get a package that only contains the python interpreter without the converter.
When running the build_pip_pkg
script (after bazel has completed) you have to add --plat=linux_aarch64
as an argument:
bazel-bin/build_pip_pkg artifacts --plat=linux_aarch64
You might have to update the pip packages setuptools
and/or wheel
to the latest version to get support for this --plat
flag.
Hi @Tombana
I tried to cross compile the python interpreter tool to work on raspberrypi 4 running on ubuntu 20.04 (aarch64) but i am always getting errors.
os used for compilation : ubuntu 20.04.2 LTS (x86_64)
target os : raspberrypi 4 running ubuntu 20.04.2 (aarch64)
python version: 3.8.10
type of error : fatal error: aarch64-linux-gnu/python3.8/pyconfig.h: No such file or directory
Btw i did all the steps that you have mentioned and always the same error. I will be grateful if you or anyone else can help me solve this or maybe just share the wheel file for aarch64. I just need it for inference.
You can try to install a package on your system that provides that missing Python header file. You can use apt-file
for that (see https://askubuntu.com/a/1912 for instructions) and then install it (e.g. `apt install libpython3.8-dev), e.g.:
$ apt-file search pyconfig.h
libpython2.7-dbg: /usr/include/aarch64-linux-gnu/python2.7_d/pyconfig.h
libpython2.7-dbg: /usr/include/python2.7_d/pyconfig.h
libpython2.7-dev: /usr/include/aarch64-linux-gnu/python2.7/pyconfig.h
libpython2.7-dev: /usr/include/python2.7/pyconfig.h
libpython3.7-dbg: /usr/include/aarch64-linux-gnu/python3.7dm/pyconfig.h
libpython3.7-dbg: /usr/include/python3.7dm/pyconfig.h
libpython3.7-dev: /usr/include/aarch64-linux-gnu/python3.7m/pyconfig.h
libpython3.7-dev: /usr/include/python3.7m/pyconfig.h
(...)
However it seems on my test system there is no such Python 3.8 package available. If you can't manage to install the required package, you can try to manually download the file (e.g. from here) and place it in the right location, but I'm not sure if you'll run into other errors later on then.
Thank you @CNugteren, I ended up installing the same python version on the raspberry pi and then I copied the aarch64-linux-gnu folder to the Linux computer. By doing that, I was able to build successfully.
Unfortunately, when I tried to build the pip package then, I came across an error, I really can't identify it's origins. I don't know if it is something related to the build or something else.
Here is the log:
Build log:
$ bazel build :build_pip_pkg --config=aarch64
Target //:build_pip_pkg up-to-date:
bazel-bin/build_pip_pkg
INFO: Elapsed time: 630.677s, Critical Path: 122.83s
INFO: 499 processes: 179 internal, 320 local.
INFO: Build completed successfully, 499 total actions
pip Package build:
$ bazel-bin/build_pip_pkg artifacts
++ uname -s
++ tr A-Z a-z
+ PLATFORM=linux
+ is_windows
+ [[ linux =~ msys_nt*|mingw*|cygwin*|uwin* ]]
+ PIP_FILE_PREFIX=bazel-bin/build_pip_pkg.runfiles/larq_compute_engine/
+ main artifacts
+ DEST=artifacts
+ BUILD_FLAG=
+ [[ -z artifacts ]]
+ mkdir -p artifacts
++ abspath artifacts
+++ dirname artifacts
++ cd .
+++ basename artifacts
++ echo /home/gtounsi/Desktop/compute-engine/artifacts
++ cd /home/gtounsi/Desktop/compute-engine
+ DEST=/home/gtounsi/Desktop/compute-engine/artifacts
+ echo '=== destination directory: /home/gtounsi/Desktop/compute-engine/artifacts'
=== destination directory: /home/gtounsi/Desktop/compute-engine/artifacts
++ mktemp -d -t tmp.XXXXXXXXXX
+ TMPDIR=/tmp/tmp.UyTI0WPySF
++ date
+ echo Wed 18 Aug 2021 09:17:22 AM CET : '=== Using tmpdir: /tmp/tmp.UyTI0WPySF'
Wed 18 Aug 2021 09:17:22 AM CET : === Using tmpdir: /tmp/tmp.UyTI0WPySF
+ echo '=== Copy Larq Compute Engine files'
=== Copy Larq Compute Engine files
+ cp bazel-bin/build_pip_pkg.runfiles/larq_compute_engine/setup.py /tmp/tmp.UyTI0WPySF
+ cp bazel-bin/build_pip_pkg.runfiles/larq_compute_engine/MANIFEST.in /tmp/tmp.UyTI0WPySF
+ cp bazel-bin/build_pip_pkg.runfiles/larq_compute_engine/README.md /tmp/tmp.UyTI0WPySF
+ cp bazel-bin/build_pip_pkg.runfiles/larq_compute_engine/LICENSE /tmp/tmp.UyTI0WPySF
+ is_linux
+ [[ linux == \l\i\n\u\x ]]
+ touch /tmp/tmp.UyTI0WPySF/stub.cc
+ is_windows
+ [[ linux =~ msys_nt*|mingw*|cygwin*|uwin* ]]
+ rsync -avm -L '--exclude=*_test.py' bazel-bin/build_pip_pkg.runfiles/larq_compute_engine/larq_compute_engine
/tmp/tmp.UyTI0WPySF
building file list ... done
larq_compute_engine/
larq_compute_engine/__init__.py
larq_compute_engine/mlir/
larq_compute_engine/mlir/__init__.py
larq_compute_engine/mlir/python/
larq_compute_engine/mlir/python/__init__.py
larq_compute_engine/tflite/
larq_compute_engine/tflite/__init__.py
larq_compute_engine/tflite/python/
larq_compute_engine/tflite/python/__init__.py
larq_compute_engine/tflite/python/interpreter.py
larq_compute_engine/tflite/python/interpreter_base.py
larq_compute_engine/tflite/python/interpreter_wrapper_lite.so
sent 2,520,971 bytes received 183 bytes 5,042,308.00 bytes/sec
total size is 2,519,573 speedup is 1.00
+ pushd /tmp/tmp.UyTI0WPySF
/tmp/tmp.UyTI0WPySF ~/Desktop/compute-engine
+ is_windows
+ [[ linux =~ msys_nt*|mingw*|cygwin*|uwin* ]]
+ echo '=== Stripping symbols'
=== Stripping symbols
+ chmod +w '/tmp/tmp.UyTI0WPySF/larq_compute_engine/mlir/*.so'
/tmp/tmp.UyTI0WPySF/larq_compute_engine/tflite/python/interpreter_wrapper_lite.so
chmod: cannot access '/tmp/tmp.UyTI0WPySF/larq_compute_engine/mlir/*.so': No such file or directory
Here is the log:
pip Package build:
$ bazel-bin/build_pip_pkg artifacts ... chmod: cannot access '/tmp/tmp.UyTI0WPySF/larq_compute_engine/mlir/*.so': No such file or directory
On line 80 and 81 of build_pip_pkg.sh
(in the root of the repository), there is this:
chmod +w ${TMPDIR}/larq_compute_engine/mlir/*.so ${TMPDIR}/larq_compute_engine/tflite/python/*.so
strip -x ${TMPDIR}/larq_compute_engine/mlir/*.so ${TMPDIR}/larq_compute_engine/tflite/python/*.so
Could you try to remove the mlir/*.so
parts:
chmod +w ${TMPDIR}/larq_compute_engine/tflite/python/*.so
strip -x ${TMPDIR}/larq_compute_engine/tflite/python/*.so
I'll update the original answer with these instructions.
Here is the log:
pip Package build:$ bazel-bin/build_pip_pkg artifacts ... chmod: cannot access '/tmp/tmp.UyTI0WPySF/larq_compute_engine/mlir/*.so': No such file or directory
On line 80 and 81 of
build_pip_pkg.sh
(in the root of the repository), there is this:chmod +w ${TMPDIR}/larq_compute_engine/mlir/*.so ${TMPDIR}/larq_compute_engine/tflite/python/*.so strip -x ${TMPDIR}/larq_compute_engine/mlir/*.so ${TMPDIR}/larq_compute_engine/tflite/python/*.soCould you try to remove the
mlir/*.so
parts:chmod +w ${TMPDIR}/larq_compute_engine/tflite/python/*.so strip -x ${TMPDIR}/larq_compute_engine/tflite/python/*.soI'll update the original answer with these instructions.
That finally worked, I am able to build the .whl file now.
But another problem happened (I don't why it going on with me really :'( ) when I tried to install the file on the raspberry pi I got this error: ERROR: larq_compute_engine-0.6.1-cp38-cp38-linux_x86_64.whl is not a supported wheel on this platform.
and I am sure that I used the --config=aarch64 when running Bazel build build_pip_package.
Thank you very much @Tombana
ERROR: larq_compute_engine-0.6.1-cp38-cp38-linux_x86_64.whl is not a supported wheel on this platform.
and I am sure that I used the --config=aarch64 when running Bazel build build_pip_package.
Thank you very much @Tombana
Can you try to add the following --plat
flag to build_pip_pkg
?
bazel-bin/build_pip_pkg artifacts --plat=linux_aarch64
I'll also add this to the instructions in the original answer.
ERROR: larq_compute_engine-0.6.1-cp38-cp38-linux_x86_64.whl is not a supported wheel on this platform.
and I am sure that I used the --config=aarch64 when running Bazel build build_pip_package.
Thank you very much @TombanaCan you try to add the following
--plat
flag tobuild_pip_pkg
?bazel-bin/build_pip_pkg artifacts --plat=linux_aarch64I'll also add this to the instructions in the original answer.
That finally worked!! Thank you very much for your help and time
- echo '=== Stripping symbols'
=== Stripping symbols - chmod +w /tmp/tmp.CpwDPt4SXi/larq_compute_engine/tflite/python/interpreter_wrapper_lite.so
- strip -x /tmp/tmp.CpwDPt4SXi/larq_compute_engine/tflite/python/interpreter_wrapper_lite.so
strip: Unable to recognise the format of the input file `/tmp/tmp.CpwDPt4SXi/larq_compute_engine/tflite/python/interpreter_wrapper_lite.so'
I am getting this issue even after removinbg .mlir lines from build_pip_pkg.sh file. can someone help me with this?
I think it's using the strip
tool from your host system instead of the crosscompiler toolchain.
Can you try removing that strip -x
line from build_pip_pkg.sh
?
I think it's using the
strip
tool from your host system instead of the crosscompiler toolchain. Can you try removing thatstrip -x
line frombuild_pip_pkg.sh
?
yeah thats working now but as per my observation from other issue....cant we perform inference using this pip package in Raspbian OS? do we have to install other os?
Hello, can someone tell me if there is any way to benchmark the lce model on int8? when we use provided executable then is it for float 32 or int8? and is its float32, which i assume looking at the padding being multiples of 32 then how can we benchmark for float32?
Thank in advance @Tombana
The benchmark executable should support both float and int8 layers.