diff --git a/src/framework/tensor.h b/src/framework/tensor.h index 8b56dc77c984f18a95ec4683f0d5dc56c16aada1..8e30b4dc4692ed3d71d9476b8a78a6d250bb2700 100644 --- a/src/framework/tensor.h +++ b/src/framework/tensor.h @@ -28,8 +28,6 @@ limitations under the License. */ #include "framework/tensor_base.h" #include "memory/t_malloc.h" -#include - namespace paddle_mobile { namespace framework { @@ -84,10 +82,8 @@ class Tensor : public TensorBase { int64_t size = numel() * SizeOfType(type); if (holder_ == nullptr || holder_->size() < size + offset_) { if (holder_ == nullptr) { - std::cout << "reset holder... size " << size << std::endl; holder_.reset(new PlaceholderImpl(size, type)); } else { - std::cout << "resize holder... size " << size << std::endl; holder_->resize(size); } offset_ = 0; diff --git a/src/pass/memory_optimize.cpp b/src/pass/memory_optimize.cpp index 68c7d442f8ef1d0ec230167dacc42d515266e66c..dec9b7f3a2c119ed6b3d7f3e5ca58dde02450435 100644 --- a/src/pass/memory_optimize.cpp +++ b/src/pass/memory_optimize.cpp @@ -18,8 +18,8 @@ limitations under the License. */ namespace paddle_mobile { namespace pass { -void MemoryOptPass::InitBlockVars(const framework::BlockDesc *block) { - block_vars_.clear(); +void MemoryOptPass::AppendBlockVars(const framework::BlockDesc *block) { + // block_vars_.clear(); for (const auto var : block->Vars()) { block_vars_[var->Name()] = var.get(); } @@ -51,8 +51,8 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program, framework::Scope *scope) { const auto &blocks = program->Blocks(); for (const auto &block : blocks) { - // access all variables in block, and stored in map - InitBlockVars(block.get()); + // access all variables in each block + AppendBlockVars(block.get()); reused_nodes_.clear(); // collect all not persistable variables, and accumulate @@ -91,6 +91,8 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program, } } + DLOG << "analysis_nodes_ size: " << analysis_nodes_.size(); + // apply optimize while (!analysis_nodes_.empty()) { auto *node = analysis_nodes_.top(); @@ -117,21 +119,22 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program, node->visited = true; node->count -= 1; } - } - // shared data within all variables in the same reused list - for (const auto &list : reused_nodes_) { - DLOG << "\n"; - DLOG << "share memory within these variables"; - std::string name = list[0]->name; - auto *reused_var = scope->Var(name); - auto *reuse_tensor = - reused_var->template GetMutable(); - reuse_tensor->mutable_data(); - for (const auto &node : list) { - DLOG << node->name; - auto *var = scope->Var(node->name); - auto *tensor = var->template GetMutable(); - tensor->ShareDataWith(*reuse_tensor); + + // shared data within all variables in the same reused list + for (const auto &list : reused_nodes_) { + DLOG << "\n"; + DLOG << "share memory within these variables"; + std::string name = list[0]->name; + auto *reused_var = scope->Var(name); + auto *reuse_tensor = + reused_var->template GetMutable(); + reuse_tensor->mutable_data(); + for (const auto &node : list) { + DLOG << node->name; + auto *var = scope->Var(node->name); + auto *tensor = var->template GetMutable(); + tensor->ShareDataWith(*reuse_tensor); + } } } } diff --git a/src/pass/memory_optimize.h b/src/pass/memory_optimize.h index 466af72e46ccc742814b84d461b9c192f3475ffa..116100af0bae137d74bbc9aaa24a8f8d61d9dfdf 100644 --- a/src/pass/memory_optimize.h +++ b/src/pass/memory_optimize.h @@ -49,7 +49,7 @@ class MemoryOptPass : public PassBase { void operator()(const framework::ProgramDesc *program, framework::Scope *scope); - void InitBlockVars(const framework::BlockDesc *block); + void AppendBlockVars(const framework::BlockDesc *block); bool IsPersistable(const std::string name);