Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

RISC-VでTensorFlow Lite


RISC-V で TensorFlow Lite を動かす。

November RISC-V Bay Area Meetup hosted by Antmicroにて、
引用
"TensorFlow Lite on RISC-V" (Pete Warden - Google)

Many emerging new microcontrollers use RISC-V, and the TensorFlow Lite team has been exploring how to best support these new platforms. In this talk, Pete Warden, Lead of the TensorFlow Mobile/Embedded team at Google will discuss how they've used Renode, gcc, and other open-source technologies to target RISC-V for machine learning.

おー、聴いてみたい。。。遠いけどね。

TensorFlow Liteには特別な仕組みは無くて、Makefileを作るだけでできるんだよね。

実は、r1.11 から入っているんだよね。ここ

riscv_makefile.inc
# Settings for RiscV platforms.
ifeq ($(TARGET), riscv)
  TARGET_ARCH := riscv
  TARGET_TOOLCHAIN_PREFIX := riscv32-unknown-elf-

  #CXXFLAGS += -march=gap8
  CXXFLAGS += -DTFLITE_MCU
	LIBS += -ldl
	BUILD_TYPE := micro
endif

じゃー、どうやって、Build するかというと、https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/g3doc/rpi.md RasPiと同じ。

https://github.com/tensorflow/tensorflow/tree/r1.11/tensorflow/contrib/lite/tools/make ここにあるbuild_rpi_lib.shをベースに以下のように変更するだけよ。
{{{
set -e

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

CC_PREFIX=arm-linux-gnueabihf- make -j 3 -f tensorflow/contrib/lite/tools/make/Makefile TARGET=riscv TARGET_ARCH=riscvl

ただし、事前にRISC-V(32ビット)のクロスコンパイラをインストールする必要がありますけどね。