Skip to content

Split tensor arena into persistent and non-persistent arenas#164

Open
andresovela wants to merge 5 commits intoxmos:developfrom
andresovela:split-tensor-arenas
Open

Split tensor arena into persistent and non-persistent arenas#164
andresovela wants to merge 5 commits intoxmos:developfrom
andresovela:split-tensor-arenas

Conversation

@andresovela
Copy link
Contributor

This PR is an attempt to fix xmos/ai_tools#908

I renamed the SHARED_TENSOR_ARENA definition to EXTERN_TENSOR_ARENA, and I added a new SPLIT_PERSISTENT_TENSOR_ARENA definition.

This PR adds the following when SPLIT_PERSISTENT_TENSOR_ARENA is defined:

  • A new extern uint8_t persistent_tensor_arena[]; declaration
  • Code uses this new buffer only when defined

I had initially renamed tensor_arena to non_persistent_tensor_arena, but I found that I had to generate the huge tflTensors[] array twice just because of the new name, so I decided against it. The code would have looked like this otherwise:

#ifdef SPLIT_PERSISTENT_TENSOR_ARENA
TfLiteTensor tflTensors[] = 
{{ {(int32_t*)(non_persistent_tensor_arena + 26112)},(TfLiteIntArray*)&g0.tensor_dimension0, kTfLiteInt8, {kTfLiteAffineQuantization, const_cast<void*>(static_cast<const void*>(&g0.quant0)) }, {g0.quant0.scale->data[0], g0.quant0.zero_point->data[0] },64, kTfLiteArenaRw, false, },
.
.
.
};
#else
TfLiteTensor tflTensors[] = 
{{ {(int32_t*)(tensor_arena + 26112)},(TfLiteIntArray*)&g0.tensor_dimension0, kTfLiteInt8, {kTfLiteAffineQuantization, const_cast<void*>(static_cast<const void*>(&g0.quant0)) }, {g0.quant0.scale->data[0], g0.quant0.zero_point->data[0] },64, kTfLiteArenaRw, false, },
.
.
.
};
#endif

I haven't been able to test if this would work or not, I just wrote the code for now.

@andresovela
Copy link
Contributor Author

andresovela commented Jul 17, 2024

Note that if this gets merged we would need to update the app_flash_two_models_one_arena example

@andresovela
Copy link
Contributor Author

I was able to test this feature. See this comment for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for splitting tensor arena into persistent/non-persistent arenas

1 participant