cancel
Showing results for 
Search instead for 
Did you mean: 

Deploying Multiple X-CUBE-AI Models on STM32: Input Sharing & API Management Best Practices?

Stone_chan
Associate

Hello everyone,
I’m currently deploying multiple models on STM32 using X-CUBE-AI (for example: first using an MLP for a coarse classification “Gas / Not Gas”, then a second model for detailed gas class identification). I’d like to ask about two main topics:

 

Question 1: If multiple models have the same input shape/size, can they “share the same input buffer”?

  • Both models have identical input dimensions, data type (float32), and layout (e.g. 1x60 vector).

  • I’d like to point both models’ ai_buffer.data to the same float in[60], then call ai_*_run sequentially (never in parallel).

  • Is this approach safe/supported in X-CUBE-AI? Could any model overwrite the input buffer during inference (theoretically it shouldn’t, but I’d like to confirm with ST/others)

 

Question 2: What is the best way to use and manage APIs with multiple models?

When two (or more) models coexist on the same MCU:

A. Keep completely separate weights[] and activations[] (independent), each with its own create/init/run/destroy.
B. Is it possible/recommended to share the activation memory (only when models run sequentially)? If yes, is this officially supported and safe?

Regarding ai_mnetwork (multi-model manager) and accessing the models’ native I/O descriptors:

  • My understanding: I can use ai_mnetwork_get_private_handle() to obtain each sub-model’s private handle, then call ai_<model>_inputs_get() / ai_<model>_outputs_get() to retrieve the native ai_buffer arrays, avoiding manual shape/format filling.

  • Is this the officially recommended workflow? Or is it better practice to use the report structure and manually fill shapes and formats?

 

 

Summary of What I’d Like to Confirm:

  1. Is input buffer sharing safe and supported when models are executed sequentially?

  2. For outputs with different formats (float, int, logits, one-hot), is it always recommended to rely on *_get_report() or *_outputs_get() instead of hardcoding?

  3. Can activations be shared safely between models if they are strictly serialized? Any official examples or caveats?

  4. Is using ai_mnetwork the recommended way to manage multiple models (vs. manually handling multiple sets of ai_buffer)?

Thanks a lot for any guidance, best practices, or references to official examples/docs!

Stone_chan_0-1755322441064.pngStone_chan_1-1755322465443.pngStone_chan_2-1755322476560.png

Stone_chan_3-1755322527546.png

Stone_chan_4-1755322539176.png

 

1 REPLY 1
Stone_chan
Associate

And How to use the  second  model , It would be better if there is a example code