Problem with TVMExecute on Arduino in standalone execution

Hi, I’m new with microTVM, but I want to run the kws model with tvm on Arduino Nano 33 BLE Sense. First of all, I tried this tutorial with micro_speech: demo. It works perfect. Problems appear when I’m trying to compile yes_no.tflite or my_kws.tflite models using tvmc or generate_project.py (from demo) on my own. My board dont answer after flashing. I think, there is a problem with TVMExecute function.

In tutorial it has this structure:

void TVMExecute(void* input_data, void* output_data) {
  int ret_val = tvmgen_default_run_model(input_data, output_data);
  if (ret_val != 0) {
    TVMPlatformAbort(kTvmErrorPlatformCheckFailure);
  }
}

And this is a part of model’s libs:

#include "../../src/standalone_crt/include/tvm/runtime/c_runtime_api.h"
#ifdef __cplusplus
extern "C" {
#endif
TVM_DLL int32_t tvmgen_default_run_model(void* arg0,void* arg1);
int32_t tvmgen_default_run(void* args, void* type_code, int num_args, void* out_value, void* out_type_code, void* resource_handle) {
return tvmgen_default_run_model(((DLTensor*)(((TVMValue*)args)[0].v_handle))[0].data,((DLTensor*)(((TVMValue*)args)[1].v_handle))[0].data);
}
#ifdef __cplusplus
}
#endif
;

So, when I compile the model, TVMExecute looks like:

void TVMExecute(void* input_data, void* output_data) {
  int ret_val = tvmgen_default___tvm_main__(input_data, output_data);
  if (ret_val != 0) {
    TVMPlatformAbort(kTvmErrorPlatformCheckFailure);
  }
}

And a part of model’s libs look like:

TVM_DLL int32_t tvmgen_default___tvm_main__(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, int* out_type_code, void* resource_handle);

int32_t tvmgen_default_run(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, int* out_type_code, void* resource_handle) {
TVMValue tensors[4];
tensors[0] = ((TVMValue*)args)[0];
tensors[1] = ((TVMValue*)args)[1];
DLTensor global_const_workspace_dltensor = {
.data = &global_const_workspace
};
TVMValue global_const_workspace_tvm_value = {
.v_handle = &global_const_workspace_dltensor
};
tensors[2] = global_const_workspace_tvm_value;
DLTensor global_workspace_dltensor = {
.data = &global_workspace
};
TVMValue global_workspace_tvm_value = {
.v_handle = &global_workspace_dltensor
};
tensors[3] = global_workspace_tvm_value;
return tvmgen_default___tvm_main__((void*)tensors, type_code, num_args, out_value, out_type_code, resource_handle);
}

For me it looks like the relay of model has changed, and I should pass to TVMExecute something else.

So, if I have inputs, how I should pass it to get answer from model?

I will be happy for any tips about what to do or how it all works.

And if it’s helpful, my tvmc commands:

tvmc compile input/kws_ref_model.tflite \    
--target='c -keys=cpu -model=host' \  
--runtime=crt \     
--runtime-crt-system-lib 1 \    
--executor='aot' \    
--output output/model.tar \    
--output-format mlf \     
--pass-config tir.disable_vectorize=1

tvmc micro create -f output/project/ output/model.tar arduino \
--project-option project_type=example_project board=nano33ble
1 Like

Hello, @mehrdadh @guberti. May you explain how I should pass input in compiled model? Or maybe give some tips about that can be wrong? I will be very thankful

1 Like

Hi @Red-Caesar, I experienced something (in a different project context) with what sounds like the same symptoms as you mentioned … Arduino Nano 33 BLE Sense execution started, but didn’t continue after call to TVMExecute().

I am also new to using microTVM, but after some tediously slow debugging I found that the following resolved it for me: (in my case using the python api)

Problem occurred with:

executor = tvm.relay.backend.Executor("aot")

Problem resolved with:

executor = tvm.relay.backend.Executor("aot", {"unpacked-api": True})

Where the “executor” variable above is used in the call to “tvm.relay.build”

I was doing the tvm compile on Google Colab, using the following tvm install:

!pip install -q apache-tvm==0.11.1

I don’t know enough to say if your issue could be similar or different, but since I found your post while searching for answers to my issue, I thought I’d post my finding here just in case.

1 Like

Hi, @colosb! Thank you very much for your answer! I really appreciate it. I’ve tried this, and now libs’ files looks fine. Moreover, after solving some of the following issues my project is working now.

Just in case, I want ask. Did you have a problem with declaration in libs file (when building a project):

default_lib0.c:97:17: error: conflicting types for 'tvmgen_default___tvm_main__'
 TVM_DLL int32_t tvmgen_default___tvm_main__(void* input_1,void* output0);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
default_lib0.c:61:17: note: previous declaration of 'tvmgen_default___tvm_main__' was here
 TVM_DLL int32_t tvmgen_default___tvm_main__(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, int* out_type_code, void* resource_handle);

A quick fix that worked is line commenting. But If you didn’t have similar issue too, I will check my project files again.

Great. I’m glad it helped you too. Thanks for letting me know. No, sorry, I don’t recall seeing that error. Best of luck with that one too.