tum-ei-eda / mlonmcu

Tool for the deployment and analysis of TinyML applications on TFLM and MicroTVM backends
Apache License 2.0
29 stars 12 forks source link

Static Memory Usage - Update ELF sections #24

Closed PhilippvK closed 1 year ago

PhilippvK commented 2 years ago

For calculating the static ROM/RAM usage on non-ETISS targets, I have created mlonmcu/target/elf.py heavily inspired by ETISS get_metrics.py.

However as we are now also targeting ARM and x86 we will very likely miss some important ELF sections.

PhilippvK commented 2 years ago

Currently explicitly ignored sections:

.stack
.comment
.riscv.attributes
.strtab
.shstrtab

Missing sections on etiss_pulpino:

INFO - ignored: .symtab / size: 8384

Missing sections on spike/ovpsim:

INFO - ignored: .eh_frame / size: 4
INFO - ignored: .fini_array / size: 4
INFO - ignored: .symtab / size: 9520

Missing sestions on host_x86:

INFO - ignored: .interp / size: 28
INFO - ignored: .note.gnu.property / size: 32
INFO - ignored: .note.gnu.build-id / size: 36
INFO - ignored: .note.ABI-tag / size: 32
INFO - ignored: .gnu.hash / size: 36
INFO - ignored: .dynsym / size: 264
INFO - ignored: .dynstr / size: 195
INFO - ignored: .gnu.version / size: 22
INFO - ignored: .gnu.version_r / size: 96
INFO - ignored: .rela.dyn / size: 240
INFO - ignored: .rela.plt / size: 120
INFO - ignored: .init / size: 27
INFO - ignored: .plt / size: 96
INFO - ignored: .plt.got / size: 16
INFO - ignored: .plt.sec / size: 80
INFO - ignored: .fini / size: 13
INFO - ignored: .eh_frame_hdr / size: 364
INFO - ignored: .eh_frame / size: 1512
INFO - ignored: .fini_array / size: 8
INFO - ignored: .dynamic / size: 512
INFO - ignored: .got / size: 104
INFO - ignored: .symtab / size: 4488

Missing section on corstone300:

INFO - ignored: .ARM.exidx / size: 8
INFO - ignored: .copy.table / size: 12
INFO - ignored: .zero.table / size: 0
INFO - ignored: .sram / size: 0
INFO - ignored: .heap / size: 32768
INFO - ignored: .ARM.attributes / size: 42
INFO - ignored: .stab / size: 60
INFO - ignored: .stabstr / size: 118
INFO - ignored: .symtab / size: 20704
PhilippvK commented 2 years ago

After a quick inspection we shoould at least properly detect the following sections as they have a non-neglectable size:

rafzi commented 2 years ago

This should be decided based on which sections would be required for a minimal functioning deployment.

For example:

ignore:

symtab, all of the extra ARM sections?

count:

eh_frame, fini_array

eh_frame is unexpected because we compile most code without exceptions enabled. Are we missing something? Would they even work if our main code does not support them? In that case they can also be ignored.

We don't use the heap of the CRT so I don't think we would need to deploy the ARM heap section.

x86 is a special case because we run on an operating system with a complex dynamic loader that requires way more than what would be necessary on bare metal. We can just keep it as is to have a roughly accurate representation but these numbers will not be very useful for tinyml evaluation anyways.

PhilippvK commented 2 years ago

I am in the process of integrating support for ESP32/ESP32C3 targets. Here are the memory segments used in the ELF:

WARNING - ignored: .rtc.text / size: 16
WARNING - ignored: .rtc.force_fast / size: 0
WARNING - ignored: .rtc.data / size: 16
WARNING - ignored: .rtc_noinit / size: 0
WARNING - ignored: .rtc.force_slow / size: 0
WARNING - ignored: .iram0.text / size: 32004
WARNING - ignored: .dram0.dummy / size: 32256
WARNING - ignored: .dram0.data / size: 3140
WARNING - ignored: .noinit / size: 0
WARNING - ignored: .dram0.bss / size: 6960
WARNING - ignored: .flash.text / size: 75412
WARNING - ignored: .flash_rodata_dummy / size: 131072
WARNING - ignored: .flash.appdesc / size: 256
WARNING - ignored: .flash.rodata / size: 554504
WARNING - ignored: .eh_frame / size: 0
WARNING - ignored: .flash.rodata_noload / size: 0
WARNING - ignored: .iram0.text_end / size: 252
WARNING - ignored: .iram0.data / size: 0
WARNING - ignored: .iram0.bss / size: 0
WARNING - ignored: .dram0.heap_start / size: 0
WARNING - ignored: .symtab / size: 52512

Instead of .text, .bss,... ESP-IDF uses .flash*, .iram,... - We need to find a fair mapping for these to enable comparisons between different platforms!

PhilippvK commented 2 years ago

I tried to map all of those in elf.py.

@rafzi What do you think about .iram.text, .iram.data and .iram.bss? Code could be split up over flash and instruction RAM, so should be still add .iram.text to rom_code?

rafzi commented 2 years ago

I'm not sure how the flash and boot process works for these. I guess text and data need to be stored in full in flash and then text would be loaded into iram during boot? The bss would not need storage space, but I assume it still has to occupy its whole space, because there would otherwise not be any information about it