analogdevicesinc / ai8x-synthesis

Quantization and Synthesis (Device Specific Code Generation) for ADI's MAX78000 and MAX78002 Edge AI Devices
Apache License 2.0
55 stars 50 forks source link

MAX78000 tinySSD yaml file memory question #328

Closed michame951 closed 6 months ago

michame951 commented 8 months ago

Hello! This is my first time using MAX78000. I saw the sample code for TinySSD, but I don't know how to calculate the memory allocation for each tier. I think it should be CNN.C that displays the data configuration of each layer. image

This should correspond to the layer offset for each layer of the YAML file. https://github.com/MaximIntegratedAI/ai8x-synthesis/blob/develop/networks/svhn-tinierssd.yaml

Below is my question

  1. Could you please tell me how to give the address of offset for each layer? How to plan it?
  2. Why does layer0 need to set out_offset and in_offset at the beginning? image
  3. The data entered into Layer0 at the beginning is 3x74x74 = 16428 = 0x402C. So the memory occupied is 0x50402000+0x402C = 0x5040 602C?
  4. Why is layer2 out_offset changed to 0x1000? image

Thank you very much for your help.

ermanok commented 8 months ago

Hello michame951,

Here are the answers to your questions:

  1. The _inoffset and _outoffset of a layer specifies the memory offset of the input and the output data of a layer. These offset values are determined according to the processors and the _outputprocessors of the layer. While determining these values, the easiest way is setting the offsets such that the input and output data do not coincide with each other. There are two ways to ensure this:
    • Using different processors and _outputprocessors
    • Setting enough gap between _inoffset and _outoffset. For instance if the input data is 32x32 and _inoffset is 0x2000, the _outoffset should be at least 0x2000 + 0x1000 (=32x32x4) = 0x3000. For some cases, the _inoffset and _outoffset should coincide, due to the data size and memory limitations. In this case, the hardware should consume the part of the input data before writing the output on that memory location. This is something hard to guess before making some tests on the hardware. Running Known Answer Tests (KAT) to set the _inoffset and _outoffset is the best approach in such situations.
  2. _inoffset is not necessary in this case. The default value of the _inoffset for the initial layer is 0 (see here). I think the model still works if you delete that line..
  3. The data is stored in HWC format and each memory block stores 4 channel of the data. So each pixel data in a memory block is represented by 4 bytes. If the number of channels in any memory block is less than 4, each pixel still uses 4 bytes with unused bytes. So, for your question the answer is 0x50402000+0x5590(=4x74x74) = 0x50407590.
  4. This question is partly answered by Q1. The layer uses same input and output processors, so if the _outoffset is not properly set, the layer can write the output data on the input data before consuming, which yields wrong output values. Then, the _outoffset should be different than the _inoffset. As the input data spans from the address 0x2000 to the end of the memory space (0x8000), the _outoffset is set to a lower memory address (0x1000).

You can also find more information about the data memory of the CNN layers in the documentation.

michame951 commented 7 months ago

Hi @ermanok , Got it, thanks for your support.

github-actions[bot] commented 6 months ago

This issue has been marked stale because it has been open for over 30 days with no activity. It will be closed automatically in 10 days unless a comment is added or the "Stale" label is removed.