zhiics commented on a change in pull request #5770:
URL: https://github.com/apache/incubator-tvm/pull/5770#discussion_r439592645



##########
File path: src/target/source/source_module.cc
##########
@@ -152,8 +153,92 @@ runtime::Module DeviceSourceModuleCreate(
   return runtime::Module(n);
 }
 
+// A helper used to wrap different types of modules and pass through 
packedfunc.
+// This module will never be used for compilation and execution.
+class ModuleClassWrapperNode : public runtime::ModuleNode {
+ public:
+  ModuleClassWrapperNode() = default;
+  const char* type_key() const { return "module_class_wrapper"; }
+  PackedFunc GetFunction(const std::string& name, const ObjectPtr<Object>& 
sptr_to_self) final {
+    LOG(FATAL) << "Cannot execute module wrapper";
+    return PackedFunc();
+  }
+};
+
+runtime::Module ModuleClassWrapperCreate() {
+  auto n = make_object<ModuleClassWrapperNode>();
+  return runtime::Module(n);
+}
+
+// Pack the source code and metadata, where source code could be any
+// user-defined code, i.e. c source code, json graph representation, etc.
+class SourceMetadataModuleNode final : public runtime::ModuleNode {
+ public:
+  SourceMetadataModuleNode(const String& func_symbol, const String& code, 
const String& source_type,
+                           const Array<String>& variables, const 
Array<runtime::NDArray>& metadata)
+      : func_symbol_(func_symbol),
+        code_(code),
+        source_type_(source_type),
+        variables_(variables),
+        metadata_(metadata) {}
+
+  PackedFunc GetFunction(const std::string& name, const ObjectPtr<Object>& 
sptr_to_self) final {
+    if (name == "get_source") {
+      return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { 
*rv = this->code_; });
+    } else if (name == "get_source_type") {
+      return PackedFunc(
+          [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = 
this->source_type_; });
+    } else if (name == "get_symbol") {
+      return PackedFunc(
+          [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = 
this->func_symbol_; });
+    } else if (name == "get_vars") {
+      return PackedFunc(
+          [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = 
this->variables_; });
+    } else if (name == "get_metadata") {
+      return PackedFunc(

Review comment:
       This module saves the data including source and metadata from the 
partitioned graphs. It is only used for packaging purpose. CSourceMoudle and 
later on other modules (e.g json runtime module) will take the code from it. 
The `ModuleInitWrapper` will take the variables and metadata from it. 
   
   If we can let MetadataModule take all {var: ndarray} mapping and let 
CSourceModule get the needed variables. We should be able to remove this module 
as well.




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