cancel
Showing results for 
Search instead for 
Did you mean: 

Used Ram over External SDRAM and TFlite Micro runtime

pepsi_zero_sugar
Associate II

It seems like a used ram size fit to External SDRAM in STM32H757i- EVAL Board.
However, I can see the error when doing analyze.

Also, I cannot see any TFLite Micro runtime generated code.
I can see empty function.
I was totally fine with STM32CUBE AI runtime.

pepsi_zero_sugar_1-1724297824905.png

 

pepsi_zero_sugar_0-1724297679218.png

pepsi_zero_sugar_2-1724297847147.png

pepsi_zero_sugar_3-1724297983155.png

pepsi_zero_sugar_4-1724298006088.png

 

5 REPLIES 5
fauvarque.daniel
ST Employee

You have to select the Template code, System performance application or Validation application to have code generated in those sections


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

I selected the Validation application.

I was wondering if TFlite model Used Ram: 1.29MiB, then MCU need x10 size RAM?
It is showing that 1.29 MiB. However, 8 MiB External SDRAM is not enough.

 

with tflite runtime we don't manage automatically the use of external RAM.

That said you can generate the code and modify the linker script to place the activation buffer in external sdram (with of course an impact on the performance)

Regards


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Thanks for your reply.

Is there any way to make a network_data.bin manually?

I would like to flash the network_data.bin file to external memory using STMCubeProgrammer.
However, STM32CubeMX cannot convert my model to .bin File.

I wrote a code to use the external flash and the sdram. However, I failed when doing aiBootstrap
Could you check whether it is right or not

1. External SDRAM (linker script, code)

MEMORY
{
  RAM_D1 (xrw)   : ORIGIN = 0x24000000, LENGTH =  512K
  FLASH   (rx)   : ORIGIN = 0x08000000, LENGTH = 1024K    /* Memory is divided. Actual start is 0x08000000 and actual length is 2048K */
  DTCMRAM (xrw)  : ORIGIN = 0x20000000, LENGTH = 128K
  RAM_D2 (xrw)   : ORIGIN = 0x30000000, LENGTH = 288K
  RAM_D3 (xrw)   : ORIGIN = 0x38000000, LENGTH = 64K
  ITCMRAM (xrw)  : ORIGIN = 0x00000000, LENGTH = 64Kf
  SDRAM (xrw)     : ORIGIN = 0xD0000000, LENGTH = 8M
}

  .sdram_section (NOLOAD):
  {
    . = ALIGN(4);
    *(.Tensor_Arena)
    *(.Tensor_Arena*)
    . = ALIGN(4);
  } >SDRAM

#if defined(__ICCARM__)
#pragma location = "Tensor_Arena"
#pragma data_alignment=4
#elif defined(__CC_ARM)
__attribute__((section(".Tensor_Arena"), zero_init))
__attribute__ ((aligned (4)))
#elif defined(__GNUC__)
__attribute__((section(".Tensor_Arena")))
__attribute__ ((aligned (4)))
#else
#error Unknown compiler
#endif
MEM_ALIGNED(4)
static uint8_t tensor_arena[TFLM_NETWORK_TENSOR_AREA_SIZE+32];

  

2.I programmed network_data.bin(tflite)  External Flash (0x90000000)

pepsi_zero_sugar_0-1724885829782.png

3. set memory address

#include <stdint.h>
#include <network_tflite_data.h>

#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __has_attribute
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
#else
#define HAVE_ATTRIBUTE(x) 0
#endif
#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4)))
#else
#define DATA_ALIGN_ATTRIBUTE
#endif

const uint8_t * g_tflm_network_model_data DATA_ALIGN_ATTRIBUTE = (uint8_t *)0x90000000;
const int g_tflm_network_model_data_len = 4065740;
#ifdef __cplusplus
}
#endif

 

4. It is failed when create tensor. 

static int aiBootstrap(struct tflm_context *ctx)
{
  TfLiteStatus res;
  struct tflm_c_version ver;

  /* Creating an instance of the network ------------------------- */
  LC_PRINT("\r\nInstancing the network (TFLM)..\r\n");

  /* TFLm runtime expects that the tensor arena is aligned on 16-bytes */
  uint32_t uaddr = (uint32_t)tensor_arena;
  uaddr = (uaddr + (16 - 1)) & (uint32_t)(-16);  // Round up to 16-byte boundary

  MON_ALLOC_RESET();
  MON_ALLOC_ENABLE();
  
   //res is not okay.
  res = tflm_c_create(g_tflm_network_model_data, (uint8_t*)uaddr,
          TFLM_NETWORK_TENSOR_AREA_SIZE, &ctx->hdl);

  MON_ALLOC_DISABLE();

  if (res != kTfLiteOk) {
    ctx->hdl = 0;
    ctx->error = -1;
    return -1;
  }
}