tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] zhiics commented on a change in pull request #5770: [BYOC][runtime] Separate code and metadata for CSourceModule
Date Fri, 12 Jun 2020 20:04:29 GMT

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



##########
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:
       Okay, I left a TODO in the code for this. Let me give it a try in this PR.




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