From b81968437064e4a56367b46438c74d8c641ebf71 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Wed, 17 Oct 2018 20:48:04 +0800 Subject: [PATCH] add compare_mkldnn test test=develop --- .../tests/api/analyzer_resnet50_tester.cc | 26 +++++++++---------- .../tests/api/analyzer_vis_tester.cc | 26 +++++++++---------- .../fluid/inference/tests/api/tester_helper.h | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc b/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc index 92cc76d3ce9..f10eb018c6d 100644 --- a/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc @@ -20,16 +20,14 @@ namespace paddle { namespace inference { namespace analysis { -void SetConfig(AnalysisConfig *cfg) { +void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) { cfg->param_file = FLAGS_infer_model + "/params"; cfg->prog_file = FLAGS_infer_model + "/model"; cfg->use_gpu = false; cfg->device = 0; cfg->enable_ir_optim = true; cfg->specify_input_name = true; -#ifdef PADDLE_WITH_MKLDNN - cfg->_use_mkldnn = FLAGS_use_MKLDNN; -#endif + cfg->_use_mkldnn = _use_mkldnn; } void SetInput(std::vector> *inputs) { @@ -92,17 +90,19 @@ TEST(Analyzer_resnet50, compare) { std::vector> input_slots_all; SetInput(&input_slots_all); CompareNativeAndAnalysis(cfg, input_slots_all); +} + +// Compare result of NativeConfig and AnalysisConfig with MKLDNN #ifdef PADDLE_WITH_MKLDNN - // since default config._use_mkldnn=true in this case, - // we should compare analysis_outputs in config._use_mkldnn=false - // with native_outputs as well. - FLAGS_use_MKLDNN = false; - AnalysisConfig cfg1; - SetConfig(&cfg1); - CompareNativeAndAnalysis(cfg1, input_slots_all); - FLAGS_use_MKLDNN = true; -#endif +TEST(Analyzer_resnet50, compare_mkldnn) { + AnalysisConfig cfg; + SetConfig(&cfg, true); + + std::vector> input_slots_all; + SetInput(&input_slots_all); + CompareNativeAndAnalysis(cfg, input_slots_all); } +#endif } // namespace analysis } // namespace inference diff --git a/paddle/fluid/inference/tests/api/analyzer_vis_tester.cc b/paddle/fluid/inference/tests/api/analyzer_vis_tester.cc index 96a3c6ff24b..7da09274772 100644 --- a/paddle/fluid/inference/tests/api/analyzer_vis_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_vis_tester.cc @@ -50,7 +50,7 @@ Record ProcessALine(const std::string &line) { return record; } -void SetConfig(AnalysisConfig *cfg) { +void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) { cfg->param_file = FLAGS_infer_model + "/__params__"; cfg->prog_file = FLAGS_infer_model + "/__model__"; cfg->use_gpu = false; @@ -59,9 +59,7 @@ void SetConfig(AnalysisConfig *cfg) { cfg->specify_input_name = true; // TODO(TJ): fix fusion gru cfg->ir_passes.push_back("fc_gru_fuse_pass"); -#ifdef PADDLE_WITH_MKLDNN - cfg->_use_mkldnn = FLAGS_use_MKLDNN; -#endif + cfg->_use_mkldnn = _use_mkldnn; } void SetInput(std::vector> *inputs) { @@ -125,17 +123,19 @@ TEST(Analyzer_vis, compare) { std::vector> input_slots_all; SetInput(&input_slots_all); CompareNativeAndAnalysis(cfg, input_slots_all); +} + +// Compare result of NativeConfig and AnalysisConfig with MKLDNN #ifdef PADDLE_WITH_MKLDNN - // since default config._use_mkldnn=true in this case, - // we should compare analysis_outputs in config._use_mkldnn=false - // with native_outputs as well. - FLAGS_use_MKLDNN = false; - AnalysisConfig cfg1; - SetConfig(&cfg1); - CompareNativeAndAnalysis(cfg1, input_slots_all); - FLAGS_use_MKLDNN = true; -#endif +TEST(Analyzer_vis, compare_mkldnn) { + AnalysisConfig cfg; + SetConfig(&cfg, true); + + std::vector> input_slots_all; + SetInput(&input_slots_all); + CompareNativeAndAnalysis(cfg, input_slots_all); } +#endif } // namespace analysis } // namespace inference diff --git a/paddle/fluid/inference/tests/api/tester_helper.h b/paddle/fluid/inference/tests/api/tester_helper.h index df9d0175673..a677783034c 100644 --- a/paddle/fluid/inference/tests/api/tester_helper.h +++ b/paddle/fluid/inference/tests/api/tester_helper.h @@ -35,7 +35,7 @@ DEFINE_bool(test_all_data, false, "Test the all dataset in data file."); DEFINE_int32(num_threads, 1, "Running the inference program in multi-threads."); DEFINE_bool(use_analysis, true, "Running the inference program in analysis mode."); -DEFINE_bool(use_MKLDNN, true, +DEFINE_bool(use_MKLDNN, false, "Running the inference program with mkldnn library."); namespace paddle { -- GitLab