[µTVM] Print .elf statistics for a model runtime built with Zephyr#7449
Merged
Conversation
Currently there isn't any statistics about the used resources by a model runtime built with Zephyr, making it difficult to have any idea about, for instance, the amount of memory taken by the operations necessary to run the model. Since Zephyr's SDK already exposes the statistics about various memory regions on linking by passing '--print-memory-usage' to the linker, it's possible to use it to have an idea about the amount of memory used by the model and how much memory is left on the device. That commit adds a simple method to extract the memory region information out of the build output and then uses it to show memory usage statistics for various memory regions when Zephyr finishes building the image to be flashed to the target device. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Contributor
Author
areusch
requested changes
Feb 12, 2021
| return tvm.micro.MicroLibrary(build_dir, [f"lib{project_name}.a"]) | ||
|
|
||
| def _print_make_statistics(self, output): | ||
| print("==================") |
Contributor
There was a problem hiding this comment.
want to print this after you see "Memory region"?
Contributor
Author
There was a problem hiding this comment.
sure! Now the output looks like:
INFO:tvm.micro.contrib.zephyr:Memory region Used Size Region Size %age Used
INFO:tvm.micro.contrib.zephyr:--------------------- ---------- ------------ ---------
INFO:tvm.micro.contrib.zephyr: FLASH: 35748 B 1 MB 3.41%
INFO:tvm.micro.contrib.zephyr: DTCM: 0 GB 64 KB 0.00%
INFO:tvm.micro.contrib.zephyr: SRAM: 146160 B 256 KB 55.76%
INFO:tvm.micro.contrib.zephyr: IDT_LIST: 232 B 2 KB 11.33%
| print("==================") | ||
| output = output.splitlines() | ||
| lines = iter(output) | ||
| for line in lines: |
Contributor
There was a problem hiding this comment.
could you catch StopIteration somewhere so that in the event the output looks weird, this doesn't break the compilation flow?
| for line in lines: | ||
| if line.startswith("Memory region"): | ||
| # print statistics header | ||
| print(line) |
Contributor
There was a problem hiding this comment.
it might be better to use _LOG.info() rather than print, so it could be suppressed if needed
Contributor
Author
There was a problem hiding this comment.
done. @areusch Thanks a lot for the review.
- Catch StopIteration in case of a weird output or no additional lines after the last memory region - Use of _LOG.info() instead of plain print() for better control over the output by the main script - Set log level in micro_tflite.py script as an example on how to get the new memory usage statistics and also because currently that's the main script used to test microTVM + Zephyr's SDK - Improve statistics header Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
areusch
approved these changes
Feb 12, 2021
Contributor
Author
|
@tmoreau89 Hi. Could you please merge it? |
Contributor
Author
|
@tmoreau89 thanks for the review and for merging it! |
Lokiiiiii
pushed a commit
to Lokiiiiii/tvm
that referenced
this pull request
Mar 2, 2021
…pache#7449) * [µTVM] Print .elf statistics for a model runtime built with Zephyr Currently there isn't any statistics about the used resources by a model runtime built with Zephyr, making it difficult to have any idea about, for instance, the amount of memory taken by the operations necessary to run the model. Since Zephyr's SDK already exposes the statistics about various memory regions on linking by passing '--print-memory-usage' to the linker, it's possible to use it to have an idea about the amount of memory used by the model and how much memory is left on the device. That commit adds a simple method to extract the memory region information out of the build output and then uses it to show memory usage statistics for various memory regions when Zephyr finishes building the image to be flashed to the target device. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * v2: Fixes accordingly to Andrew review - Catch StopIteration in case of a weird output or no additional lines after the last memory region - Use of _LOG.info() instead of plain print() for better control over the output by the main script - Set log level in micro_tflite.py script as an example on how to get the new memory usage statistics and also because currently that's the main script used to test microTVM + Zephyr's SDK - Improve statistics header Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * Fix build It seems build system is using Python < 3.7, so 'text' argument is not present as an alias for 'universal_newlines'. To satisfy it use old 'universal_newlines' argument which is available prior to Python 3.7. * Fix build Avoid exception anti-pattern when catching StopIteration * Retrigger CI
trevor-m
pushed a commit
to neo-ai/tvm
that referenced
this pull request
Mar 2, 2021
…pache#7449) * [µTVM] Print .elf statistics for a model runtime built with Zephyr Currently there isn't any statistics about the used resources by a model runtime built with Zephyr, making it difficult to have any idea about, for instance, the amount of memory taken by the operations necessary to run the model. Since Zephyr's SDK already exposes the statistics about various memory regions on linking by passing '--print-memory-usage' to the linker, it's possible to use it to have an idea about the amount of memory used by the model and how much memory is left on the device. That commit adds a simple method to extract the memory region information out of the build output and then uses it to show memory usage statistics for various memory regions when Zephyr finishes building the image to be flashed to the target device. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * v2: Fixes accordingly to Andrew review - Catch StopIteration in case of a weird output or no additional lines after the last memory region - Use of _LOG.info() instead of plain print() for better control over the output by the main script - Set log level in micro_tflite.py script as an example on how to get the new memory usage statistics and also because currently that's the main script used to test microTVM + Zephyr's SDK - Improve statistics header Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> * Fix build It seems build system is using Python < 3.7, so 'text' argument is not present as an alias for 'universal_newlines'. To satisfy it use old 'universal_newlines' argument which is available prior to Python 3.7. * Fix build Avoid exception anti-pattern when catching StopIteration * Retrigger CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
Could the following simple change be reviewed please?
Currently there isn't any statistics about the used resources by a model
runtime built with Zephyr, making it difficult to have any idea about, for
instance, the amount of memory taken by the operations necessary to run the
model.
Since Zephyr's SDK already exposes the statistics about various memory
regions on linking by passing '--print-memory-usage' to the linker, it's
possible to use it to have an idea about the amount of memory used by the
model and how much memory is left on the device.
That commit adds a simple method to extract the memory region information
out of the build output and then uses it to show memory usage statistics
for various memory regions when Zephyr finishes building the image to be
flashed to the target device.
Output example follows:
Thanks & best regards,
Gustavo