This is an automated email from the ASF dual-hosted git repository.
zhic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/master by this push:
new 2bbfbb1 [Runtime] Only initialize required module (#5926)
2bbfbb1 is described below
commit 2bbfbb10ba53c649d110828b4978df12b4f3b3e2
Author: Cody Yu <[email protected]>
AuthorDate: Fri Jun 26 08:05:12 2020 -0700
[Runtime] Only initialize required module (#5926)
* init required modules
* trigger ci
* trigger ci
---
src/runtime/metadata_module.cc | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/runtime/metadata_module.cc b/src/runtime/metadata_module.cc
index cf3d547..56f894c 100644
--- a/src/runtime/metadata_module.cc
+++ b/src/runtime/metadata_module.cc
@@ -48,15 +48,22 @@ class MetadataModuleNode : public ModuleNode {
public:
MetadataModuleNode(const std::unordered_map<std::string, NDArray>& metadata,
const std::unordered_map<std::string,
std::vector<std::string>>& sym_vars)
- : metadata_(metadata), sym_vars_(sym_vars) {}
+ : metadata_(metadata), sym_vars_(sym_vars) {
+ // Only the related submodules are cached to reduce the number of runtime
+ // symbol lookup for initialization. Otherwise, symbols/primitives in the
+ // DSO module will also be cached but they never need to be initialized.
+ for (const auto& it : sym_vars_) {
+ initialized_[it.first] = false;
+ }
+ }
PackedFunc GetFunction(const std::string& name, const ObjectPtr<Object>&
sptr_to_self) final {
// Initialize and memoize the module.
// Usually, we have some warmup runs. The module initialization should be
// done at this stage. Therefore, runtime overhead is not a concern.
- if (initialized_.count(name) == 0) {
+ if (initialized_.count(name) && !initialized_.at(name)) {
this->InitSubModule(name);
- initialized_.emplace(name);
+ initialized_[name] = true;
}
// Run the module.
@@ -202,7 +209,7 @@ class MetadataModuleNode : public ModuleNode {
* \brief Record if a module is initialized. It is needed by imported
* modules using execution engine.
*/
- std::unordered_set<std::string> initialized_;
+ std::unordered_map<std::string, bool> initialized_;
/*! \brief Variable name to NDArray mapping. */
std::unordered_map<std::string, NDArray> metadata_;
/*! \brief Symbol name to required constant variables mapping. */