Skip to content

Commit b819684

Browse files
committed
add compare_mkldnn test
test=develop
1 parent e47f418 commit b819684

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ namespace paddle {
2020
namespace inference {
2121
namespace analysis {
2222

23-
void SetConfig(AnalysisConfig *cfg) {
23+
void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) {
2424
cfg->param_file = FLAGS_infer_model + "/params";
2525
cfg->prog_file = FLAGS_infer_model + "/model";
2626
cfg->use_gpu = false;
2727
cfg->device = 0;
2828
cfg->enable_ir_optim = true;
2929
cfg->specify_input_name = true;
30-
#ifdef PADDLE_WITH_MKLDNN
31-
cfg->_use_mkldnn = FLAGS_use_MKLDNN;
32-
#endif
30+
cfg->_use_mkldnn = _use_mkldnn;
3331
}
3432

3533
void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
@@ -92,17 +90,19 @@ TEST(Analyzer_resnet50, compare) {
9290
std::vector<std::vector<PaddleTensor>> input_slots_all;
9391
SetInput(&input_slots_all);
9492
CompareNativeAndAnalysis(cfg, input_slots_all);
93+
}
94+
95+
// Compare result of NativeConfig and AnalysisConfig with MKLDNN
9596
#ifdef PADDLE_WITH_MKLDNN
96-
// since default config._use_mkldnn=true in this case,
97-
// we should compare analysis_outputs in config._use_mkldnn=false
98-
// with native_outputs as well.
99-
FLAGS_use_MKLDNN = false;
100-
AnalysisConfig cfg1;
101-
SetConfig(&cfg1);
102-
CompareNativeAndAnalysis(cfg1, input_slots_all);
103-
FLAGS_use_MKLDNN = true;
104-
#endif
97+
TEST(Analyzer_resnet50, compare_mkldnn) {
98+
AnalysisConfig cfg;
99+
SetConfig(&cfg, true);
100+
101+
std::vector<std::vector<PaddleTensor>> input_slots_all;
102+
SetInput(&input_slots_all);
103+
CompareNativeAndAnalysis(cfg, input_slots_all);
105104
}
105+
#endif
106106

107107
} // namespace analysis
108108
} // namespace inference

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Record ProcessALine(const std::string &line) {
5050
return record;
5151
}
5252

53-
void SetConfig(AnalysisConfig *cfg) {
53+
void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) {
5454
cfg->param_file = FLAGS_infer_model + "/__params__";
5555
cfg->prog_file = FLAGS_infer_model + "/__model__";
5656
cfg->use_gpu = false;
@@ -59,9 +59,7 @@ void SetConfig(AnalysisConfig *cfg) {
5959
cfg->specify_input_name = true;
6060
// TODO(TJ): fix fusion gru
6161
cfg->ir_passes.push_back("fc_gru_fuse_pass");
62-
#ifdef PADDLE_WITH_MKLDNN
63-
cfg->_use_mkldnn = FLAGS_use_MKLDNN;
64-
#endif
62+
cfg->_use_mkldnn = _use_mkldnn;
6563
}
6664

6765
void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
@@ -125,17 +123,19 @@ TEST(Analyzer_vis, compare) {
125123
std::vector<std::vector<PaddleTensor>> input_slots_all;
126124
SetInput(&input_slots_all);
127125
CompareNativeAndAnalysis(cfg, input_slots_all);
126+
}
127+
128+
// Compare result of NativeConfig and AnalysisConfig with MKLDNN
128129
#ifdef PADDLE_WITH_MKLDNN
129-
// since default config._use_mkldnn=true in this case,
130-
// we should compare analysis_outputs in config._use_mkldnn=false
131-
// with native_outputs as well.
132-
FLAGS_use_MKLDNN = false;
133-
AnalysisConfig cfg1;
134-
SetConfig(&cfg1);
135-
CompareNativeAndAnalysis(cfg1, input_slots_all);
136-
FLAGS_use_MKLDNN = true;
137-
#endif
130+
TEST(Analyzer_vis, compare_mkldnn) {
131+
AnalysisConfig cfg;
132+
SetConfig(&cfg, true);
133+
134+
std::vector<std::vector<PaddleTensor>> input_slots_all;
135+
SetInput(&input_slots_all);
136+
CompareNativeAndAnalysis(cfg, input_slots_all);
138137
}
138+
#endif
139139

140140
} // namespace analysis
141141
} // namespace inference

paddle/fluid/inference/tests/api/tester_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DEFINE_bool(test_all_data, false, "Test the all dataset in data file.");
3535
DEFINE_int32(num_threads, 1, "Running the inference program in multi-threads.");
3636
DEFINE_bool(use_analysis, true,
3737
"Running the inference program in analysis mode.");
38-
DEFINE_bool(use_MKLDNN, true,
38+
DEFINE_bool(use_MKLDNN, false,
3939
"Running the inference program with mkldnn library.");
4040

4141
namespace paddle {

0 commit comments

Comments
 (0)