tvm.micro¶
MicroTVM module for bare-metal backends
Functions:
A dummy build function which causes autotvm to use a different export format. |
|
Find the standalone_crt directory. |
|
|
Find microTVM template project directory for specific platform. |
|
Copy crt_config header file for a platform to destinatin. |
|
Export the build artifact in Model Library Format. |
|
Generate a project for an embedded platform that contains the given model. |
|
Create a local graph executor driving execution on the remote CPU device given. |
|
Create a local debug runtime driving execution on the remote CPU device given. |
|
Create a local AoT executor driving execution on the remote CPU device given. |
Classes:
|
MicroTVM AutoTVM Module Loader |
|
Defines a glue interface to interact with a generated project through the API server. |
|
Defines a glue interface to interact with a template project through the API Server. |
|
MicroTVM Device Session |
|
Wraps a Transport implementation and logs traffic to the Python logging infrastructure. |
Exceptions:
Raised when export_model_library_format does not support the given Module tree. |
|
Raised when a transport read operation discovers that the remote session is terminated. |
- tvm.micro.autotvm_build_func()¶
A dummy build function which causes autotvm to use a different export format.
- class tvm.micro.AutoTvmModuleLoader(template_project_dir: Union[os.PathLike, str], project_options: Optional[dict] = None, project_dir: Optional[Union[os.PathLike, str]] = None, use_existing: bool = False)¶
MicroTVM AutoTVM Module Loader
- Parameters
template_project_dir (Union[os.PathLike, str]) – project template path
project_options (dict) – project generation option
project_dir (str) – if use_existing is False: The path to save the generated microTVM Project. if use_existing is True: The path to a generated microTVM Project for debugging.
use_existing (bool) – skips the project generation and opens transport to the project at the project_dir address.
- tvm.micro.get_standalone_crt_dir() str ¶
Find the standalone_crt directory.
Though the C runtime source lives in the tvm tree, it is intended to be distributed with any binary build of TVM. This source tree is intended to be integrated into user projects to run models targeted with –runtime=c.
- Returns
The path to the standalone_crt
- Return type
- tvm.micro.get_microtvm_template_projects(platform: str) str ¶
Find microTVM template project directory for specific platform.
- tvm.micro.copy_crt_config_header(platform: str, output_path: pathlib.Path)¶
Copy crt_config header file for a platform to destinatin.
- Parameters
platform (str) – Platform type which should be defined in MicroTVMTemplateProject.
output_path (Path) – Output path for crt_config header file.
- tvm.micro.export_model_library_format(mods: Union[tvm.driver.build_module.OperatorModule, tvm.relay.backend.executor_factory.AOTExecutorFactoryModule, tvm.relay.backend.executor_factory.GraphExecutorFactoryModule, List[Union[tvm.driver.build_module.OperatorModule, tvm.relay.backend.executor_factory.AOTExecutorFactoryModule, tvm.relay.backend.executor_factory.GraphExecutorFactoryModule]]], file_name: Union[str, pathlib.Path])¶
Export the build artifact in Model Library Format.
This function creates a .tar archive containing the build artifacts in a standardized layout. It’s intended to allow downstream automation to build TVM artifacts against the C runtime.
- exception tvm.micro.UnsupportedInModelLibraryFormatError¶
Raised when export_model_library_format does not support the given Module tree.
- tvm.micro.generate_project(template_project_dir: Union[pathlib.Path, str], module: Union[tvm.driver.build_module.OperatorModule, tvm.relay.backend.executor_factory.AOTExecutorFactoryModule, tvm.relay.backend.executor_factory.GraphExecutorFactoryModule], generated_project_dir: Union[pathlib.Path, str], options: Optional[dict] = None)¶
Generate a project for an embedded platform that contains the given model.
- Parameters
template_project_path (pathlib.Path or str) – Path to a template project containing a microTVM Project API server.
generated_project_path (pathlib.Path or str) – Path to a directory to be created and filled with the built project.
module (ExportableModule) – A runtime.Module exportable as Model Library Format. The value returned from tvm.relay.build or tvm.build.
options (dict) – If given, Project API options given to the microTVM API server found in both template_project_path and generated_project_path.
- Returns
A class that wraps the generated project and which can be used to further interact with it.
- Return type
- class tvm.micro.GeneratedProject(api_client, options)¶
Defines a glue interface to interact with a generated project through the API server.
- class tvm.micro.TemplateProject(api_client)¶
Defines a glue interface to interact with a template project through the API Server.
Methods:
Generate a project from MLF file.
generate_project
(graph_executor_factory, ...)Generate a project given GraphRuntimeFactory.
- generate_project_from_mlf(model_library_format_path, project_dir, options: dict)¶
Generate a project from MLF file.
- generate_project(graph_executor_factory, project_dir, options)¶
Generate a project given GraphRuntimeFactory.
- tvm.micro.create_local_graph_executor(graph_json_str, mod, device)¶
Create a local graph executor driving execution on the remote CPU device given.
- Parameters
graph_json_str (str) – A string containing the graph representation.
mod (tvm.runtime.Module) – The remote module containing functions in graph_json_str.
device (tvm.runtime.Device) – The remote CPU execution device.
- Returns
A local graph executor instance that executes on the remote device.
- Return type
tvm.contrib.GraphExecutor
- tvm.micro.create_local_debug_executor(graph_json_str, mod, device, dump_root=None)¶
Create a local debug runtime driving execution on the remote CPU device given.
- Parameters
graph_json_str (str) – A string containing the graph representation.
mod (tvm.runtime.Module) – The remote module containing functions in graph_json_str.
device (tvm.runtime.Device) – The remote CPU execution device.
dump_root (Optional[str]) – If given, passed as dump_root= to GraphModuleDebug.
- Returns
A local graph executor instance that executes on the remote device.
- Return type
tvm.contrib.GraphExecutor
- tvm.micro.create_local_aot_executor(session: tvm.micro.session.Session)¶
Create a local AoT executor driving execution on the remote CPU device given.
- Parameters
session (Session) – A microTVM device session.
- Returns
A local AoT executor instance that executes on the remote device.
- Return type
tvm.runtime.executor.aot_executor.AotModule
- class tvm.micro.Session(transport_context_manager=None, session_name='micro-rpc', timeout_override=None)¶
MicroTVM Device Session
- Parameters
config (dict) – configuration for this session (as generated by tvm.micro.device.host.default_config(), for example)
Example
c_mod = ... # some module generated with "c" as the target dev_config = micro.device.arm.stm32f746xx.default_config('127.0.0.1', 6666) with tvm.micro.Session(dev_config) as sess: micro_mod = sess.create_micro_mod(c_mod)
- exception tvm.micro.SessionTerminatedError¶
Raised when a transport read operation discovers that the remote session is terminated.
- class tvm.micro.TransportLogger(name, child, logger=None, level=20)¶
Wraps a Transport implementation and logs traffic to the Python logging infrastructure.
Methods:
timeouts
()Return TransportTimeouts suitable for use with this transport.
open
()Open any resources needed to send and receive RPC protocol data for a single session.
close
()Release resources associated with this transport.
read
(n, timeout_sec)Read up to n bytes from the transport.
write
(data, timeout_sec)Write data to the transport channel.
- timeouts()¶
Return TransportTimeouts suitable for use with this transport.
See the TransportTimeouts documentation in python/tvm/micro/session.py.
- open()¶
Open any resources needed to send and receive RPC protocol data for a single session.
- close()¶
Release resources associated with this transport.
- read(n, timeout_sec)¶
Read up to n bytes from the transport.
- Parameters
n (int) – Maximum number of bytes to read from the transport.
timeout_sec (Union[float, None]) – Number of seconds to wait for all n bytes to be received before timing out. The transport can wait additional time to account for transport latency or bandwidth limitations based on the selected configuration and number of bytes being received. If timeout_sec is 0, read should attempt to service the request in a non-blocking fashion. If timeout_sec is None, read should block until at least 1 byte of data can be returned.
- Returns
Data read from the channel. Less than n bytes may be returned, but 0 bytes should never be returned. If returning less than n bytes, the full timeout_sec, plus any internally-added timeout, should be waited. If a timeout or transport error occurs, an exception should be raised rather than simply returning empty bytes.
- Return type
- Raises
TransportClosedError : – When the transport layer determines that the transport can no longer send or receive data due to an underlying I/O problem (i.e. file descriptor closed, cable removed, etc).
IoTimeoutError : – When timeout_sec elapses without receiving any data.
- write(data, timeout_sec)¶
Write data to the transport channel.
- Parameters
data (bytes) – The data to write over the channel.
timeout_sec (Union[float, None]) – Number of seconds to wait for at least one byte to be written before timing out. The transport can wait additional time to account for transport latency or bandwidth limitations based on the selected configuration and number of bytes being received. If timeout_sec is 0, write should attempt to service the request in a non-blocking fashion. If timeout_sec is None, write should block until at least 1 byte of data can be returned.
- Returns
The number of bytes written to the underlying channel. This can be less than the length of data, but cannot be 0 (raise an exception instead).
- Return type
- Raises
TransportClosedError : – When the transport layer determines that the transport can no longer send or receive data due to an underlying I/O problem (i.e. file descriptor closed, cable removed, etc).
IoTimeoutError : – When timeout_sec elapses without receiving any data.