Re: TFLM / C++ library issues


Murphy, Lauren
 

Hi Bharath,

You may want to consider modeling your prj.conf off of the TensorFlow Lite Micro hello_world sample as well (https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/modules/tflite-micro/hello_world). You will probably also need to copy the CMakeLists.txt from that sample if you use any local static initialization - see comment below.

```
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(tensorflow_hello_world)

# These samples use local static initialization. Since Zephyr doesn't support the
# C++ ABI for thread-safe initialization of local statics and the constructors don't
# appear to require thread safety, we turn it off in the C++ compiler.
set(NO_THREADSAFE_STATICS $<TARGET_PROPERTY:compiler-cpp,no_threadsafe_statics>)
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${NO_THREADSAFE_STATICS}>)

file(GLOB app_sources src/*)
target_sources(app PRIVATE ${app_sources})
```

If you do happen to need thread-safe local static initialization... well, you can file a feature request asking for ABI support, but we only support a limited subset of C++ (https://docs.zephyrproject.org/latest/reference/kernel/other/cxx_support.html) so I'm not sure if it'll be accepted.

Right now, there are two approaches to using TFLM with Zephyr that you can follow:
1. Use the TFLM build system with a static commit of Zephyr (model your project after this example: https://github.com/antmicro/tensorflow-zephyr-vexriscv-examples)
2. Use the Zephyr build system with a static copy of the TFLM 2.5.0 library as a Zephyr "module": (model your project after this example: https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/modules/tflite-micro/hello_world

The Google maintainers recommend (1), since they helped Antmicro to develop that sample repository. (1) also lets you use a more recent version of TFLM (October 2021, instead of April 2021 / 2.5.0 for the module) and gives you more control over TFLM's configuration but takes away your control of Zephyr's. I introduced (2) last year so that users could directly use the Zephyr build / configuration system, but that similarly means you can't configure TFLM directly.

If you do decide to use the module, tag me @laurenmurphyx64 if you file GitHub issues. I'm not a TFLM jock, but I introduced the module and the samples in the Zephyr tree. I did the verification on the Renode simulator for litex_vexriscv, so it's possible you'll encounter some weirdness on the actual hardware. Also, if you find yourself configuring TFLM in certain ways you think most people would benefit from, let me know and I may be able to introduce it as a Kconfig option for the module.

Sincerely,
Lauren Murphy

-----Original Message-----
From: users@... <users@...> On Behalf Of Guy Morand
Sent: Thursday, February 17, 2022 12:02 AM
To: users@...
Subject: Re: [Zephyr-users] C++ library issues

Hi Baharath,

I also struggle a little to get cpp running, I needed the following configuration in my project to make it work:
CONFIG_NEWLIB_LIBC=y
CONFIG_CPLUSPLUS=y
CONFIG_STD_CPP20=y
CONFIG_LIB_CPLUSPLUS=y

Regards,

Guy


On 16/02/2022 16:42, Bharath V wrote:
Dear Team

I am currently working on implementing Tensorflow lite on RISC-V
(LiteX
vexRISC-V) using Zephyr RTOS. I have successfully installed Zephyr
RTOS (with SDK) and am able to run the blinky program. I am facing an
issue with the C++ libraries while using tensorflow lite. I not able
to include cstdarg library in tensorflow lite libraries or the main.c
program. The exact issue is mentioned below.

-----------------------------------------------------------------

/home/bharath/zephyrproject/zephyr/hello_world/src/main.c:8:10: fatal
error: cstdarg: No such file or directory
    8 | #include <cstdarg>
      |          ^~~~~~~~~
compilation terminated.

-----------------------------------------------------------------

I am using the west utility to build the code. Kindly requesting for
assistance.

Thanks and regards
Bharath V
--
bytes at work
Technoparkstrasse 7
CH-8406 Winterthur
Switzerland

phone: +41 52 213 79 79

Join users@lists.zephyrproject.org to automatically receive all group messages.