Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Raspberry Pi #aarch64 cross-compile instructions #30716

Closed
marianopeck opened this issue Jul 15, 2019 · 13 comments
Closed

Provide Raspberry Pi #aarch64 cross-compile instructions #30716

marianopeck opened this issue Jul 15, 2019 · 13 comments
Assignees
Labels
comp:lite TF Lite related issues subtype: raspberry pi Raspberry Pi Build/Installation Issues TF 1.13 Issues related to TF 1.13 type:build/install Build and install issues

Comments

@marianopeck
Copy link

marianopeck commented Jul 15, 2019

System information

  • TensorFlow version (you are using): 1.13.1
  • Are you willing to contribute it (Yes/No): yes, at least as a tester

Describe the feature and the current behavior/state.

There is no pre-build binary for Raspberry Pi / ARM and the instructions to build from scratch here. However, there is nothing for any kind of SBC (like Raspberry Pi, ODroid, Pine64, etc) with a aarch64 architecture.

I cannot use the Python wheel. I need the C library to bind to a different language.

Will this change the current api? How?

No.

Who will benefit with this feature?

Anyone using a SBC with a aarch64 OS.

@eduardofv
Copy link

Haven't tried this myself, but you can find here how to install using pip directly on the Raspberry Pi

@marianopeck
Copy link
Author

That would only work for installing the Python wheel. I need the C library to bind via FFI to other languages (like Go, Rust, etc)

@freedomtan
Copy link
Contributor

Not sure about 1.13.1, For 1.14 or master branch, Something like

bazel --host_jvm_args=-Xms128m --host_jvm_args=-Xmx2048m \
build --config opt --local_resources 1024,1,1 \
tensorflow/tools/lib_package:libtensorflow

should just work. I think I upstreamed necessary patches for

bazel --host_jvm_args=-Xms128m --host_jvm_args=-Xmx2048m \
build --config opt --local_resources 1024,1,1 \
tensorflow/tools/pip_package:build_pip_package

Raspbian 32-bit is a bit complicated, because for RPI 3, an AAarch64 platform, it runs aarch32 (armv7-a) kernel, armv6 user-level binaries, and compilers/toolchains configured to armv6.

@ravikyram ravikyram self-assigned this Jul 16, 2019
@ravikyram ravikyram added TF 1.13 Issues related to TF 1.13 comp:lite TF Lite related issues subtype: raspberry pi Raspberry Pi Build/Installation Issues type:build/install Build and install issues stat:awaiting response Status - Awaiting response from author labels Jul 16, 2019
@marianopeck
Copy link
Author

Hi @freedomtan
Thanks for your response. But there is something I am not sure I understand. The link I pasted above (in my original post) is a way for cross compiling for Raspberry Pi. Doing something as simple as:

      tensorflow/tools/ci_build/ci_build.sh PI \
      tensorflow/tools/ci_build/pi/build_raspberry_pi.sh

If you see here you can see all the magic. Cross compiling is much easier and faster than compiling on the Pi.

I have many images running 64 bits OS on a Pi 3 and 4 (Armiban, Ubuntu Server 18.04, etc)... In addition, an aarch64 build would also help other similar SBC like Pine64, Odriod etc..

What I was proposing is a similar build_raspberry_pi.sh but that would allow me to cross-compile for aarch64.

Thoughts?

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Jul 16, 2019
@freedomtan
Copy link
Contributor

Yes, cross-compiling usually is much faster, esp. for a fresh build. Easier, I don't think so. As I said, the environments before RPi 4 is quite complex.

@marianopeck marianopeck changed the title Provide Raspberry Pi #aarch64 compile instructions Provide Raspberry Pi #aarch64 cross-compile instructions Jul 17, 2019
@ravikyram ravikyram assigned gunan and unassigned ravikyram Jul 17, 2019
@ravikyram ravikyram added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jul 17, 2019
@marianopeck
Copy link
Author

Thanks @freedomtan for all your help.
I finally took the time to write down everything I found during my attempt to get TensorFlow C library compiled for Raspberry Pi. In that tutorial, I point back to this issue in case any progress is done.
Thank you

@lgeiger
Copy link
Contributor

lgeiger commented Apr 9, 2020

I added an AArch64 toolchain to bazel in #38399 which should make cross-compiling a lot easier. It would be great if the PR could get a review.

@terryheo terryheo self-assigned this Apr 27, 2020
@terryheo
Copy link
Member

There are commands to build Python PIP wheel for aarch64.
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/pip_package

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@terryheo terryheo reopened this Jul 23, 2020
@terryheo
Copy link
Member

Oh we need a guide to build full Tensorflow package. Let me check it.

@tensorflowbutler tensorflowbutler removed the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jul 25, 2020
tensorflow-copybara pushed a commit that referenced this issue Jul 25, 2020
- Simplify build commands with only container name without providing environment variables.
- Add Python 3.8 support.
- Update build_raspberry_pi.sh to build generate aarch64 binary.

[Python 3.8 PIP package for ARM64]
The following command is used to build Python 3.8 PIP package for aarch64.
$ tensorflow/tools/ci_build/ci_build.sh PI-PYTHON38 \
    tensorflow/tools/ci_build/pi/build_raspberry_pi.sh AARCH64

[Test on Ubuntu 20.04 ARM64]
I've tested the PIP package on Ubuntu 20.04 64bit with RPI4.
There was an issue on installing h5py on Ubuntu 20.04. The following command
was needed to install h5py package.
$ HDF5_DIR=/usr/lib/aarch64-linux-gnu/hdf5/serial CC=h5cc pip3 install h5py

This PR handles #30716 issue.

PiperOrigin-RevId: 323111228
Change-Id: I408149305a082afe105215fc380f602961b2fdf0
@terryheo
Copy link
Member

You can build TF Python wheel for aarch64.
https://www.tensorflow.org/install/source_rpi#python-3.8-64bit

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@Yasin40
Copy link

Yasin40 commented Aug 12, 2020

Hi @freedomtan
Thanks for your response. But there is something I am not sure I understand. The link I pasted above (in my original post) is a way for cross compiling for Raspberry Pi. Doing something as simple as:

      tensorflow/tools/ci_build/ci_build.sh PI \
      tensorflow/tools/ci_build/pi/build_raspberry_pi.sh

If you see here you can see all the magic. Cross compiling is much easier and faster than compiling on the Pi.

I have many images running 64 bits OS on a Pi 3 and 4 (Armiban, Ubuntu Server 18.04, etc)... In addition, an aarch64 build would also help other similar SBC like Pine64, Odriod etc..

What I was proposing is a similar build_raspberry_pi.sh but that would allow me to cross-compile for aarch64.

Thoughts?

How can i cross compile TF for ODROID? This script work for odroid xu4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:lite TF Lite related issues subtype: raspberry pi Raspberry Pi Build/Installation Issues TF 1.13 Issues related to TF 1.13 type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests

10 participants