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 2020/07/10 17:26:31 UTC

[GitHub] [incubator-tvm] tqchen commented on a change in pull request #5753: Support module based interface runtime

tqchen commented on a change in pull request #5753:
URL: https://github.com/apache/incubator-tvm/pull/5753#discussion_r452957910



##########
File path: src/node/container.cc
##########
@@ -357,7 +357,4 @@ TVM_REGISTER_GLOBAL("node.MapItems").set_body([](TVMArgs args, TVMRetValue* ret)
   *ret = std::move(rkvs);
 });
 
-#if (USE_FALLBACK_STL_MAP == 0)
-TVM_DLL constexpr uint64_t DenseMapNode::kNextProbeLocation[];

Review comment:
       cc @junrushao1994 please check 

##########
File path: python/tvm/relay/backend/graph_runtime_factory.py
##########
@@ -0,0 +1,98 @@
+# 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.
+"""Graph runtime factory."""
+import warnings
+from tvm._ffi.base import string_types
+from tvm._ffi.registry import get_global_func
+from tvm.runtime.module import Module
+from tvm.runtime import ndarray
+
+
+def create(graph_json_str, libmod, libmod_name, params):
+    """Create a runtime executor module given a graph and module.
+    Parameters
+    ----------
+    graph_json_str : str or graph class
+        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.
+    libmod : tvm.Module
+        The module of the corresponding function
+    libmod_name: str
+        The name of module
+    params : dict of str to NDArray
+        The parameters of module
+
+    Returns
+    -------
+    graph_module : GraphRuntimeFactoryModule
+        Runtime graph runtime factory module.
+    """
+    if not isinstance(graph_json_str, string_types):
+        try:
+            graph_json_str = graph_json_str._tvm_graph_json()
+        except AttributeError:
+            raise ValueError("Type %s is not supported" % type(graph_json_str))
+    fcreate = get_global_func("tvm.graph_runtime_factory.create")
+    args = []
+    for k, v in params.items():
+        args.append(k)
+        args.append(ndarray.array(v))
+    return GraphRuntimeFactoryModule(fcreate(graph_json_str, libmod, libmod_name, *args))
+
+
+class GraphRuntimeFactoryModule(Module):
+    """Graph runtime factory module.
+    This is a module of graph runtime factory
+
+    Parameters
+    ----------
+    module : Module
+        The interal tvm module that holds the actual graph functions.
+    """
+
+    def __init__(self, module):

Review comment:
       We don't need to wrap module here. Instead, we can simply take a constructor that takes graph_json, lib_mod, and libmod_name, besides the module as a member. 
   
   Then we overload export_library to redirects to `self.module.export_library`. This helps us to reduce the functions we need to expose, for example, we don't have to expose `get_lib`

##########
File path: src/runtime/module.cc
##########
@@ -66,9 +66,19 @@ PackedFunc ModuleNode::GetFunction(const std::string& name, bool query_imports)
   PackedFunc pf = self->GetFunction(name, GetObjectPtr<Object>(this));
   if (pf != nullptr) return pf;
   if (query_imports) {
-    for (Module& m : self->imports_) {
-      pf = m->GetFunction(name, m.data_);
-      if (pf != nullptr) return pf;

Review comment:
       should'nt recursive call of m->GetFunction is enough? Perhaps we should add a GetFunction that has a query_import flag.




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