@@ -36,26 +36,10 @@ ScopeBufferedSSAGraphExecutor::ScopeBufferedSSAGraphExecutor(
36
36
FeedFetchList ScopeBufferedSSAGraphExecutor::Run (
37
37
const std::vector<std::string> &fetch_tensors) {
38
38
if (drop_scope_counter_ == 0 ) {
39
- // Create local scopes.
40
- for (auto it = local_scopes_.rbegin (); it != local_scopes_.rend (); ++it) {
41
- auto &scope = *it;
42
- Scope &local_scope = scope->NewScope ();
43
- *scope->Var (details::kLocalExecScopeName )->GetMutable <Scope *>() =
44
- &local_scope;
45
-
46
- for (auto &info : var_infos_) {
47
- if (scope->FindVar (info.name_ ) != nullptr ) {
48
- continue ;
49
- }
50
-
51
- if (info.persistable_ ) { // Persistable
52
- InitializeVariable (scope->Var (info.name_ ), info.type_ );
53
- } else {
54
- InitializeVariable (local_scope.Var (info.name_ ), info.type_ );
55
- }
56
- }
57
- }
39
+ platform::RecordEvent e (" InitLocalExeScopes" );
40
+ PrepareLocalExeScopes ();
58
41
}
42
+
59
43
std::vector<framework::LoDTensor> fetch_data;
60
44
std::exception_ptr eptr = nullptr ;
61
45
try {
@@ -64,9 +48,7 @@ FeedFetchList ScopeBufferedSSAGraphExecutor::Run(
64
48
eptr = std::current_exception ();
65
49
}
66
50
67
- platform::RecordEvent e (" ScopeBufferedSSAGraphExecutorAfterRun" );
68
51
++drop_scope_counter_;
69
-
70
52
if (drop_scope_counter_ == strategy_.num_iteration_per_drop_scope_ ) {
71
53
DropLocalExeScopes ();
72
54
}
@@ -78,11 +60,11 @@ FeedFetchList ScopeBufferedSSAGraphExecutor::Run(
78
60
}
79
61
80
62
void ScopeBufferedSSAGraphExecutor::DropLocalExeScopes () {
63
+ platform::RecordEvent drop_scope_event (" DropLocalExeScopes" );
81
64
drop_scope_counter_ = 0 ;
82
65
for (auto p : places_) {
83
66
platform::DeviceContextPool::Instance ().Get (p)->Wait ();
84
67
}
85
-
86
68
for (auto &scope : local_scopes_) {
87
69
auto &local_scope =
88
70
*scope->Var (details::kLocalExecScopeName )->GetMutable <Scope *>();
@@ -91,6 +73,26 @@ void ScopeBufferedSSAGraphExecutor::DropLocalExeScopes() {
91
73
}
92
74
}
93
75
76
+ void ScopeBufferedSSAGraphExecutor::PrepareLocalExeScopes () {
77
+ // Create local scopes.
78
+ for (auto it = local_scopes_.rbegin (); it != local_scopes_.rend (); ++it) {
79
+ auto &scope = *it;
80
+ Scope &local_scope = scope->NewScope ();
81
+ *scope->Var (kLocalExecScopeName )->GetMutable <Scope *>() = &local_scope;
82
+
83
+ for (auto &info : var_infos_) {
84
+ if (scope->FindVar (info.name_ ) != nullptr ) {
85
+ continue ;
86
+ }
87
+ if (info.persistable_ ) { // Persistable
88
+ InitializeVariable (scope->Var (info.name_ ), info.type_ );
89
+ } else {
90
+ InitializeVariable (local_scope.Var (info.name_ ), info.type_ );
91
+ }
92
+ }
93
+ }
94
+ }
95
+
94
96
bool ScopeBufferedSSAGraphExecutor::NeedCreateLocalExeScope () {
95
97
return drop_scope_counter_ == 0 ;
96
98
}
0 commit comments