tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] tqchen commented on a change in pull request #5753: [Draft] Support Module based interface runtime
Date Tue, 09 Jun 2020 16:32:31 GMT

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



##########
File path: include/tvm/runtime/graph_runtime.h
##########
@@ -26,25 +26,27 @@
 #define TVM_RUNTIME_GRAPH_GRAPH_RUNTIME_H_
 
 #include <dlpack/dlpack.h>
-#include <dmlc/json.h>
 #include <dmlc/memory_io.h>
+#include <dmlc/json.h>
 #include <tvm/runtime/ndarray.h>
 #include <tvm/runtime/packed_func.h>
-
+#include <tvm/runtime/graph_runtime_factory.h>

Review comment:
       We should still keep the graph runtime internal, as we only expose the results as a
Module API

##########
File path: include/tvm/runtime/graph_runtime_factory.h
##########
@@ -0,0 +1,136 @@
+/*
+ * 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 tvm/runtime/graph_runtime_factory.h
+ * \brief Graph runtime factory creating graph runtime.
+ */
+
+#ifndef TVM_RUNTIME_GRAPH_RUNTIME_FACTORY_H_
+#define TVM_RUNTIME_GRAPH_RUNTIME_FACTORY_H_
+
+#include <tvm/runtime/c_runtime_api.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/module.h>
+#include <tvm/runtime/ndarray.h>
+#include <string>
+#include <vector>
+#include <unordered_map>
+
+
+namespace tvm {
+namespace runtime {
+
+class TVM_DLL GraphRuntimeFactory : public runtime::ModuleNode {
+
+ public:
+
+  /*!
+   * \brief Initialize the GraphRuntimeFactory with graph and context.
+   * \param graph_json The execution graph.
+   * \param params The params of graph.
+   * \param kind The runtime kind to be created.
+   */
+
+  void Init(const std::string& kind,
+            const std::string& graph_json,
+            const std::unordered_map<std::string, tvm::runtime::NDArray>& params);
+
+  void ImportModule(Module other, std::string module_name);
+
+  /*!
+   * \brief Get member function to front-end
+   * \param name The name of the function.
+   * \param sptr_to_self The pointer to the module node.
+   * \return The corresponding member function.
+   */
+  virtual PackedFunc GetFunction(const std::string& name,
+                                 const ObjectPtr<Object>& sptr_to_self);
+
+  /*!
+   * \return The type key of the executor.
+   */
+  const char* type_key() const override {
+    return "GraphRuntimeFactory";
+  }
+
+  /*!
+   * \brief Save the module to binary stream.
+   * \param stream The binary stream to save to.
+   */
+  void SaveToBinary(dmlc::Stream* stream) override;
+
+
+  /*!
+   * \brief Create a specific runtime module
+   * \param module The module we will be used for creating runtime
+   * \param ctxs The context of the host and devices where graph nodes will be
+   *  executed on.
+   * \return created runtime module
+   */
+  Module RuntimeCreate(Module module, const std::vector<TVMContext>& ctxs);
+
+  /*!
+   * \brief Select the specific module
+   * \param name The name of the module
+   * \return selected module
+   */
+  Module SelectModule(const std::string& name);
+
+  inline std::string GetJson() const {
+    return graph_json_;
+  }
+
+  inline std::unordered_map<std::string, tvm::runtime::NDArray> GetParams() const {

Review comment:
       Keep this signature internal

##########
File path: include/tvm/runtime/graph_runtime_factory.h
##########
@@ -0,0 +1,136 @@
+/*
+ * 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 tvm/runtime/graph_runtime_factory.h
+ * \brief Graph runtime factory creating graph runtime.
+ */
+
+#ifndef TVM_RUNTIME_GRAPH_RUNTIME_FACTORY_H_
+#define TVM_RUNTIME_GRAPH_RUNTIME_FACTORY_H_
+
+#include <tvm/runtime/c_runtime_api.h>
+#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/module.h>
+#include <tvm/runtime/ndarray.h>
+#include <string>
+#include <vector>
+#include <unordered_map>
+
+
+namespace tvm {
+namespace runtime {
+
+class TVM_DLL GraphRuntimeFactory : public runtime::ModuleNode {
+
+ public:
+
+  /*!
+   * \brief Initialize the GraphRuntimeFactory with graph and context.
+   * \param graph_json The execution graph.
+   * \param params The params of graph.
+   * \param kind The runtime kind to be created.
+   */
+
+  void Init(const std::string& kind,
+            const std::string& graph_json,
+            const std::unordered_map<std::string, tvm::runtime::NDArray>& params);
+
+  void ImportModule(Module other, std::string module_name);
+
+  /*!
+   * \brief Get member function to front-end
+   * \param name The name of the function.
+   * \param sptr_to_self The pointer to the module node.
+   * \return The corresponding member function.
+   */
+  virtual PackedFunc GetFunction(const std::string& name,
+                                 const ObjectPtr<Object>& sptr_to_self);
+
+  /*!
+   * \return The type key of the executor.
+   */
+  const char* type_key() const override {
+    return "GraphRuntimeFactory";
+  }
+
+  /*!
+   * \brief Save the module to binary stream.
+   * \param stream The binary stream to save to.
+   */
+  void SaveToBinary(dmlc::Stream* stream) override;
+
+
+  /*!
+   * \brief Create a specific runtime module
+   * \param module The module we will be used for creating runtime
+   * \param ctxs The context of the host and devices where graph nodes will be
+   *  executed on.
+   * \return created runtime module
+   */
+  Module RuntimeCreate(Module module, const std::vector<TVMContext>& ctxs);
+
+  /*!
+   * \brief Select the specific module
+   * \param name The name of the module
+   * \return selected module
+   */
+  Module SelectModule(const std::string& name);
+
+  inline std::string GetJson() const {
+    return graph_json_;
+  }
+
+  inline std::unordered_map<std::string, tvm::runtime::NDArray> GetParams() const {

Review comment:
       Sorry I meant this header file, not this particular function

##########
File path: include/tvm/runtime/graph_runtime.h
##########
@@ -26,25 +26,27 @@
 #define TVM_RUNTIME_GRAPH_GRAPH_RUNTIME_H_
 
 #include <dlpack/dlpack.h>
-#include <dmlc/json.h>
 #include <dmlc/memory_io.h>
+#include <dmlc/json.h>
 #include <tvm/runtime/ndarray.h>
 #include <tvm/runtime/packed_func.h>
-
+#include <tvm/runtime/graph_runtime_factory.h>

Review comment:
       It has to do with how would the user with the code. While some of the vm data structures
are publically available(e.g. Closure), most of the vm should also become private. 
   
   Putting it internal means that `graph_runtime_factory` is visible to all the components
inside tvm, it will be visible to vm as well. For the users, they can always use `factory["resnet18"]`
to create the model and `factory["get_params"]()` to obtain the parameters.




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



Mime
View raw message