17
17
namespace paddle {
18
18
namespace framework {
19
19
20
+ // Holds all the transfer scope across the process.
20
21
std::unordered_map<size_t , Scope*>& global_transfer_data_cache () {
21
- thread_local auto * x = new std::unordered_map<size_t , Scope*>;
22
+ typedef std::unordered_map<size_t , Scope*> map_t ;
23
+ thread_local std::unique_ptr<map_t > x (new map_t );
22
24
return *x;
23
25
}
24
26
27
+ // Holds all the transfer scope for this thread.
25
28
std::unordered_set<Scope*>& global_transfer_scope_cache () {
26
- thread_local auto * x = new std::unordered_set<Scope*>;
29
+ typedef std::unordered_set<Scope*> set_t ;
30
+ thread_local std::unique_ptr<set_t > x (new set_t );
27
31
return *x;
28
32
}
29
33
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.
30
42
Scope* TryCreateTransferScope (OpKernelType type0, OpKernelType type1,
31
43
const Scope* scope) {
32
44
Scope* new_scope{nullptr };
@@ -46,27 +58,5 @@ Scope* TryCreateTransferScope(OpKernelType type0, OpKernelType type1,
46
58
return new_scope;
47
59
}
48
60
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
-
71
61
} // namespace framework
72
62
} // namespace paddle
0 commit comments