From b5960b63ac5b174f23b89e49e4070b9f5609f2b9 Mon Sep 17 00:00:00 2001 From: Cody Yu Date: Mon, 22 Jun 2020 16:38:40 +0000 Subject: [PATCH 1/2] update source module --- src/target/source/source_module.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/target/source/source_module.cc b/src/target/source/source_module.cc index 1e201e50f0ea..68a34c8304f8 100644 --- a/src/target/source/source_module.cc +++ b/src/target/source/source_module.cc @@ -58,15 +58,18 @@ runtime::Module CreateMetadataModule( // Wrap all submodules in the initialization wrapper. std::unordered_map> sym_metadata; for (runtime::Module it : modules) { - CHECK_EQ(it->type_key(), "c") << "Only csource submodule is handled for now"; - String symbol = it.GetFunction("get_symbol")(); - Array variables = it.GetFunction("get_const_vars")(); - std::vector arrays; - for (size_t i = 0; i < variables.size(); i++) { - arrays.push_back(variables[i].operator std::string()); + auto pf_sym = it.GetFunction("get_symbol"); + auto pf_var = it.GetFunction("get_const_vars"); + if (pf_sym != nullptr && pf_var != nullptr) { + String symbol = pf_sym(); + Array variables = pf_var(); + std::vector arrays; + for (size_t i = 0; i < variables.size(); i++) { + arrays.push_back(variables[i].operator std::string()); + } + CHECK_EQ(sym_metadata.count(symbol), 0U) << "Found duplicated symbol: " << symbol; + sym_metadata[symbol] = arrays; } - CHECK_EQ(sym_metadata.count(symbol), 0U) << "Found duplicated symbol: " << symbol; - sym_metadata[symbol] = arrays; } // Wrap the modules. @@ -119,7 +122,6 @@ class CSourceModuleNode : public runtime::ModuleNode { return PackedFunc( [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = this->const_vars_; }); } else { - LOG(FATAL) << "Unknown packed function: " << name; return PackedFunc(nullptr); } } From 3164e10d9685930ea2a9a28c6f9056891884318c Mon Sep 17 00:00:00 2001 From: Cody Yu Date: Mon, 22 Jun 2020 23:19:20 +0000 Subject: [PATCH 2/2] address comment --- src/target/source/source_module.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/target/source/source_module.cc b/src/target/source/source_module.cc index 68a34c8304f8..9139f9f6a2a3 100644 --- a/src/target/source/source_module.cc +++ b/src/target/source/source_module.cc @@ -122,6 +122,7 @@ class CSourceModuleNode : public runtime::ModuleNode { return PackedFunc( [sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = this->const_vars_; }); } else { + LOG(FATAL) << "Unknown packed function: " << name; return PackedFunc(nullptr); } }