You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2019/11/28 00:45:17 UTC

[GitHub] [incubator-tvm] ZihengJiang commented on a change in pull request #4439: [CONTRIB] TFLite Runtime

ZihengJiang commented on a change in pull request #4439: [CONTRIB] TFLite Runtime
URL: https://github.com/apache/incubator-tvm/pull/4439#discussion_r351550324
 
 

 ##########
 File path: python/tvm/contrib/tflite_runtime.py
 ##########
 @@ -0,0 +1,128 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""TFLite runtime that load and run tflite models."""
+import numpy as np
+
+from .._ffi.base import string_types
+from .._ffi.ndarray import context
+from .._ffi.function import get_global_func
+from .._ffi.runtime_ctypes import TVMContext
+from ..rpc import base as rpc_base
+
+def create(tflite_fname, ctx):
+    """Create a runtime executor module given a graph and module.
+    Parameters
+    ----------
+    tflite_fname : str
+        The graph to be deployed in json format output by nnvm graph.
+        The graph can only contain one operator(tvm_op) that
+        points to the name of PackedFunc in the libmod.
+    ctx : TVMContext or list of TVMContext
+        The context to deploy the module. It can be local or remote when there
+        is only one TVMContext. Otherwise, the first context in the list will
+        be used as this purpose. All context should be given for heterogeneous
+        execution.
+    Returns
+    -------
+    graph_module : GraphModule
+        Runtime graph module that can be used to execute the graph.
+    """
+    if not isinstance(tflite_fname, string_types):
+        raise ValueError("Type %s is not supported" % type(tflite_fname))
+
+    device_type = ctx.device_type
+    if device_type >= rpc_base.RPC_SESS_MASK:
+        device_type = ctx.device_type % rpc_base.RPC_SESS_MASK
+        device_id = ctx.device_id
+        remote_ctx = context(device_type, device_id)
+        fcreate = ctx._rpc_sess.get_function("tvm.tflite_runtime.create")
+        return TFLiteModule(fcreate(tflite_fname, ctx))
+    fcreate = get_global_func("tvm.tflite_runtime.create")
+    return TFLiteModule(fcreate(tflite_fname, ctx))
+
+
+class TFLiteModule(object):
+    """Wrapper runtime module.
+
+    This is a thin wrapper of the underlying TVM module.
+    you can also directly call set_input, run, and get_output
+    of underlying module functions
+
+    Parameters
+    ----------
+    module : Module
 
 Review comment:
   sure

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services