FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

TensorFlow LiteでのRISC-V向けビルド試行(1. riscv32-gccを使ったビルド試行→失敗)

f:id:msyksphinz:20181128161624p:plain

TensorFlow Liteは、Raspberry Pi向けであったり、iOS向けにコンパイル環境が用意されているようだが、よく見てみると一応RISC-V向けのビルドファイルが用意されている。

ちゃんとしたサポートになっているのかは分からないが、これを使えばとりあえずRISC-V向けにTensorFlow Liteを動かすことができるのだろうか。 中身を見てみると32-bit版RISC-Vになっているので、HiFive1 あたりで動いてくれると嬉しい。

github.com

とりあえず32-bit版RISC-Vのツールチェインをインストールして、ビルドを試行してみる。

32-bit版RISC-Vツールチェインのインストールが完了して、Raspberry Pi向けの構成を真似てビルドしてみても思いっきりエラーとなった。

  • ./tensorflow/lite/tools/make/build_riscv_lib.sh
set -e

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

CC_PREFIX=riscv64-unknown-elf- make -j 3 -f tensorflow/lite/tools/make/Makefile TARGET=riscv TARGET_ARCH=riscv
cd tensorflow
./tensorflow/lite/tools/make/download_dependencies.sh
./tensorflow/lite/tools/make/build_riscv_lib.sh
...
/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/gemmlowp/public/../internal/multi_thread_gemm.h:111:59: error: 'pthread_cond_t' has not been declared
 T WaitForVariableChange(volatile T* var, T initial_value, pthread_cond_t* cond,

これはやはりLinuxGCCを使わなければならないのだろうか。

riscv32-unknown-linux-gnuを使ってみた。しかし最後にやはりエラーとなる。-lzを除去してもエラーになるので、もう少し解析が必要だ。

riscv32-unknown-linux-gnu-g++ -O3 -DNDEBUG --std=c++11 -DTFLITE_MCU -I. -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/../../../../../ -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/../../../../../../ -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/ -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/eigen -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/absl -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/gemmlowp -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/neon_2_sse -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/farmhash/src -I/home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/downloads/flatbuffers/include -I -I/usr/local/include \
-o /home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/gen/riscv_riscv/bin/minimal /home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/gen/riscv_riscv/obj/tensorflow/lite/examples/minimal/minimal.o \
 /home/msyksphinz/others/riscv/tensorflow/tensorflow/lite/tools/make/gen/riscv_riscv/lib/libtensorflow-lite.a  -lstdc++ -lpthread -lm -lz -ldl
/home/msyksphinz/riscv32_linux/bin/../lib/gcc/riscv32-unknown-linux-gnu/7.2.0/../../../../riscv32-unknown-linux-gnu/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status