From 9bd20aa0d24aa1c459cb2775879754fdd05a8456 Mon Sep 17 00:00:00 2001 From: zlsh80826 Date: Thu, 15 Dec 2022 11:20:52 +0800 Subject: [PATCH] Add a persistent ibuilder to speedup unit test (#48906) --- paddle/fluid/inference/tensorrt/engine.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/paddle/fluid/inference/tensorrt/engine.h b/paddle/fluid/inference/tensorrt/engine.h index 81e4ca8980..c1fa94ef42 100644 --- a/paddle/fluid/inference/tensorrt/engine.h +++ b/paddle/fluid/inference/tensorrt/engine.h @@ -852,6 +852,15 @@ class TRTEngineManager { size_t max_ctx_mem_size_{0}; std::unordered_map context_memorys_; std::unordered_map> engines_; + // createInferBuilder loads trt kernels and take a few second + // But as long as one IBuilder lives, trt kernel will not be unloaded + // Hence, a persistent IBuilder to avoid TensorRT unload/reload kernels + std::unique_ptr> + holder{createInferBuilder(&NaiveLogger::Global()), [](auto* ptr) { + if (ptr) { + ptr->destroy(); + } + }}; }; } // namespace tensorrt -- GitLab