From d091d1b0a3a5fad28a9e8b12b9be3da3a011c053 Mon Sep 17 00:00:00 2001 From: Yuanle Liu Date: Tue, 11 Oct 2022 12:21:43 +0800 Subject: [PATCH] optimize Paddle-TRT performance (#46684) --- 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 33b3da0717b..eae515bdef5 100755 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -1244,6 +1244,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 0cf1d6352c3..eee6af7297a 100644 --- a/paddle/fluid/inference/tensorrt/engine.cc +++ b/paddle/fluid/inference/tensorrt/engine.cc @@ -646,9 +646,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