Merci de vous être connecté à Google I/O. Voir toutes les sessions à la demande Regarder à la demande

Compilation croisée TensorFlow Lite avec CMake

Cette page décrit comment créer la bibliothèque TensorFlow Lite pour divers appareils ARM.

Les instructions suivantes ont été testées sur Ubuntu 16.04.3 64 bits PC (AMD64) , TensorFlow devel docker image tensorflow/tensorflow:devel .

Conditions préalables

Vous devez avoir installé et téléchargé le code source TensorFlow de CMake. Veuillez consulter la page Build TensorFlow Lite with CMake pour plus de détails.

Vérifiez votre environnement cible

Les exemples suivants sont testés sous Raspberry Pi OS, Ubuntu Server 20.04 LTS et Mendel Linux 4.0. En fonction de la version de votre glibc cible et des capacités du processeur, vous devrez peut-être utiliser une version différente de la chaîne d'outils et des paramètres de construction.

Vérification de la version de la glibc

ldd --version
ldd (Debian GLIBC 2.28-10) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

Vérification de la compatibilité ABI

Si votre cible est ARM 32 bits, deux ABI sont disponibles en fonction de la disponibilité de VFP. armhf et armel . Ce document montre un exemple armhf, vous devez utiliser une chaîne d'outils différente pour les cibles armhf.

Vérification de la capacité du processeur

Pour ARMv7, vous devez connaître la version VFP prise en charge par la cible et la disponibilité de NEON.

cat /proc/cpuinfo
processor   : 0
model name  : ARMv7 Processor rev 3 (v7l)
BogoMIPS    : 108.00
Features    : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part    : 0xd08
CPU revision    : 3

Construire pour AArch64 (ARM64)

Cette instruction montre comment construire un binaire AArch64 compatible avec Coral Mendel Linux 4.0 , Raspberry Pi (avec Ubuntu Server 20.04.01 LTS 64 bits installé).

Télécharger la chaîne d'outils

Ces commandes installent la chaîne d'outils gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu sous ${HOME}/toolchains.

curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz
mkdir -p ${HOME}/toolchains
tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C ${HOME}/toolchains

Exécutez CMake

ARMCC_PREFIX=${HOME}/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
ARMCC_FLAGS="-funsafe-math-optimizations"
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
  -DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
  -DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
  -DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_PROCESSOR=aarch64 \
  ../tensorflow/lite/

Build pour ARMv7 NEON activé

Cette instruction montre comment construire ARMv7 avec un binaire compatible VFPv4 et NEON compatible avec Raspberry Pi 3 et 4.

Télécharger la chaîne d'outils

Ces commandes installent la chaîne d'outils gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf sous ${HOME}/toolchains.

curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz
mkdir -p ${HOME}/toolchains
tar xvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz -C ${HOME}/toolchains

Exécutez CMake

ARMCC_FLAGS="-march=armv7-a -mfpu=neon-vfpv4 -funsafe-math-optimizations -mfp16-format=ieee"
ARMCC_PREFIX=${HOME}/toolchains/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
  -DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
  -DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
  -DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_PROCESSOR=armv7 \
  ../tensorflow/lite/

Conçu pour Raspberry Pi Zero (ARMv6)

Cette instruction montre comment créer un binaire ARMv6 compatible avec Raspberry Pi Zero.

Télécharger la chaîne d'outils

Ces commandes installent la chaîne d'outils gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf sous ${HOME}/toolchains.

curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz
mkdir -p ${HOME}/toolchains
tar xvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz -C ${HOME}/toolchains

Exécutez CMake

ARMCC_FLAGS="-march=armv6 -mfpu=vfp -mfloat-abi=hard -funsafe-math-optimizations"
ARMCC_PREFIX=${HOME}/toolchains/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
  -DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
  -DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
  -DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_PROCESSOR=armv6 \
  -DTFLITE_ENABLE_XNNPACK=OFF \
  ../tensorflow/lite/