gromero commented on a change in pull request #8380:
URL: https://github.com/apache/tvm/pull/8380#discussion_r677788445



##########
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:
       @areusch I thought of this code as a convenient wrapper around  
`TemplateProject` class and, ultimately, around project_api.client module. 
Hence in the use case where a program wants to simply query some info only 
about the template project (without generating a project based on the template 
dir) it would use the `server_info_query()` method. For instance, with the most 
recent code there is now a new `options` '`project_type` (which can be 
currently `host_driven` or `aot_driven`. TVMC create-project command would need 
to accept an argument specifying which one it can take. Since Client API 
detects it automatically based on what's in `src/`, it would be matter of 
querying the `project_type`s  available by using 
`TemplateProject.server_info_query` to show the user the options available - we 
would need also create an associated wrapper like 
`tvmc.micro.project.template_project` On a second run the user woulds already 
know the right option and pass to TVMC create-project command, 
 which by its turn would that time call `tvm.micro.project.create_project`.
   
   Maybe I've misunderstood some project.py role. Let me know if it's not clear 
the use case I'm thinking of.




-- 
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]


Reply via email to