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

This adds TFLite build script for generic aarch64 boards #24876

Merged
merged 10 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions tensorflow/lite/g3doc/devguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ trained Tensorflow models to the
devices. To use the converter, refer to the
[Tensorflow-CoreML converter documentation](https://github.com/tf-coreml/tf-coreml).

### Raspberry Pi
### ARM32 and ARM64 Linux

Compile Tensorflow Lite for a Raspberry Pi by following the
[RPi build instructions](rpi.md) This compiles a static library file (`.a`) used
Compile Tensorflow Lite for a Raspberry Pi by following the [RPi build
instructions](rpi.md) Compile Tensorflow Lite for a generic aarch64 board such
as Odroid C2, Pine64, NanoPi, and others by following the [ARM64 Linux build
instructions](linux_aarch64.md) This compiles a static library file (`.a`) used
to build your app. There are plans for Python bindings and a demo app.
60 changes: 60 additions & 0 deletions tensorflow/lite/g3doc/linux_aarch64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# TensorFlow Lite for generic ARM64 boards

## Cross compiling

### Installing the toolchain

```bash
sudo apt-get update
sudo apt-get install crossbuild-essential-arm64
```

> If you are using Docker, you may not use `sudo`.

### Building

Clone this Tensorflow repository.
Run this script at the root of the repository to download all the dependencies:

> The Tensorflow repository is in `/tensorflow` if you are using `tensorflow/tensorflow:nightly-devel` docker image, just try it.

```bash
./tensorflow/lite/tools/make/download_dependencies.sh
```

Note that you only need to do this once.

Compile:

```bash
./tensorflow/lite/tools/make/build_aarch64_lib.sh
```

This should compile a static library in:
`tensorflow/lite/gen/gen/aarch64_armv8-a/lib/libtensorflow-lite.a`.

## Native compiling

These steps were tested on HardKernel Odroid C2, gcc version 5.4.0.

Log in to your board, install the toolchain.

```bash
sudo apt-get install build-essential
```

First, clone the TensorFlow repository. Run this at the root of the repository:

```bash
./tensorflow/lite/tools/make/download_dependencies.sh
```
Note that you only need to do this once.

Compile:

```bash
./tensorflow/lite/tools/make/build_aarch64_lib.sh
```

This should compile a static library in:
`tensorflow/lite/gen/gen/aarch64_armv8-a/lib/libtensorflow-lite.a`.
4 changes: 4 additions & 0 deletions tensorflow/lite/tools/make/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Make uses /bin/sh by default, which is incompatible with the bashisms seen
# below.
SHELL := /bin/bash

# Find where we're running from, so we can store generated files here.
ifeq ($(origin MAKEFILE_DIR), undefined)
MAKEFILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
Expand Down
22 changes: 22 additions & 0 deletions tensorflow/lite/tools/make/build_aarch64_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash -x
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/../../../.."

CC_PREFIX=aarch64-linux-gnu- make -j 3 -f tensorflow/lite/tools/make/Makefile TARGET=aarch64 TARGET_ARCH=armv8-a
33 changes: 33 additions & 0 deletions tensorflow/lite/tools/make/targets/aarch64_makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Settings for generic aarch64 boards such as Odroid C2 or Pine64.
ifeq ($(TARGET),aarch64)
# The aarch64 architecture covers all 64-bit ARM chips. This arch mandates
# NEON, so FPU flags are not needed below.
TARGET_ARCH := armv8-a
TARGET_TOOLCHAIN_PREFIX := aarch64-linux-gnu-

CXXFLAGS += \
-march=armv8-a \
-funsafe-math-optimizations \
-ftree-vectorize \
-fPIC

CCFLAGS += \
-march=armv8-a \
-funsafe-math-optimizations \
-ftree-vectorize \
-fPIC

LDFLAGS := \
-Wl,--no-export-dynamic \
-Wl,--exclude-libs,ALL \
-Wl,--gc-sections \
-Wl,--as-needed


LIBS := \
-lstdc++ \
-lpthread \
-lm \
-ldl

endif