areusch commented on a change in pull request #8380:
URL: https://github.com/apache/tvm/pull/8380#discussion_r677865293
##########
File path: python/tvm/micro/project.py
##########
@@ -0,0 +1,97 @@
+"""Defines glue wrappers around the Project API which mate to TVM
interfaces."""
+
+from ..contrib import utils
+from .build import get_standalone_crt_dir
+from .model_library_format import export_model_library_format
+from .project_api import client
+from .transport import Transport, TransportTimeouts
+
+
+class ProjectTransport(Transport):
+
+ def __init__(self, client, options):
+ self._client = client
+ self._options = options
+ self._timeouts = None
+
+ def timeouts(self):
+ assert self._timeouts is not None, "Transport not yet opened"
+ return self._timeouts
+
+ def open(self):
+ reply = self._client.connect_transport(self._options)
+ self._timeouts = TransportTimeouts(**reply["timeouts"])
+
+ def close(self):
+ self._client.disconnect_transport()
+
+ def write(self, data, timeout_sec):
+ return self._client.write_transport(data, timeout_sec)["bytes_written"]
+
+ def read(self, n, timeout_sec):
+ return self._client.read_transport(n, timeout_sec)["data"]
+
+
+class TemplateProjectError(Exception):
+ """Raised when the Project API server given to GeneratedProject reports
is_template=True."""
+
+
+class GeneratedProject:
+ """Defines a glue interface to interact with a generated project through
the API server."""
+
+ @classmethod
+ def from_directory(cls, project_dir, options):
+ return cls(client.instantiate_from_dir(project_dir), options)
+
+ def __init__(self, client, options):
+ self._client = client
+ self._options = options
+ self._info = self._client.server_info_query()
+ if self._info['is_template']:
+ raise TemplateProjectError()
+
Review comment:
@gromero ah gotcha. yeah so i view this more as an internal interface
rather than an external one. as such, i do think that a server_info_query() may
have a place here. maybe better for your use case would be a function
`get_project_options` which would call `server_info_query` if it hadn't yet
been, and then return the `project_options`. the idea here is to document all
of TVM's uses of Project API all in once place. since there isn't that use case
today in the code, it isn't there yet. however, you should feel free to add
such functions to project.py as needed.
does that sound ok to you?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]