Skip to content

Commit af4dac4

Browse files
authored
Feature/free kid scope (PaddlePaddle#4951)
* Delete kid * Delete local scope
1 parent 42f2dd4 commit af4dac4

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

paddle/framework/executor.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope, int block_id) {
8484
op->Run(local_scope, *device);
8585
}
8686

87-
// TODO(tonyyang-svail):
88-
// - Destroy local_scope
87+
scope->DeleteScope(&local_scope);
8988
}
9089

9190
} // namespace framework

paddle/framework/scope.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ void Scope::DropKids() {
6565
kids_.clear();
6666
}
6767

68+
void Scope::DeleteScope(Scope* scope) {
69+
auto it = std::find(this->kids_.begin(), this->kids_.end(), scope);
70+
PADDLE_ENFORCE(it != this->kids_.end(), "Cannot find %p as kid scope", scope);
71+
this->kids_.erase(it);
72+
delete scope;
73+
}
74+
6875
framework::Scope& GetGlobalScope() {
6976
static framework::Scope* g_scope = nullptr;
7077
if (g_scope == nullptr) {

paddle/framework/scope.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Scope {
5959
/// Find the scope or an ancestor scope that contains the given variable.
6060
const Scope* FindScope(const Variable* var) const;
6161

62+
void DeleteScope(Scope* scope);
63+
6264
/// Drop all kids scopes belonged to this scope.
6365
void DropKids();
6466

0 commit comments

Comments
 (0)