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



##########
File path: src/runtime/graph/graph_runtime_factory.cc
##########
@@ -0,0 +1,236 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file graph_runtime_factory.cc
+ * \brief Graph runtime factory implementations
+ */
+
+#include "./graph_runtime_factory.h"
+
+#include <tvm/node/container.h>
+#include <tvm/runtime/registry.h>
+
+#include <algorithm>
+#include <iterator>
+#include <vector>
+
+#include "./graph_runtime.h"
+
+namespace tvm {
+namespace runtime {
+
+void GraphRuntimeFactory::Init(const std::string& kind, const std::string& 
graph_json,
+                               const std::unordered_map<std::string, 
tvm::runtime::NDArray>& params,
+                               const std::string& module_name) {
+  kind_ = kind;
+  graph_json_ = graph_json;
+  params_ = params;
+  module_name_ = module_name;
+  graph_runtime_factory_module_list_.push_back(module_name_);
+}
+
+void GraphRuntimeFactory::ImportModule(Module other) {
+  this->Import(other);
+  auto module = other.as<GraphRuntimeFactory>();
+  CHECK(module) << "should only import graph runtime factory module";
+  graph_runtime_factory_module_list_.push_back(module->GetModuleName());
+}
+
+PackedFunc GraphRuntimeFactory::GetFunction(
+    const std::string& name, const 
tvm::runtime::ObjectPtr<tvm::runtime::Object>& sptr_to_self) {
+  if (name == "runtime_create") {
+    return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) {
+      std::vector<TVMContext> contexts;
+      TVMContext ctx;
+      // arg is: module, ctxs
+      CHECK_EQ((args.size() - 1) % 2, 0);
+      for (int i = 1; i < args.num_args; i += 2) {
+        int dev_type = args[i];
+        ctx.device_type = static_cast<DLDeviceType>(dev_type);
+        ctx.device_id = args[i + 1];
+        contexts.push_back(ctx);
+      }
+      *rv = this->RuntimeCreate(args[0], contexts);
+    });
+  } else if (name == "import_module") {
+    return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) {
+      CHECK_EQ(args.size(), 1);
+      this->ImportModule(args[0]);
+    });
+  } else if (name == "select_module") {
+    return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) {
+      CHECK_EQ(args.size(), 1);
+      *rv = this->SelectModule(args[0]);
+    });
+  } else if (name == "get_json") {
+    return PackedFunc(
+        [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = 
this->GetJson(); });
+  } else if (name == "get_lib") {
+    return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) {
+      CHECK_GT(this->imports().size(), 0);

Review comment:
       It is unnessary.




----------------------------------------------------------------
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:
[email protected]


Reply via email to