Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[µTVM] Print .elf statistics for a model runtime built with Zephyr #7449

Merged
merged 5 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions python/tvm/micro/contrib/zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run(self, cmd, **kw):
for k, v in self.default_overrides.items():
env[k] = v

return subprocess.check_output(cmd, env=env, **kw)
return subprocess.check_output(cmd, env=env, **kw, universal_newlines=True)


class ProjectNotFoundError(Exception):
Expand Down Expand Up @@ -204,6 +204,25 @@ def library(self, output, sources, options=None):
)
return tvm.micro.MicroLibrary(build_dir, [f"lib{project_name}.a"])

def _print_make_statistics(self, output):
output = output.splitlines()
lines = iter(output)
for line in lines:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you catch StopIteration somewhere so that in the event the output looks weird, this doesn't break the compilation flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if line.startswith("Memory region"):
# print statistics header
_LOG.info(line)
_LOG.info("--------------------- ---------- ------------ ---------")
line = next(lines)
# while there is a region print it
try:
while ":" in line:
_LOG.info(line)
line = next(lines)
else:
break
except StopIteration:
pass

def binary(self, output, objects, options=None, link_main=True, main_options=None):
assert link_main, "Must pass link_main=True"
assert self._project_dir is not None, "Must supply project_dir= to build binaries"
Expand All @@ -224,7 +243,9 @@ def binary(self, output, objects, options=None, link_main=True, main_options=Non
cmake_args.append(f'-DTVM_LIBS={";".join(copied_libs)}')
self._subprocess_env.run(cmake_args, cwd=output)

self._subprocess_env.run(["make"], cwd=output)
make_output = self._subprocess_env.run(["make"], cwd=output)

self._print_make_statistics(make_output)

return tvm.micro.MicroBinary(
output,
Expand Down
6 changes: 6 additions & 0 deletions tutorials/micro/micro_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@

import os
import numpy as np
import logging

import tvm
import tvm.micro as micro
from tvm.contrib.download import download_testdata
Expand Down Expand Up @@ -227,6 +229,10 @@
# )
#
# opts = tvm.micro.default_options(f"{project_dir}/crt")
#
# enable printing memory usage statistics of the runtime image
# generated by Zephyr compiler for the physical hardware
# logging.basicConfig(level="INFO")

workspace = tvm.micro.Workspace()
micro_binary = tvm.micro.build_static_runtime(
Expand Down