Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tflite-micro is breaking complex.h #9516

Open
1 task done
pschatzmann opened this issue Apr 15, 2024 · 15 comments
Open
1 task done

tflite-micro is breaking complex.h #9516

pschatzmann opened this issue Apr 15, 2024 · 15 comments
Labels
Area: Libraries Issue is related to Library support. Status: Solved

Comments

@pschatzmann
Copy link

Board

Any

Device Description

The issue is with all boards: I tried with the ESP32 and a C6

Hardware Configuration

n/a

Version

latest development Release Candidate (RC-X)

IDE Name

Arduino IDE

Operating System

Linux Mint

Flash frequency

n/a

PSRAM enabled

no

Upload speed

n/a

Description

The new version (4.0.0) contains espressif__esp-tflite-micro which has a complex.h in the src directory:
~/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-3662303f312/esp32/include/espressif__esp-tflite-micro/signal/src/complex.h

This is preventing that the regular complex.h from the c and c++ library can be used!
So all libraries containing complex.h are broken and will produce compile errors.

Sketch

#include <complex.h>

std::complex<double> mycomplex(10.0, 2.0);

void setup() {}

void loop() {}

Debug Message

Compile error:

/tmp/.arduinoIDE-unsaved2024315-466177-1nzbc94.mycl/sketch_apr15c/sketch_apr15c.ino:3:6: error: 'complex' in namespace 'std' does not name a template type
    3 | std::complex<double> mycomplex(10.0, 2.0);
      |      ^~~~~~~
/tmp/.arduinoIDE-unsaved2024315-466177-1nzbc94.mycl/sketch_apr15c/sketch_apr15c.ino:2:1: note: 'std::complex' is defined in header '<complex>'; did you forget to '#include <complex>'?
    1 | #include <complex.h>
  +++ |+#include <complex>
    2 | 

exit status 1

Compilation error: 'complex' in namespace 'std' does not name a template type

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@pschatzmann pschatzmann added the Status: Awaiting triage Issue is waiting for triage label Apr 15, 2024
@pschatzmann
Copy link
Author

I messed up with the version info: of cause it is 3.0.0-rc1

@lucasssvaz
Copy link
Collaborator

The CPP STD header name is complex without the .h

This will compile without any issue:

#include <complex>

std::complex<double> mycomplex(10.0, 2.0);

void setup() {}

void loop() {}

@me-no-dev
Copy link
Member

#include <complex> not <complex.h>. Would that work?

@pschatzmann
Copy link
Author

pschatzmann commented Apr 15, 2024

For the indicated example it would work, but I filed the issue because some sketches which are using c libraries (some audio codecs and fft) are not compiling any more and it was too tedious to demo the issue in c.

I wanted proof the point that complex.h is broken in C!

e.g.
https://github.com/pschatzmann/esp32-fft
https://github.com/pschatzmann/arduino-codec2
https://github.com/pschatzmann/kissfft

@me-no-dev
Copy link
Member

If you think that complex.h is broken, maybe file an issue in the toolchain repository: https://github.com/espressif/crosstool-NG/issues

@pschatzmann
Copy link
Author

pschatzmann commented Apr 15, 2024

So it is the toolchain and not arduino-esp32 that decides to include and make available tflite-micro ?

@me-no-dev
Copy link
Member

@pschatzmann we did resolve your original issue. For the others it's too tedious for you to properly report. I am still trying to offer you a way to resolve the problem, for which I only know that it has to do with complex.h.

@me-no-dev me-no-dev added Area: Libraries Issue is related to Library support. Status: Solved and removed Status: Awaiting triage Issue is waiting for triage labels Apr 16, 2024
@pschatzmann
Copy link
Author

I can create an additional simple example (on top of the mentioned libraries that give compile errors) if that helps you to understand the issue. Please let me know!

@me-no-dev
Copy link
Member

Yes it will. thanks!

@pschatzmann
Copy link
Author

pschatzmann commented Apr 16, 2024

In Arduino, create a new tab: test.c with the following lines:

#include <complex.h> 
double complex  z  = 3.2 + 4.1 * I; 

This gives the following error:

In file included from /tmp/.arduinoIDE-unsaved2024316-5867-1odft3o.2uay/sketch_apr16a/test.c:1:
/home/pschatzmann/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-3662303f312/esp32/include/espressif__esp-tflite-micro/signal/src/complex.h:23:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   23 | template <typename T>
      |          ^
/tmp/.arduinoIDE-unsaved2024316-5867-1odft3o.2uay/sketch_apr16a/test.c:2:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'z'
    2 | double complex  z  = 3.2 + 4.1 * I;
      |                 ^

exit status 1

Compilation error: expected '=', ',', ';', 'asm' or '__attribute__' before 'z'

Deleting the file ~/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-3662303f312/esp32/include/espressif__esp-tflite-micro/signal/src/complex.h is correcting the issue!

So this is the root cause of the issue! and any Arduino library using complex.h in a c file will not work any more.

This example is working properly in prior versions

@pschatzmann
Copy link
Author

I cross posted the issue in tflite-micro as well, since it could be resolved easily there

@me-no-dev
Copy link
Member

This would be easily fixable in the header itself. Seems to not have guards for CPP and also does not include the next complex.h. With the following changes your example compiled
Screenshot 2024-04-16 at 11 42 06

@pschatzmann
Copy link
Author

pschatzmann commented Apr 16, 2024

Just for my better understanding: am I correct in the assumption that it was the decision of the arduino-esp32 project to include tflite-micro into the basic functionality instead of relying on an Arduino library ?

From my point of view an Arduino library would be a better fit and would provide much more flexibility.

@me-no-dev
Copy link
Member

differences is that this "version" of tflite is written to support the hardware accelerators in some of our chips, so on S3 you would get better results. I do not see how external Arduino library would help in this case. The header comes from tflite itself.

@me-no-dev
Copy link
Member

Also tflite is precompiled, so you only need to link against it and not compile the whole thing (it's a lot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Status: Solved
Projects
None yet
Development

No branches or pull requests

3 participants