liangfu commented on a change in pull request #5417:
URL: https://github.com/apache/incubator-tvm/pull/5417#discussion_r417774863
##########
File path: python/tvm/micro/base.py
##########
@@ -133,44 +152,91 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
self._exit()
-def create_micro_mod(c_mod, dev_config):
+def _calc_max_workspace_usage(src):
+ # TODO factor in alignment to the calculation (alloc sizes will be aligned
up to the word size)
+ alloc_re = re.compile(
+ r'.*\* ?(.+) = (\(.+\))? TVMBackendAllocWorkspace\(.+, .+,
\(uint64_t\)(.+), .+, .+\).*')
+ free_re = re.compile(r'.*if \(TVMBackendFreeWorkspace\(.+, .+,
(\(void\*\))? (.+)\) != 0\) {.*')
+ max_usage = 0
+ alloc_map = {}
+ for line in src.split("\n"):
+ if line.strip().startswith("//"):
+ continue
+ match = alloc_re.match(line)
+ if match is not None:
+ alloc_map[match.group(1)] = int(match.group(3))
+ max_usage = max(max_usage, sum(alloc_map.values()))
+ else:
+ match = free_re.match(line)
+ if match is not None:
+ print(alloc_map)
+ del alloc_map[match.group(2)]
+ return max_usage
+
+
+def create_micro_mod(c_mod, dev_config, lib_src_paths=None, lib_headers=None,
+ lib_include_paths=None):
"""Produces a micro module from a given module.
Parameters
----------
- c_mod : tvm.runtime.Module
+ c_mod : tvm.module.Module
module with "c" as its target backend
- dev_config : Dict[str, Any]
- MicroTVM config dict for the target device
+ lib_src_paths: TODO
+ TODO
+
+ lib_headers: TODO
+ TODO
+
+ lib_include_paths: TODO
+ TODO
Return
------
- micro_mod : tvm.runtim.Module
+ micro_mod : tvm.module.Module
micro module for the target device
"""
temp_dir = _util.tempdir()
lib_obj_path = temp_dir.relpath("dev_lib.obj")
+ # TODO use dev config to dispatch on the type of C codegen to run through
+ # (e.g., CodeGenCArm, CodeGenCHost, CodeGenCRiscV)
c_mod.export_library(
lib_obj_path,
- fcompile=cross_compiler(dev_config, LibType.OPERATOR))
+ fcompile=cross_compiler(
+ dev_config,
+ LibType.OPERATOR,
+ lib_src_paths=lib_src_paths,
+ lib_headers=lib_headers,
+ lib_include_paths=lib_include_paths))
micro_mod = tvm.runtime.load_module(lib_obj_path)
return micro_mod
-def cross_compiler(dev_config, lib_type):
- """Create a cross-compile function that wraps `create_lib` for a `Binutil`
instance.
+def cross_compiler(dev_config, lib_type, lib_src_paths=None, lib_headers=None,
+ lib_include_paths=None):
+ """Create a cross compile function that wraps `create_lib` for a `Binutil`
instance.
For use in `tvm.runtime.Module.export_library`.
Parameters
----------
- dev_config : Dict[str, Any]
- MicroTVM config dict for the target device
+ create_micro_lib : func
+ function for creating MicroTVM libraries for a specific device (e.g.,
+
`tvm.micro.device.get_device_funcs('arm.stm32f746xx')['create_micro_lib']`)
lib_type : micro.LibType
whether to compile a MicroTVM runtime or operator library
+ lib_src_paths: TODO
+ TODO
+
+ lib_headers: TODO
+ e.g., `['cmsis_gcc.h', 'arm_math.h']`
+
+ lib_include_paths: TODO
Review comment:
Please add a meaningful comment here.
##########
File path: python/tvm/micro/device/riscv_spike.py
##########
@@ -62,56 +78,31 @@ def default_config(base_addr, server_addr, server_port):
server_port : int
port of OpenOCD server to connect to
+ TODO correct type annotation?
+ section_constraints: Optional[Dict[str, Tuple[Number, MemConstraint]]]
+ TODO
Review comment:
leave a meaningful comment
##########
File path: python/tvm/micro/device/arm/stm32f746xx.py
##########
@@ -36,23 +55,40 @@ def create_micro_lib(obj_path, src_path, lib_type,
options=None):
options : Optional[List[str]]
additional options to pass to GCC
+
+ lib_src_paths : Optional[List[str]]
+ TODO
Review comment:
Please put a meaningful comment here as well.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]