Porting Autogenerated C code from Deep learning toolbox to embedded environment

5 views (last 30 days)
In ANN Auto C code all matrices are appearing as Static const variables which means that they will be RAM. These variables need to be in FLASH and always read from FLASH due to limitations in RAM size. How is it possible to customise the autocode from Matlab scripts to achieve this ?
Are there are any code generation configuration which allows us to achieve this ?
Please note that I am using MATLAB coder and M-scripts (not SIMULINK)

Accepted Answer

Ram Kokku
Ram Kokku on 6 Feb 2025
Moved: Walter Roberson on 6 Feb 2025
@Nitin Skandan, mapping constants to hardware depends on the backend C/C++ compiler. MATLAB Coder allows customization of deep learning constant generation using the config option LargeConstantGeneration ( https://www.mathworks.com/help/coder/ref/coder.codeconfig.html ). If this does not meet your requirements, please provide an example code snippet that describes your requirements.
  2 Comments
Nitin Skandan
Nitin Skandan on 6 Feb 2025
Moved: Walter Roberson on 6 Feb 2025
Will try with LargeConstantGeneration options. But looks like this will help us seggregate the weights from the C Source files .
Nitin Skandan
Nitin Skandan on 13 Mar 2025
Hi I have been able to generate NN weight as a separate bin file. In the autocode it now generates
static void readDnnConstants(real32_T *inputBufferPtr,
const char_T *unresolvedFilePath,
int32_T numElementsToRead)
{
int32_T elementSizeInBytes;
const char_T *fileOpenMode;
char_T *resolvedFilePath;
FILE *filePtr;
void *dataBufferPtr;
resolvedFilePath = getResolvedFilePath(unresolvedFilePath);
fileOpenMode = "rb";
filePtr = fopen(resolvedFilePath, (char_T *)fileOpenMode);
dataBufferPtr = &inputBufferPtr[0];
elementSizeInBytes = 4;
fread(dataBufferPtr, elementSizeInBytes, numElementsToRead, filePtr);
fclose(filePtr);
free(resolvedFilePath);
}
we dont want this bit of code to be generated as the bin will be hosted inside our OBC filesystem and we will be using our OSAL calls and can provide inputBufferPtr . How this is possible without manually editing the autocode ?

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!