From 146d70ca06e1de61d155784c6b9c9db867f6606c Mon Sep 17 00:00:00 2001 From: Yuanle Liu Date: Sat, 8 Oct 2022 14:56:45 +0800 Subject: [PATCH] optimize Paddle-TRT performance (#46682) * optimize Paddle-TRT performance --- paddle/fluid/inference/api/analysis_predictor.cc | 10 ++++++++++ paddle/fluid/inference/tensorrt/engine.cc | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index 7eca5aa126..2f6813b156 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -1246,6 +1246,16 @@ void AnalysisPredictor::PrepareArgument() { // NOTE All the members in AnalysisConfig should be copied to Argument. void AnalysisPredictor::OptimizeInferenceProgram() { PrepareArgument(); + +#ifdef PADDLE_WITH_TENSORRT + if (config_.tensorrt_engine_enabled()) { + inference::tensorrt::TensorRTEngine::predictor_id_per_thread = + predictor_id_; + VLOG(3) << "thread_local var predictor_id in TensorRTEngine is set to: " + << inference::tensorrt::TensorRTEngine::predictor_id_per_thread; + } +#endif + Analyzer().Run(&argument_); PADDLE_ENFORCE_EQ( diff --git a/paddle/fluid/inference/tensorrt/engine.cc b/paddle/fluid/inference/tensorrt/engine.cc index 8fc332399a..768555dd53 100644 --- a/paddle/fluid/inference/tensorrt/engine.cc +++ b/paddle/fluid/inference/tensorrt/engine.cc @@ -745,9 +745,8 @@ void TensorRTEngine::GetEngineInfo() { LOG(INFO) << "====== engine info ======"; std::unique_ptr infer_inspector( infer_engine_->createEngineInspector()); - auto infer_context = infer_ptr( - infer_engine_->createExecutionContextWithoutDeviceMemory()); - infer_inspector->setExecutionContext(infer_context.get()); + auto *infer_context = context(); + infer_inspector->setExecutionContext(infer_context); LOG(INFO) << infer_inspector->getEngineInformation( nvinfer1::LayerInformationFormat::kONELINE); LOG(INFO) << "====== engine info end ======"; -- GitLab