File tree Expand file tree Collapse file tree 3 files changed +16
-14
lines changed Expand file tree Collapse file tree 3 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,9 @@ void TestMultiThreadPrediction(
139
139
}
140
140
for (int tid = 0 ; tid < num_threads; ++tid) {
141
141
threads.emplace_back ([&, tid]() {
142
+ #ifdef PADDLE_WITH_MKLDNN
142
143
platform::set_cur_thread_id (static_cast <int >(tid) + 1 );
144
+ #endif
143
145
// Each thread should have local inputs and outputs.
144
146
// The inputs of each thread are all the same.
145
147
std::vector<std::vector<PaddleTensor>> inputs_tid = inputs;
Original file line number Diff line number Diff line change @@ -25,14 +25,6 @@ namespace platform {
25
25
26
26
DeviceContextPool* DeviceContextPool::pool = nullptr ;
27
27
28
- namespace {
29
- // Current thread's id.
30
- thread_local int cur_thread_id = 0 ;
31
- }
32
-
33
- void set_cur_thread_id (int tid) { cur_thread_id = tid; }
34
- int get_cur_thread_id (void ) { return cur_thread_id; }
35
-
36
28
platform::DeviceContext* DeviceContextPool::Get (const platform::Place& place) {
37
29
auto it = device_contexts_.find (place);
38
30
if (it == device_contexts_.end ()) {
@@ -309,6 +301,14 @@ MKLDNNDeviceContext::MKLDNNDeviceContext(CPUPlace place)
309
301
p_mutex_.reset (new std::mutex ());
310
302
}
311
303
304
+ namespace {
305
+ // Current thread's id.
306
+ thread_local int cur_thread_id = 0 ;
307
+ }
308
+
309
+ void set_cur_thread_id (int tid) { cur_thread_id = tid; }
310
+ int get_cur_thread_id (void ) { return cur_thread_id; }
311
+
312
312
void MKLDNNDeviceContext::SetBlob (const std::string& name,
313
313
std::shared_ptr<void > data) const {
314
314
BlobMap* pMap = p_blobmap_.get ();
Original file line number Diff line number Diff line change @@ -39,12 +39,6 @@ limitations under the License. */
39
39
namespace paddle {
40
40
namespace platform {
41
41
42
- using KeyBlob = std::unordered_map<std::string, std::shared_ptr<void >>;
43
- using BlobMap = std::unordered_map<int , std::shared_ptr<KeyBlob>>;
44
-
45
- void set_cur_thread_id (int );
46
- int get_cur_thread_id (void );
47
-
48
42
class DeviceContext {
49
43
public:
50
44
virtual ~DeviceContext () {}
@@ -182,6 +176,12 @@ struct DefaultDeviceContextType<platform::CUDAPinnedPlace> {
182
176
#endif
183
177
184
178
#ifdef PADDLE_WITH_MKLDNN
179
+ using KeyBlob = std::unordered_map<std::string, std::shared_ptr<void >>;
180
+ using BlobMap = std::unordered_map<int , std::shared_ptr<KeyBlob>>;
181
+
182
+ void set_cur_thread_id (int );
183
+ int get_cur_thread_id (void );
184
+
185
185
class MKLDNNDeviceContext : public CPUDeviceContext {
186
186
public:
187
187
explicit MKLDNNDeviceContext (CPUPlace place);
You can’t perform that action at this time.
0 commit comments