Closed uvvpavel closed 1 year ago
As part of this issue, I debugged the failure seen in the Stage B tests that led to an interesting discovery. The failure scenario was, 2 tests run using pytest -n1 in the CFFI environment, which meant C functions were being called directly in python. The test that got run second always failed and if the tests were run as 2 separate pytest commands, they both passed.
What was happening was that both tests were initialising the module and then doing some processing. So the model_init() function in VNR ended up being called twice since in CFFI, python would end up calling functions corresponding to both tests one after the other, without a restart between tests. Turns out, the autogenerated tflite_micro_compiler output file that has model_init() implementation has some one time initialised non const global variables, which end up having different values between the first and second init call. Specifically, the AllocPtr initialisation in the AllocatePersistentBuffer() https://github.com/shuchitak/sw_avona-1/blob/feature/latest_tflite_micro/modules/lib_vnr/src/inference/model/trained_model_xcore.cpp#L994 was not happening in the second model_init() so it was crashing due to running out of memory.
So, for a given model, model_init() cannot be called more than once. I've added a fix in the VNR module to ensure this.
After merging changes for using the latest lib_tflite_micro to develop, there are some more steps remaining: