Skip to content

Commit dc249d3

Browse files
committed
Revert "fix transfer cache thread_local bug (#14581)"
This reverts commit 5c073a4.
1 parent 05b7ee7 commit dc249d3

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

paddle/fluid/framework/transfer_scope_cache.cc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,16 @@
1717
namespace paddle {
1818
namespace framework {
1919

20-
// Holds all the transfer scope across the process.
2120
std::unordered_map<size_t, Scope*>& global_transfer_data_cache() {
22-
typedef std::unordered_map<size_t, Scope*> map_t;
23-
thread_local std::unique_ptr<map_t> x(new map_t);
21+
thread_local auto* x = new std::unordered_map<size_t, Scope*>;
2422
return *x;
2523
}
2624

27-
// Holds all the transfer scope for this thread.
2825
std::unordered_set<Scope*>& global_transfer_scope_cache() {
29-
typedef std::unordered_set<Scope*> set_t;
30-
thread_local std::unique_ptr<set_t> x(new set_t);
26+
thread_local auto* x = new std::unordered_set<Scope*>;
3127
return *x;
3228
}
3329

34-
// Try to create a transfer scope. If one cached scope has match the
35-
// requirement, just return that one.
36-
// Inputs:
37-
// @type0: the source kernel type.
38-
// @type1: the target kernel type.
39-
// @scope: the execution scope of this op.
40-
// Returns: A scope used to hold the transfer data across the different kernel
41-
// type.
4230
Scope* TryCreateTransferScope(OpKernelType type0, OpKernelType type1,
4331
const Scope* scope) {
4432
Scope* new_scope{nullptr};
@@ -58,5 +46,27 @@ Scope* TryCreateTransferScope(OpKernelType type0, OpKernelType type1,
5846
return new_scope;
5947
}
6048

49+
void RemoveKidsFromTransferScopeCache(Scope* scope) {
50+
auto it = global_transfer_scope_cache().find(scope);
51+
if (it != global_transfer_scope_cache().end()) {
52+
global_transfer_scope_cache().erase(it);
53+
}
54+
for (auto* s : scope->kids()) {
55+
auto it = global_transfer_scope_cache().find(s);
56+
if (it != global_transfer_scope_cache().end()) {
57+
global_transfer_scope_cache().erase(it);
58+
}
59+
}
60+
61+
// remove global transfer data cache
62+
auto& cache = global_transfer_data_cache();
63+
for (auto it = cache.begin(); it != cache.end();) {
64+
if (it->second == scope)
65+
it = cache.erase(it);
66+
else
67+
it++;
68+
}
69+
}
70+
6171
} // namespace framework
6272
} // namespace paddle

0 commit comments

Comments
 (0)