cpetig / tflite_micro_compiler

generate tflite micro code which bypasses the interpreter (directly calls into kernels)
Apache License 2.0
76 stars 26 forks source link

[BUG]Compiler fails for mobilenet (memory corruption?) #43

Closed cpetig closed 4 years ago

cpetig commented 4 years ago

When running make regenerate in the examples folder the compiled_mobilenet.cpp is broken. Interestingly a string is substituted (considered as a custom operator?), so I suspect some interesting memory corruption:

-  { (TfLiteIntArray*)&inputs12, (TfLiteIntArray*)&outputs12, const_cast<void*>(static_cast<const void*>(&opdata12)), OP_CONV_2D, },
+  { (TfLiteIntArray*)&inputs12, (TfLiteIntArray*)&outputs12, const_cast<void*>(static_cast<const void*>(&opdata12)), OP_ROMTensor_L0in, 0, },
cpetig commented 4 years ago

I believe I found the problem: When it checks for custom operators (https://github.com/cpetig/tflite_micro_compiler/blob/7a2f20a00ad99bb52024dd0063b6e19ef800712c/src/Compiler.cpp#L352) it uses the wrong index (i instead of regI), as random memory is unlikely to be equal to a 32bit constant most of the time it does no harm.