Skip to content

Commit 305034f

Browse files
authored
Merge pull request #13909 from luotao1/mkldnn_test
refine mkldnn test in analyzer_tests
2 parents 081fd41 + e5b4643 commit 305034f

File tree

10 files changed

+40
-16
lines changed

10 files changed

+40
-16
lines changed

paddle/fluid/framework/ir/attention_lstm_fuse_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ std::unique_ptr<ir::Graph> AttentionLSTMFusePass::ApplyImpl(
262262
std::unordered_set<std::string> specified_vars({"data_lod_attention",
263263
"cell_init", "hidden_init",
264264
"data", "week", "minute"});
265-
int count = 0;
265+
size_t count = 0;
266266
for (auto* node : graph->Nodes()) {
267267
if (node->IsVar() && specified_vars.count(node->Name())) {
268268
++count;

paddle/fluid/framework/program_desc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const std::vector<std::string> ProgramDesc::GetFeedTargetNames() {
126126
std::vector<std::string> feed_target_names;
127127
for (auto *op : global_block.AllOps()) {
128128
if (op->Type() == kFeedOpType) {
129-
int col = boost::get<int>(op->GetAttr("col"));
129+
size_t col = boost::get<int>(op->GetAttr("col"));
130130
if (col >= feed_target_names.size()) {
131131
feed_target_names.resize(col + 1);
132132
}
@@ -143,7 +143,7 @@ const std::vector<std::string> ProgramDesc::GetFetchTargetNames() {
143143
std::vector<std::string> fetch_target_names;
144144
for (auto *op : global_block.AllOps()) {
145145
if (op->Type() == kFetchOpType) {
146-
int col = boost::get<int>(op->GetAttr("col"));
146+
size_t col = boost::get<int>(op->GetAttr("col"));
147147
if (col >= fetch_target_names.size()) {
148148
fetch_target_names.resize(col + 1);
149149
}

paddle/fluid/framework/reader_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TEST(READER, decorate_chain) {
3939
{
4040
auto endpoints = root->GetEndPoints();
4141
ASSERT_EQ(endpoints.size(), 2U);
42-
ASSERT_NE(endpoints.count(end_point1.get()), 0);
42+
ASSERT_NE(endpoints.count(end_point1.get()), 0UL);
4343
ASSERT_NE(endpoints.count(end_point2.get()), 0);
4444
}
4545

paddle/fluid/framework/selected_rows_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ TEST(SelectedRows, SparseTable) {
9191
ASSERT_TRUE(table.HasKey(10));
9292
ASSERT_TRUE(table.HasKey(8));
9393
ASSERT_TRUE(table.HasKey(6));
94-
ASSERT_EQ(table.rows().size(), 3);
94+
ASSERT_EQ(table.rows().size(), 3UL);
9595

9696
framework::Tensor ids;
9797
ids.Resize(framework::make_ddim({4}));

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
5252
}
5353

5454
// Easy for profiling independently.
55-
TEST(Analyzer_resnet50, profile) {
55+
void profile(bool use_mkldnn = false) {
5656
AnalysisConfig cfg;
5757
SetConfig(&cfg);
58+
cfg._use_mkldnn = use_mkldnn;
5859
std::vector<PaddleTensor> outputs;
5960

6061
std::vector<std::vector<PaddleTensor>> input_slots_all;
@@ -69,6 +70,11 @@ TEST(Analyzer_resnet50, profile) {
6970
}
7071
}
7172

73+
TEST(Analyzer_resnet50, profile) { profile(); }
74+
#ifndef PADDLE_WITH_MKLDNN
75+
TEST(Analyzer_resnet50, profile_mkldnn) { profile(true /* use_mkldnn */); }
76+
#endif
77+
7278
// Check the fuse status
7379
TEST(Analyzer_resnet50, fuse_statis) {
7480
AnalysisConfig cfg;
@@ -82,15 +88,21 @@ TEST(Analyzer_resnet50, fuse_statis) {
8288
}
8389

8490
// Compare result of NativeConfig and AnalysisConfig
85-
TEST(Analyzer_resnet50, compare) {
91+
void compare(bool use_mkldnn = false) {
8692
AnalysisConfig cfg;
8793
SetConfig(&cfg);
94+
cfg._use_mkldnn = use_mkldnn;
8895

8996
std::vector<std::vector<PaddleTensor>> input_slots_all;
9097
SetInput(&input_slots_all);
9198
CompareNativeAndAnalysis(cfg, input_slots_all);
9299
}
93100

101+
TEST(Analyzer_resnet50, compare) { compare(); }
102+
#ifdef PADDLE_WITH_MKLDNN
103+
TEST(Analyzer_resnet50, compare_mkldnn) { compare(true /* use_mkldnn */); }
104+
#endif
105+
94106
} // namespace analysis
95107
} // namespace inference
96108
} // namespace paddle

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ 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 = true;
64-
#endif
6562
}
6663

6764
void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
@@ -84,9 +81,10 @@ void SetInput(std::vector<std::vector<PaddleTensor>> *inputs) {
8481

8582
// Easy for profiling independently.
8683
// ocr, mobilenet and se_resnext50
87-
TEST(Analyzer_vis, profile) {
84+
void profile(bool use_mkldnn = false) {
8885
AnalysisConfig cfg;
8986
SetConfig(&cfg);
87+
cfg._use_mkldnn = use_mkldnn;
9088
std::vector<PaddleTensor> outputs;
9189

9290
std::vector<std::vector<PaddleTensor>> input_slots_all;
@@ -108,6 +106,12 @@ TEST(Analyzer_vis, profile) {
108106
}
109107
}
110108

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+
111115
// Check the fuse status
112116
TEST(Analyzer_vis, fuse_statis) {
113117
AnalysisConfig cfg;
@@ -118,15 +122,21 @@ TEST(Analyzer_vis, fuse_statis) {
118122
}
119123

120124
// Compare result of NativeConfig and AnalysisConfig
121-
TEST(Analyzer_vis, compare) {
125+
void compare(bool use_mkldnn = false) {
122126
AnalysisConfig cfg;
123127
SetConfig(&cfg);
128+
cfg._use_mkldnn = use_mkldnn;
124129

125130
std::vector<std::vector<PaddleTensor>> input_slots_all;
126131
SetInput(&input_slots_all);
127132
CompareNativeAndAnalysis(cfg, input_slots_all);
128133
}
129134

135+
TEST(Analyzer_vis, compare) { compare(); }
136+
#ifdef PADDLE_WITH_MKLDNN
137+
TEST(Analyzer_vis, compare_mkldnn) { compare(true /* use_mkldnn */); }
138+
#endif
139+
130140
} // namespace analysis
131141
} // namespace inference
132142
} // namespace paddle

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ void TestPrediction(const AnalysisConfig &config,
163163
const std::vector<std::vector<PaddleTensor>> &inputs,
164164
std::vector<PaddleTensor> *outputs, int num_threads,
165165
bool use_analysis = FLAGS_use_analysis) {
166-
LOG(INFO) << "use_analysis: " << use_analysis;
166+
LOG(INFO) << "use_analysis: " << use_analysis
167+
<< ", use_mkldnn: " << config._use_mkldnn;
167168
if (num_threads == 1) {
168169
TestOneThreadPrediction(config, inputs, outputs, use_analysis);
169170
} else {
@@ -175,6 +176,7 @@ void TestPrediction(const AnalysisConfig &config,
175176
void CompareNativeAndAnalysis(
176177
const AnalysisConfig &config,
177178
const std::vector<std::vector<PaddleTensor>> &inputs) {
179+
LOG(INFO) << "use_mkldnn: " << config._use_mkldnn;
178180
std::vector<PaddleTensor> native_outputs, analysis_outputs;
179181
TestOneThreadPrediction(config, inputs, &native_outputs, false);
180182
TestOneThreadPrediction(config, inputs, &analysis_outputs, true);

paddle/fluid/operators/reader/reader_blocking_queue_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ TEST(BlockingQueue, speed_test_mode) {
229229
q1.Receive(&b);
230230
EXPECT_EQ(b, i);
231231
}
232-
EXPECT_EQ(q1.Size(), 0);
232+
EXPECT_EQ(q1.Size(), 0UL);
233233

234234
BlockingQueue<size_t> q2(queue_size, true);
235235
for (size_t i = 0; i < queue_size; ++i) {

paddle/fluid/operators/sequence_unpad_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SequenceUnpadOp : public framework::OperatorWithKernel {
5050
if (x_dims.size() == 2) {
5151
out_dims_vec.push_back(1);
5252
} else {
53-
for (size_t i = 2; i < x_dims.size(); ++i) {
53+
for (int i = 2; i < x_dims.size(); ++i) {
5454
out_dims_vec.push_back(x_dims[i]);
5555
}
5656
}

paddle/fluid/operators/sequence_unpad_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SequenceUnpadOpKernel : public framework::OpKernel<T> {
6161
if (x_t->dims().size() == 2) {
6262
out_dims_vec.push_back(1);
6363
} else {
64-
for (size_t i = 2; i < x_t->dims().size(); ++i) {
64+
for (int i = 2; i < x_t->dims().size(); ++i) {
6565
out_dims_vec.push_back(x_t->dims()[i]);
6666
}
6767
}

0 commit comments

Comments
 (0)