2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Native build procedure of Tensorflow v2.0.0 C API for RaspberryPi / arm64 devices (armhf / aarch64)

Last updated at Posted at 2019-11-04

Tensorflow-bin GitHub stars

Bazel_bin GitHub stars

1.Introduction

This section describes how to build Tensorflow v2.0.0 C API (RaspberryPi / arm64 devices). Since we get an error when we build according to the official tutorial, I devised my own procedure. In particular, when using armhf (armv7l), an error undefined symbol: __atomic_fetch_add_8 will occur, so an option must be added to the build script. My procedure can avoid undefined symbol: __atomic_fetch_add_8 errors and complete the build successfully. When using RaspberryPi4, it will be completed in about 6 hours. Prebuilt binaries and installers can be downloaded from my Github repository.

2.Environment

3.Procedure

Install_required_packages
$ sudo apt-get install -y \
make cmake wget curl libhdf5-dev libc-ares-dev libeigen3-dev libatomic1 \
openmpi-bin libopenmpi-dev libatlas-base-dev zip unzip
Clone_Tensorflow
$ cd ~

$ git clone -b v2.0.0 https://github.com/tensorflow/tensorflow.git

or

$ git clone -b v1.15.0 https://github.com/tensorflow/tensorflow.git

$ cd tensorflow/tensorflow/tools/lib_package
【Pattern_1】_Build_Tensorflow_v2.0.0_Pi3/Pi4_armhf
### Install openjdk-8-jdk armhf
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1LQUSal55R6fmawZS9zZuk6-5ZFOdUqRK" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1LQUSal55R6fmawZS9zZuk6-5ZFOdUqRK" -o adoptopenjdk-8-hotspot_8u222-b10-2_armhf.deb
$ sudo apt-get install -y ./adoptopenjdk-8-hotspot_8u222-b10-2_armhf.deb

### Install Bazel 0.26.1 armhf
$ wget https://github.com/PINTO0309/Bazel_bin/raw/master/0.26.1/Raspbian_Debian_Buster_armhf/openjdk-8-jdk/install.sh
$ ./install.sh

### Build Tensorflow
$ sudo bazel --host_jvm_args=-Xmx512m build \
--config=noaws \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--config=v2 \
--local_resources=4096.0,3.0,1.0 \   #<===[If Pi3] --local_resources=1024.0,0.5,0.5 \
--copt=-mfpu=neon-vfpv4 \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--copt=-DRASPBERRY_PI \
--host_copt=-DRASPBERRY_PI \
--linkopt=-Wl,-latomic \
--host_linkopt=-Wl,-latomic \
//tensorflow/tools/lib_package:libtensorflow
【Pattern_2】_Build_Tensorflow_v1.15.0_Pi3/Pi4_armhf
### Install openjdk-8-jdk armhf
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1LQUSal55R6fmawZS9zZuk6-5ZFOdUqRK" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1LQUSal55R6fmawZS9zZuk6-5ZFOdUqRK" -o adoptopenjdk-8-hotspot_8u222-b10-2_armhf.deb
$ sudo apt-get install -y ./adoptopenjdk-8-hotspot_8u222-b10-2_armhf.deb

### Install Bazel 0.26.1 armhf
$ wget https://github.com/PINTO0309/Bazel_bin/raw/master/0.26.1/Raspbian_Debian_Buster_armhf/openjdk-8-jdk/install.sh
$ ./install.sh

### Build Tensorflow
$ sudo bazel --host_jvm_args=-Xmx512m build \
--config=noaws \
--config=nogcp \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--local_resources=4096.0,3.0,1.0 \   #<===[If Pi3] --local_resources=1024.0,0.5,0.5 \
--copt=-mfpu=neon-vfpv4 \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--copt=-DRASPBERRY_PI \
--host_copt=-DRASPBERRY_PI \
--linkopt=-Wl,-latomic \
--host_linkopt=-Wl,-latomic \
//tensorflow/tools/lib_package:libtensorflow
【Pattern_3】_Build_Tensorflow_v2.0.0_Debian_Buster_aarch64
### Install openjdk-8-jdk aarch64
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1VwLxzT3EOTbhSzwvRF2H4ChTQyTQBt3x" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1VwLxzT3EOTbhSzwvRF2H4ChTQyTQBt3x" -o adoptopenjdk-8-hotspot_8u222-b10-2_arm64.deb
$ sudo apt-get install -y ./adoptopenjdk-8-hotspot_8u222-b10-2_arm64.deb

### Install Bazel 0.26.1 aarch64
$ wget https://github.com/PINTO0309/Bazel_bin/raw/master/0.26.1/Raspbian_Debian_Buster_aarch64/openjdk-8-jdk/install.sh
$ ./install.sh

### Build Tensorflow
$ sudo bazel --host_jvm_args=-Xmx512m build \
--config=noaws \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--config=v2 \
//tensorflow/tools/lib_package:libtensorflow
【Pattern_4】_Build_Tensorflow_v1.15.0_Debian_Buster_aarch64
### Install openjdk-8-jdk aarch64
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1VwLxzT3EOTbhSzwvRF2H4ChTQyTQBt3x" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1VwLxzT3EOTbhSzwvRF2H4ChTQyTQBt3x" -o adoptopenjdk-8-hotspot_8u222-b10-2_arm64.deb
$ sudo apt-get install -y ./adoptopenjdk-8-hotspot_8u222-b10-2_arm64.deb

### Install Bazel 0.26.1 aarch64
$ wget https://github.com/PINTO0309/Bazel_bin/raw/master/0.26.1/Raspbian_Debian_Buster_aarch64/openjdk-8-jdk/install.sh
$ ./install.sh

### Build Tensorflow
$ sudo bazel --host_jvm_args=-Xmx512m build \
--config=noaws \
--config=nogcp \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
//tensorflow/tools/lib_package:libtensorflow

Prebuilt binaries are generated in bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz.

4.Install Tensorflow C API

$ tar -C /usr/local -xzf libtensorflow.tar.gz

5.Reference articles

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?