zhiics commented on a change in pull request #5770:
URL: https://github.com/apache/incubator-tvm/pull/5770#discussion_r439757500
##########
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:
@tqchen I refactored CSourceModule generator for subfunctions to
initialize the submodules. Now I am working on this. But I have a few questions
Suppose we have:
```
MetadataModule:
- Graphruntime LLVM module(uses p0 = const0, p1 = const1)
- Accelerator CSourceModule0, foo_0 (uses a = const1, b = const2)
- Accelerator CSourceModule1, foo_1 (uses c = const1, d = const3)
```
- How do we collect all required Metadata? Maybe we can collect them through
graph_runtime_codegen/vmcompiler because the params (var: ndarray pairs) used
by graphruntime/VM is from there. We can visit into other functions to collect
for the other two submodules.
- How do we dispatch the correct constants to the corresponding submodule,
`InitFoo0(const1, const2)`? It looks to me that MetadataModule is not aware of
any const to submodule mapping. I current stored all the variables and
ndarrays. Should we also need to have each submodule store the required
const_vars? By this, `MetadataModule` can query which ndarrays a submodule
would require by looking at the list of `const_vars`. However, this would mean
we need to have a `const_vars/params` field for different runtime modules.
Am I missing anything?
----------------------------------------------------------------
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]