Skip to content

Commit e5b4643

Browse files
committed
add profile_mkldnn test
test=develop
1 parent 7d680be commit e5b4643

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

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

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

23-
void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) {
23+
void SetConfig(AnalysisConfig *cfg) {
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-
cfg->_use_mkldnn = _use_mkldnn;
3130
}
3231

3332
void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
@@ -53,9 +52,10 @@ void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
5352
}
5453

5554
// Easy for profiling independently.
56-
TEST(Analyzer_resnet50, profile) {
55+
void profile(bool use_mkldnn = false) {
5756
AnalysisConfig cfg;
5857
SetConfig(&cfg);
58+
cfg._use_mkldnn = use_mkldnn;
5959
std::vector<PaddleTensor> outputs;
6060

6161
std::vector<std::vector<PaddleTensor>> input_slots_all;
@@ -70,6 +70,11 @@ TEST(Analyzer_resnet50, profile) {
7070
}
7171
}
7272

73+
TEST(Analyzer_resnet50, profile) { profile(); }
74+
#ifndef PADDLE_WITH_MKLDNN
75+
TEST(Analyzer_resnet50, profile_mkldnn) { profile(true /* use_mkldnn */); }
76+
#endif
77+
7378
// Check the fuse status
7479
TEST(Analyzer_resnet50, fuse_statis) {
7580
AnalysisConfig cfg;
@@ -83,25 +88,19 @@ TEST(Analyzer_resnet50, fuse_statis) {
8388
}
8489

8590
// Compare result of NativeConfig and AnalysisConfig
86-
TEST(Analyzer_resnet50, compare) {
91+
void compare(bool use_mkldnn = false) {
8792
AnalysisConfig cfg;
8893
SetConfig(&cfg);
94+
cfg._use_mkldnn = use_mkldnn;
8995

9096
std::vector<std::vector<PaddleTensor>> input_slots_all;
9197
SetInput(&input_slots_all);
9298
CompareNativeAndAnalysis(cfg, input_slots_all);
9399
}
94100

95-
// Compare result of NativeConfig and AnalysisConfig with MKLDNN
101+
TEST(Analyzer_resnet50, compare) { compare(); }
96102
#ifdef PADDLE_WITH_MKLDNN
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);
104-
}
103+
TEST(Analyzer_resnet50, compare_mkldnn) { compare(true /* use_mkldnn */); }
105104
#endif
106105

107106
} // namespace analysis

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, bool _use_mkldnn = FLAGS_use_MKLDNN) {
53+
void SetConfig(AnalysisConfig *cfg) {
5454
cfg->param_file = FLAGS_infer_model + "/__params__";
5555
cfg->prog_file = FLAGS_infer_model + "/__model__";
5656
cfg->use_gpu = false;
@@ -59,7 +59,6 @@ void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) {
5959
cfg->specify_input_name = true;
6060
// TODO(TJ): fix fusion gru
6161
cfg->ir_passes.push_back("fc_gru_fuse_pass");
62-
cfg->_use_mkldnn = _use_mkldnn;
6362
}
6463

6564
void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
@@ -82,9 +81,10 @@ void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
8281

8382
// Easy for profiling independently.
8483
// ocr, mobilenet and se_resnext50
85-
TEST(Analyzer_vis, profile) {
84+
void profile(bool use_mkldnn = false) {
8685
AnalysisConfig cfg;
8786
SetConfig(&cfg);
87+
cfg._use_mkldnn = use_mkldnn;
8888
std::vector<PaddleTensor> outputs;
8989

9090
std::vector<std::vector<PaddleTensor>> input_slots_all;
@@ -106,6 +106,12 @@ TEST(Analyzer_vis, profile) {
106106
}
107107
}
108108

109+
TEST(Analyzer_vis, profile) { profile(); }
110+
111+
#ifdef PADDLE_WITH_MKLDNN
112+
TEST(Analyzer_vis, profile_mkldnn) { profile(true /* use_mkldnn */); }
113+
#endif
114+
109115
// Check the fuse status
110116
TEST(Analyzer_vis, fuse_statis) {
111117
AnalysisConfig cfg;
@@ -116,25 +122,19 @@ TEST(Analyzer_vis, fuse_statis) {
116122
}
117123

118124
// Compare result of NativeConfig and AnalysisConfig
119-
TEST(Analyzer_vis, compare) {
125+
void compare(bool use_mkldnn = false) {
120126
AnalysisConfig cfg;
121127
SetConfig(&cfg);
128+
cfg._use_mkldnn = use_mkldnn;
122129

123130
std::vector<std::vector<PaddleTensor>> input_slots_all;
124131
SetInput(&input_slots_all);
125132
CompareNativeAndAnalysis(cfg, input_slots_all);
126133
}
127134

128-
// Compare result of NativeConfig and AnalysisConfig with MKLDNN
135+
TEST(Analyzer_vis, compare) { compare(); }
129136
#ifdef PADDLE_WITH_MKLDNN
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);
137-
}
137+
TEST(Analyzer_vis, compare_mkldnn) { compare(true /* use_mkldnn */); }
138138
#endif
139139

140140
} // namespace analysis

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ 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, false,
39-
"Running the inference program with mkldnn library.");
4038

4139
namespace paddle {
4240
namespace inference {

0 commit comments

Comments
 (0)