Skip to content

Commit

Permalink
Update TFLite ARM build page
Browse files Browse the repository at this point in the history
- Unified ARM64, RPI build pages
- Removed Makefile build path
- Removed experimental tag for CMake build page

PiperOrigin-RevId: 363315150
Change-Id: I391533c0ebeb5359c9c286758c6395bba75dbeb9
  • Loading branch information
terryheo authored and tensorflower-gardener committed Mar 17, 2021
1 parent 01f66f4 commit 1376eba
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 336 deletions.
7 changes: 2 additions & 5 deletions tensorflow/lite/g3doc/_book.yaml
Expand Up @@ -177,13 +177,10 @@ upper_tabs:
path: /lite/guide/build_android
- title: "Build for iOS"
path: /lite/guide/build_ios
- title: "Build for ARM64"
path: /lite/guide/build_arm64
- title: "Build for Raspberry Pi"
path: /lite/guide/build_rpi
- title: "Build for ARM"
path: /lite/guide/build_arm
- title: "Build with CMake"
path: /lite/guide/build_cmake
status: experimental
section:
- title: "Cross compilation for ARM"
path: /lite/guide/build_cmake_arm
Expand Down
105 changes: 105 additions & 0 deletions tensorflow/lite/g3doc/guide/build_arm.md
@@ -0,0 +1,105 @@
# Build TensorFlow Lite for ARM boards

This page describes how to build the TensorFlow Lite libraries for ARM-based
computers.

TensorFlow Lite supports two build systems and supported features from each
build system are not idential. Check the following table to pick a proper build
system.

Feature | Bazel | CMake
----------------------------------------------------------------------------------------- | ---------------------------- | -----
Predefined toolchains | armhf, aarch64 | armel, armhf, aarch64
Custom toolchains | harder to use | easy to use
[Select TF ops](https://www.tensorflow.org/lite/guide/ops_select) | supported | not supported
[GPU delegate](https://www.tensorflow.org/lite/performance/gpu) | only available for Android | any platform that supports OpenCL
XNNPack | supported | supported
[Python Wheel](https://www.tensorflow.org/lite/guide/build_cmake_pip) | supported | supported
[C API](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/README.md) | supported | [supported](https://www.tensorflow.org/lite/guide/build_cmake#build_tensorflow_lite_c_library)
[C++ API](https://www.tensorflow.org/lite/guide/inference#load_and_run_a_model_in_c) | supported for Bazel projects | supported for CMake projects

## Cross-compilation for ARM with CMake

If you have a CMake project or if you want to use a custom toolchain, you'd
better use CMake for cross compilation. There is a separate
[Cross compilation TensorFlow Lite with CMake](https://www.tensorflow.org/lite/guide/build_cmake_arm)
page available for this.

## Cross-compilation for ARM with Bazel

If you have a Bazel project or if you want to use TF ops, you'd better use Bazel
build system. You'll use the integrated
[ARM GCC 8.3 toolchains](https://github.com/tensorflow/tensorflow/tree/master/third_party/toolchains/embedded/arm-linux)
with Bazel to build an ARM32/64 shared library.

| Target Architecture | Bazel Configureation | Compatibile Devices |
| ------------------- | ----------------------- | -------------------------- |
| armhf (ARM32) | --config=elinux_armhf | RPI3, RPI4 with 32 bit |
: : : Raspberry Pi OS :
| AArch64 (ARM64) | --config=elinux_aarch64 | Coral, RPI4 with Ubuntu 64 |
: : : bit :

Note: The generated shared library requires glibc 2.28 or higher to run.

The following instructions have been tested on Ubuntu 16.04.3 64-bit PC (AMD64)
and TensorFlow devel docker image
[tensorflow/tensorflow:devel](https://hub.docker.com/r/tensorflow/tensorflow/tags/).

To cross compile TensorFlow Lite with Bazel, follow the steps:

#### Step 1. Install Bazel

Bazel is the primary build system for TensorFlow. Install the latest version of
the [Bazel build system](https://bazel.build/versions/master/docs/install.html).

**Note:** If you're using the TensorFlow Docker image, Bazel is already
available.

#### Step 2. Clone TensorFlow repository

```sh
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
```

**Note:** If you're using the TensorFlow Docker image, the repo is already
provided in `/tensorflow_src/`.

#### Step 3. Build ARM binary

##### C library

```bash
bazel build --config=elinux_aarch64 -c opt //tensorflow/lite/c:libtensorflowlite_c.so
```

You can find a shared library in:
`bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so`.

**Note:** Use `elinux_armhf` for
[32bit ARM hard float](https://wiki.debian.org/ArmHardFloatPort) build.

Check
[TensorFlow Lite C API](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/README.md)
page for the detail.

##### C++ library

```bash
bazel build --config=elinux_aarch64 -c opt //tensorflow/lite:libtensorflowlite.so
```

You can find a shared library in:
`bazel-bin/tensorflow/lite/libtensorflowlite.so`.

Currently, there is no straightforward way to extract all header files needed,
so you must include all header files in tensorflow/lite/ from the TensorFlow
repository. Additionally, you will need header files from FlatBuffers and
Abseil.

##### Etc

You can also build other Bazel targets with the toolchain. Here are some useful
targets.

* //tensorflow/lite/tools/benchmark:benchmark_model
* //tensorflow/lite/examples/label_image:label_image
146 changes: 0 additions & 146 deletions tensorflow/lite/g3doc/guide/build_arm64.md

This file was deleted.

0 comments on commit 1376eba

Please sign in to comment.