From e5b4643ad80da6ce3681adb286731b601b27da5b Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Thu, 18 Oct 2018 16:21:33 +0800 Subject: [PATCH] add profile_mkldnn test test=develop --- .../tests/api/analyzer_resnet50_tester.cc | 25 +++++++++--------- .../tests/api/analyzer_vis_tester.cc | 26 +++++++++---------- .../fluid/inference/tests/api/tester_helper.h | 2 -- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc b/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc index f10eb018c6d..67668298440 100644 --- a/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_resnet50_tester.cc @@ -20,14 +20,13 @@ namespace paddle { namespace inference { namespace analysis { -void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) { +void SetConfig(AnalysisConfig *cfg) { 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; - cfg->_use_mkldnn = _use_mkldnn; } void SetInput(std::vector> *inputs) { @@ -53,9 +52,10 @@ void SetInput(std::vector> *inputs) { } // Easy for profiling independently. -TEST(Analyzer_resnet50, profile) { +void profile(bool use_mkldnn = false) { AnalysisConfig cfg; SetConfig(&cfg); + cfg._use_mkldnn = use_mkldnn; std::vector outputs; std::vector> input_slots_all; @@ -70,6 +70,11 @@ TEST(Analyzer_resnet50, profile) { } } +TEST(Analyzer_resnet50, profile) { profile(); } +#ifndef PADDLE_WITH_MKLDNN +TEST(Analyzer_resnet50, profile_mkldnn) { profile(true /* use_mkldnn */); } +#endif + // Check the fuse status TEST(Analyzer_resnet50, fuse_statis) { AnalysisConfig cfg; @@ -83,25 +88,19 @@ TEST(Analyzer_resnet50, fuse_statis) { } // Compare result of NativeConfig and AnalysisConfig -TEST(Analyzer_resnet50, compare) { +void compare(bool use_mkldnn = false) { AnalysisConfig cfg; SetConfig(&cfg); + cfg._use_mkldnn = use_mkldnn; std::vector> input_slots_all; SetInput(&input_slots_all); CompareNativeAndAnalysis(cfg, input_slots_all); } -// Compare result of NativeConfig and AnalysisConfig with MKLDNN +TEST(Analyzer_resnet50, compare) { compare(); } #ifdef PADDLE_WITH_MKLDNN -TEST(Analyzer_resnet50, compare_mkldnn) { - AnalysisConfig cfg; - SetConfig(&cfg, true); - - std::vector> input_slots_all; - SetInput(&input_slots_all); - CompareNativeAndAnalysis(cfg, input_slots_all); -} +TEST(Analyzer_resnet50, compare_mkldnn) { compare(true /* use_mkldnn */); } #endif } // namespace analysis diff --git a/paddle/fluid/inference/tests/api/analyzer_vis_tester.cc b/paddle/fluid/inference/tests/api/analyzer_vis_tester.cc index 7da09274772..89332964907 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, bool _use_mkldnn = FLAGS_use_MKLDNN) { +void SetConfig(AnalysisConfig *cfg) { cfg->param_file = FLAGS_infer_model + "/__params__"; cfg->prog_file = FLAGS_infer_model + "/__model__"; cfg->use_gpu = false; @@ -59,7 +59,6 @@ void SetConfig(AnalysisConfig *cfg, bool _use_mkldnn = FLAGS_use_MKLDNN) { cfg->specify_input_name = true; // TODO(TJ): fix fusion gru cfg->ir_passes.push_back("fc_gru_fuse_pass"); - cfg->_use_mkldnn = _use_mkldnn; } void SetInput(std::vector> *inputs) { @@ -82,9 +81,10 @@ void SetInput(std::vector> *inputs) { // Easy for profiling independently. // ocr, mobilenet and se_resnext50 -TEST(Analyzer_vis, profile) { +void profile(bool use_mkldnn = false) { AnalysisConfig cfg; SetConfig(&cfg); + cfg._use_mkldnn = use_mkldnn; std::vector outputs; std::vector> input_slots_all; @@ -106,6 +106,12 @@ TEST(Analyzer_vis, profile) { } } +TEST(Analyzer_vis, profile) { profile(); } + +#ifdef PADDLE_WITH_MKLDNN +TEST(Analyzer_vis, profile_mkldnn) { profile(true /* use_mkldnn */); } +#endif + // Check the fuse status TEST(Analyzer_vis, fuse_statis) { AnalysisConfig cfg; @@ -116,25 +122,19 @@ TEST(Analyzer_vis, fuse_statis) { } // Compare result of NativeConfig and AnalysisConfig -TEST(Analyzer_vis, compare) { +void compare(bool use_mkldnn = false) { AnalysisConfig cfg; SetConfig(&cfg); + cfg._use_mkldnn = use_mkldnn; std::vector> input_slots_all; SetInput(&input_slots_all); CompareNativeAndAnalysis(cfg, input_slots_all); } -// Compare result of NativeConfig and AnalysisConfig with MKLDNN +TEST(Analyzer_vis, compare) { compare(); } #ifdef PADDLE_WITH_MKLDNN -TEST(Analyzer_vis, compare_mkldnn) { - AnalysisConfig cfg; - SetConfig(&cfg, true); - - std::vector> input_slots_all; - SetInput(&input_slots_all); - CompareNativeAndAnalysis(cfg, input_slots_all); -} +TEST(Analyzer_vis, compare_mkldnn) { compare(true /* use_mkldnn */); } #endif } // namespace analysis diff --git a/paddle/fluid/inference/tests/api/tester_helper.h b/paddle/fluid/inference/tests/api/tester_helper.h index bff781af25d..b1ee1080030 100644 --- a/paddle/fluid/inference/tests/api/tester_helper.h +++ b/paddle/fluid/inference/tests/api/tester_helper.h @@ -35,8 +35,6 @@ 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, false, - "Running the inference program with mkldnn library."); namespace paddle { namespace inference { -- GitLab