tqchen commented on a change in pull request #5770:
URL: https://github.com/apache/incubator-tvm/pull/5770#discussion_r439593516
##########
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:
It would be great to see if we can reduce to only MetaDataModule, and
reuse mechanism here
https://tvm.apache.org/docs/dev/introduction_to_module_serialization.html for
serialization and packaging.
----------------------------------------------------------------
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]