Skip to content

Commit 0097cd6

Browse files
committed
- Second fix
- fix
1 parent 992d0d9 commit 0097cd6

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

paddle/fluid/inference/api/analysis_predictor.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,6 @@ void AnalysisPredictor::MkldnnPreSet(
341341
platform::MKLDNNDeviceContext::tls().set_cur_mkldnn_session_id(
342342
platform::MKLDNNDeviceContextThreadLocals::
343343
kMKLDNNSessionID_CacheClearing);
344-
platform::MKLDNNDeviceContext::tls().set_cur_input_shape_cache_capacity(
345-
config_.mkldnn_cache_capacity_);
346344
// Set current_input_shape for caching dynamic shape.
347345
std::stringstream ss;
348346
for (size_t i = 0; i < inputs_shape.size(); ++i) {
@@ -353,6 +351,9 @@ void AnalysisPredictor::MkldnnPreSet(
353351
VLOG(2) << "Set input shape=" << ss.str();
354352
platform::MKLDNNDeviceContext::tls().set_cur_input_shape_str(ss.str());
355353
}
354+
platform::MKLDNNDeviceContext::tls().set_cur_input_shape_cache_capacity(
355+
config_.mkldnn_cache_capacity_);
356+
356357
#endif
357358
}
358359

@@ -368,10 +369,9 @@ void AnalysisPredictor::MkldnnPostReset() {
368369
CHECK_LE(shape_blob_size,
369370
static_cast<size_t>(config_.mkldnn_cache_capacity_));
370371
}
371-
paddle::platform::MKLDNNDeviceContext::tls().set_cur_mkldnn_session_id(
372-
platform::MKLDNNDeviceContextThreadLocals::kMKLDNNSessionID_Default);
373-
platform::MKLDNNDeviceContext::tls().set_cur_input_shape_cache_capacity(0);
374-
platform::MKLDNNDeviceContext::tls().set_cur_input_shape_str("");
372+
// We cannot reset to the default cache settings
373+
// as there maybe CopyToCPU method used and oneDNN
374+
// primitives are used there so cache would grow
375375
}
376376
#endif
377377
}

paddle/fluid/inference/tests/api/analyzer_detect_functional_mkldnn_tester.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ void validate_cache_onednn(int cache_capacity = 1) {
120120
file.close();
121121
infer_file.close();
122122

123+
// Pick first output tensor from model
124+
// as internally reorders may be called
125+
// so it will impact cache size
126+
auto output_names = predictor->GetOutputNames();
127+
auto output_t = predictor->GetOutputHandle(output_names[0]);
128+
std::vector<int> output_shape = output_t->shape();
129+
size_t out_num = std::accumulate(output_shape.begin(), output_shape.end(), 1,
130+
std::multiplies<int>());
131+
std::vector<float> out_data;
132+
out_data.resize(out_num);
133+
output_t->CopyToCpu(out_data.data());
134+
135+
// Release predictor (relevant cache should be emptied)
123136
predictor.reset(nullptr);
124137
cache_filling.push_back(GetNumCachedObjects());
125138

0 commit comments

Comments
 (0)