Arm Community
Arm Community
  • Site
  • User
  • Site
  • Search
  • User
Arm Community blogs
Arm Community blogs
AI blog Building Bazel and TensorFlow 2.x on AArch64
  • Blogs
  • Mentions
  • Sub-Groups
  • Tags
  • Jump...
  • Cancel
More blogs in Arm Community blogs
  • AI blog

  • Announcements

  • Architectures and Processors blog

  • Automotive blog

  • Embedded and Microcontrollers blog

  • Internet of Things (IoT) blog

  • Laptops and Desktops blog

  • Mobile, Graphics, and Gaming blog

  • Operating Systems blog

  • Servers and Cloud Computing blog

  • SoC Design and Simulation blog

  • Tools, Software and IDEs blog

Tags
  • AArch64
  • Docker
  • TensorFlow
Actions
  • RSS
  • More
  • Cancel
Related blog posts
Related forum threads

Building Bazel and TensorFlow 2.x on AArch64

Matthew Du Puy
Matthew Du Puy
June 3, 2020
3 minute read time.

Until recently, building TensorFlow at all on AArch64 was not possible due to its dependency on Bazel. Doing a bootstrap build of Bazel with its architecture-independent distribution archive failed. GitHub contributor, powderluv, has released several Bazel binaries allowing Google's instructions to work with a few caveats. Note: There are now a number of TensorFlow Docker containers for Arm but none of them are TensorFlow 2 or greater at the time of this writing.

Steps to build Bazel:

  • Follow the Google build instructions regarding Python and pip and when you get to the section on installing Bazel, follow the instructions for installing for
    Ubuntu->"Compile Bazel from source"->"using an existing Bazel binary".

    https://docs.bazel.build/versions/master/install-compile-source.html#build-bazel-using-bazel
  • In my particular case I am building TensorFlow 2.2, on Ubuntu 18.04.1 on an AWS EC2 A1 instance. Please note, one of the single biggest issues I have discovered had to do with RAM limits causing the compiler to crash on some TF kernel files. Using the Bazel “—local_ram_resources=“ option does not prevent the per-file gcc/clang crashes. Instead, either have an AArch64 system with more than 4GB of RAM or setup a swapfile size of 8GB.

  • TensorFlow’s configure.py file specifies: Different versions of TensorFlow require different versions of Bazel to build. To find out which version of Bazel you need to build, look in you your TensorFlow source directory or on GitHub for the configure.py file. Search for _TF_MIN_BAZEL_VERSION. In the case of TensorFlow 2.2, we see:

    _TF_MIN_BAZEL_VERSION = '2.0.0'
    _TF_MAX_BAZEL_VERSION = '2.0.0'

  • Downloaded the appropriate source archive of Bazel from Github. In this case:
    https://github.com/bazelbuild/bazel/releases/tag/2.0.0 and unpacked it.

  • Grab one of the aarch64 Bazel binaries
    https://github.com/powderluv/bazel-binbazel-1.2.1-aarch64-glibc-2.27 is the most appropriate at the time of this writing
    And, of course, make sure it is in your path as Bazel somewhere. e.g.:
    ln -s bazel-1.2.1-aarch64-glibc-2.27 /usr/local/bin/bazel

  • Change in to your new Bazel source directory (2.0 in my case) and build it:
    bazel build //src:bazel
    (or for a dev build with more debug output: bazel build //src:bazel-dev)

    The binary should build in ./bazel-bin/src/bazel (or ./bazel-bin/src/bazel-dev). Simply replace the older binary Bazel in your path with this new one and proceed to build TensorFlow from source. 
    e.g.: sudo ln -s /home/<user>/bazel-2.0.0/bazel-bin/src/bazel /usr/local/bin/bazel

Steps to build TensorFlow (2.2rc3 or newer):

  • Assuming you have already installed Python and pip dependencies according to 
    • Clone the repo: git clone https://github.com/tensorflow/tensorflow.git -or- cd tensorflow && git pull if you have already cloned the repo
    • git checkout v2.2
    • configure 
      Set python to /usr/bin/python for python 2.7, use defaults for the rest unless you have any special requirements, if not this line should work expeditiously
      yes "" | ./configure; python -c "import numpy as np"
  • A variety of other dependencies and known issues are satisfied by pip future and grpc:
    • pip install --upgrade setuptools && pip install future && pip install futures && pip install grpc
      -or, if you're using python3-
    • pip3 install --upgrade setuptools && pip3 install future
  • Build TensorFlow with Bazel with a few basic options; on AWS --config noaws is required to avoid some non-arm header includes. Using --local_ram_resources=1600 won't limit gcc or clang building individual kernels and can cause an unrecoverable compiler crash on machines with less than 4GB of RAM. The number of Bazel threads can be tuned to your number of cores; e.g. -local_cpu_resources=1
    This line should work on a majority of AArch64 systems with enough RAM
    • date; bazel build //tensorflow/tools/pip_package:build_pip_package --config noaws --config=monolithic --local_cpu_resources=4; date
  • Make a cup of tea
  • Run any relevant unit tests

If you have any interesting training scenarios, please contact me.
Contact Matt

We might be able to allocate compute resources and share our story at Arm DevSummit. 

Anonymous
  • Peter Hägglund
    Peter Hägglund over 4 years ago in reply to hopezhou

    I'm using Ubuntu 20.10 on Raspberyy Pi 4 8Gb.

    After installing Bazel 3.7.0 I set (https://github.com/bazelbuild/bazelisk):

    export USE_BAZEL_VERSION=3.7.0

    before running the bazel build.

    When build finished:

    (https://collaborate.linaro.org/display/BDTS/Building+and+Installing+Tensorflow+on+AArch64)

    #Build pip package
    bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    sudo pip install /tmp/tensorflow_pkg/tensorflow-2.5.0-cp38-cp38-linux_aarch64.whl

    It worked splendidly for me - a bit worried about the 2.5.0 version though... but at least I succeeded to install and use.

    Hope it helps.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • hopezhou
    hopezhou over 4 years ago

    I came across following error:

    (py3) pcl@begoit-920-11:~/packages/tensorflow$ date; bazel build //tensorflow/tools/pip_package:build_pip_package --config noaws --config=monolithic --local_cpu_resources=90; date
    Tue Nov 3 16:29:48 CST 2020
    2020/11/03 16:29:48 Downloading releases.bazel.build/.../bazel-2.0.0-linux-arm64...
    2020/11/03 16:29:49 could not download Bazel: HTTP GET releases.bazel.build/.../bazel-2.0.0-linux-arm64 failed with error 404
    Tue Nov 3 16:29:49 CST 2020

    Then, I found there is no ‘bazel-2.0.0-linux-arm64’ in releases.bazel.build/.../release

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
AI blog
  • Make an AI Yoga Tutor for TV or smartphone and accelerate it with SME2

    Hamza Arslan
    Hamza Arslan
    In this blog post learn how Arm SME2 accelerates our AI Yoga Tutor, delivering real-time, personalized pose correction.
    • September 22, 2025
  • Sign language translation using machine learning

    Lizzie Salter
    Lizzie Salter
    In this blog post, learn how the Arm Developer Advocacy team is exploring how machine learning can enable a sign-to-speech translator for video conferencing.
    • August 15, 2025
  • Bringing Generative AI to the masses with ExecuTorch and KleidiAI

    Gian Marco Iodice
    Gian Marco Iodice
    With the recent Arm SME2 announcement, the role of Arm KleidiAI is increasingly clear as Arm’s AI accelerator layer powering the next wave of AI.
    • August 13, 2025