@@ -20,13 +20,6 @@ limitations under the License. */
20
20
#include " paddle/fluid/framework/threadpool.h"
21
21
#include " paddle/fluid/string/printf.h"
22
22
23
- // The mutex is not needed by training and inference, only for distribution.
24
- #if PADDLE_WITH_DISTRIBUTE
25
- #define WITH_LOCK 1
26
- #else
27
- #define WITH_LOCK 0
28
- #endif
29
-
30
23
DEFINE_bool (benchmark, false ,
31
24
" Doing memory benchmark. It will make deleting scope synchronized, "
32
25
" and add some memory usage logs."
@@ -56,24 +49,18 @@ int64_t GetEagerDeletionThreshold() {
56
49
Scope::~Scope () { DropKids (); }
57
50
58
51
Scope& Scope::NewScope () const {
59
- #if WITH_LOCK
60
52
std::unique_lock<std::mutex> lock (mutex_);
61
- #endif
62
53
kids_.push_back (new Scope (this ));
63
54
return *kids_.back ();
64
55
}
65
56
66
57
Variable* Scope::Var (const std::string& name) {
67
- #if WITH_LOCK
68
58
std::unique_lock<std::mutex> lock (mutex_);
69
- #endif
70
59
return VarInternal (name);
71
60
}
72
61
73
62
Variable* Scope::Var (std::string* name) {
74
- #if WITH_LOCK
75
63
std::unique_lock<std::mutex> lock (mutex_);
76
- #endif
77
64
auto new_name = string::Sprintf (" %p.%d" , this , vars_.size ());
78
65
if (name != nullptr ) {
79
66
*name = new_name;
@@ -82,39 +69,29 @@ Variable* Scope::Var(std::string* name) {
82
69
}
83
70
84
71
Variable* Scope::FindVar (const std::string& name) const {
85
- #if WITH_LOCK
86
72
std::unique_lock<std::mutex> lock (mutex_);
87
- #endif
88
73
return FindVarInternal (name);
89
74
}
90
75
91
76
const Scope* Scope::FindScope (const Variable* var) const {
92
- #if WITH_LOCK
93
77
std::unique_lock<std::mutex> lock (mutex_);
94
- #endif
95
78
return FindScopeInternal (var);
96
79
}
97
80
98
81
void Scope::DropKids () {
99
- #if WITH_LOCK
100
82
std::unique_lock<std::mutex> lock (mutex_);
101
- #endif
102
83
for (Scope* s : kids_) delete s;
103
84
kids_.clear ();
104
85
}
105
86
106
87
bool Scope::HasKid (const Scope* scope) const {
107
- #if WITH_LOCK
108
88
std::unique_lock<std::mutex> lock (mutex_);
109
- #endif
110
89
auto it = std::find (this ->kids_ .begin (), this ->kids_ .end (), scope);
111
90
return it != this ->kids_ .end ();
112
91
}
113
92
114
93
std::vector<std::string> Scope::LocalVarNames () const {
115
- #if WITH_LOCK
116
94
std::unique_lock<std::mutex> lock (mutex_);
117
- #endif
118
95
std::vector<std::string> known_vars;
119
96
known_vars.reserve (this ->vars_ .size ());
120
97
for (auto & p : vars_) {
@@ -124,9 +101,7 @@ std::vector<std::string> Scope::LocalVarNames() const {
124
101
}
125
102
126
103
void Scope::DeleteScope (Scope* scope) const {
127
- #if WITH_LOCK
128
104
std::unique_lock<std::mutex> lock (mutex_);
129
- #endif
130
105
auto it = std::find (this ->kids_ .begin (), this ->kids_ .end (), scope);
131
106
PADDLE_ENFORCE (it != this ->kids_ .end (), " Cannot find %p as kid scope" , scope);
132
107
this ->kids_ .erase (it);
@@ -139,9 +114,7 @@ void Scope::DeleteScope(Scope* scope) const {
139
114
}
140
115
141
116
void Scope::EraseVars (const std::vector<std::string>& var_names) {
142
- #if WITH_LOCK
143
117
std::unique_lock<std::mutex> lock (mutex_);
144
- #endif
145
118
std::set<std::string> var_set (var_names.begin (), var_names.end ());
146
119
for (auto it = vars_.begin (); it != vars_.end ();) {
147
120
if (var_set.find (it->first ) != var_set.end ()) {
@@ -154,16 +127,12 @@ void Scope::EraseVars(const std::vector<std::string>& var_names) {
154
127
155
128
void Scope::Rename (const std::string& origin_name,
156
129
const std::string& new_name) const {
157
- #if WITH_LOCK
158
130
std::unique_lock<std::mutex> lock (mutex_);
159
- #endif
160
131
RenameInternal (origin_name, new_name);
161
132
}
162
133
163
134
std::string Scope::Rename (const std::string& origin_name) const {
164
- #if WITH_LOCK
165
135
std::unique_lock<std::mutex> lock (mutex_);
166
- #endif
167
136
auto new_name = string::Sprintf (" %p.%d" , this , vars_.size ());
168
137
RenameInternal (origin_name, new_name);
169
138
return new_name;
0 commit comments