From 04dd2861cffd5c058bafabf0f93e79536b938bda Mon Sep 17 00:00:00 2001 From: Wilber Date: Thu, 15 Dec 2022 10:22:40 +0800 Subject: [PATCH] [Inference] memory_optimize and mkdlnn problem (#49054) * memory_optimize and mkdlnn problem * update * update * update --- paddle/fluid/inference/api/analysis_config.cc | 14 ++++++++++++++ .../api/analyzer_capi_exp_pd_config_tester.cc | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/inference/api/analysis_config.cc b/paddle/fluid/inference/api/analysis_config.cc index 58b0d2a1189..0b39041c971 100644 --- a/paddle/fluid/inference/api/analysis_config.cc +++ b/paddle/fluid/inference/api/analysis_config.cc @@ -948,8 +948,22 @@ void AnalysisConfig::Update() { #endif } + // TODO(inference): When we enable memory_optimize and mkldnn, PaddleSeg model + // fail. if (enable_memory_optim_) { +#ifdef PADDLE_WITH_MKLDNN + if (use_mkldnn_) { + enable_memory_optim_ = false; + LOG_FIRST_N(WARNING, 1) + << "It is detected that mkldnn and memory_optimize_pass are enabled " + "at the same time, but they are not supported yet. Currently, " + "memory_optimize_pass is explicitly disabled"; + } else { + pass_builder()->AppendAnalysisPass("memory_optimize_pass"); + } +#else pass_builder()->AppendAnalysisPass("memory_optimize_pass"); +#endif } if (use_lite_) { diff --git a/paddle/fluid/inference/tests/api/analyzer_capi_exp_pd_config_tester.cc b/paddle/fluid/inference/tests/api/analyzer_capi_exp_pd_config_tester.cc index cbf0e615c4d..804ac21ea40 100644 --- a/paddle/fluid/inference/tests/api/analyzer_capi_exp_pd_config_tester.cc +++ b/paddle/fluid/inference/tests/api/analyzer_capi_exp_pd_config_tester.cc @@ -55,6 +55,10 @@ TEST(PD_Config, interface) { bool ir_optim = PD_ConfigIrOptim(config); EXPECT_TRUE(ir_optim); + PD_ConfigEnableMemoryOptim(config, true); + bool memory_enabled = PD_ConfigMemoryOptimEnabled(config); + EXPECT_TRUE(memory_enabled); + #ifndef PADDLE_WITH_LITE PD_ConfigEnableLiteEngine( config, PD_PRECISION_FLOAT32, TRUE, 0, nullptr, 0, nullptr); @@ -95,10 +99,6 @@ TEST(PD_Config, interface) { EXPECT_FALSE(onnxruntime_disabled); PD_ConfigEnableORTOptimization(config); - PD_ConfigEnableMemoryOptim(config, true); - bool memory_enabled = PD_ConfigMemoryOptimEnabled(config); - EXPECT_TRUE(memory_enabled); - PD_ConfigEnableProfile(config); bool profile_enabled = PD_ConfigProfileEnabled(config); EXPECT_TRUE(profile_enabled); -- GitLab