From 237c1fe63e8504d00d88448e5e09de9abcc8578e Mon Sep 17 00:00:00 2001 From: Leo Chen <39020268+leo0519@users.noreply.github.com> Date: Fri, 17 Dec 2021 14:30:08 +0800 Subject: [PATCH] [Paddle-TRT] Use TRT inspector to show the information inside an engine to verbose log (#38200) * Inspect the information inside a TRT engine. * Follow up the google code style. * Fix code error. --- paddle/fluid/inference/tensorrt/engine.cc | 8 ++++++++ paddle/fluid/inference/tensorrt/engine.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/paddle/fluid/inference/tensorrt/engine.cc b/paddle/fluid/inference/tensorrt/engine.cc index 2addff52829..cb815e00c44 100644 --- a/paddle/fluid/inference/tensorrt/engine.cc +++ b/paddle/fluid/inference/tensorrt/engine.cc @@ -54,6 +54,7 @@ void TensorRTEngine::Execute(int batch_size, std::vector *buffers, } else { #if IS_TRT_VERSION_GE(6000) infer_context->enqueueV2(buffers->data(), stream, nullptr); + GetEngineInfo(); #endif } SetRuntimeBatch(batch_size); @@ -237,6 +238,11 @@ void TensorRTEngine::FreezeNetwork() { #endif } +#if IS_TRT_VERSION_GE(8200) + infer_builder_config_->setProfilingVerbosity( + nvinfer1::ProfilingVerbosity::kDETAILED); +#endif + #if IS_TRT_VERSION_LT(8000) infer_engine_.reset(infer_builder_->buildEngineWithConfig( *network(), *infer_builder_config_)); @@ -253,6 +259,8 @@ void TensorRTEngine::FreezeNetwork() { infer_engine_, platform::errors::Fatal( "Build TensorRT cuda engine failed! Please recheck " "you configurations related to paddle-TensorRT.")); + + GetEngineInfo(); } nvinfer1::ITensor *TensorRTEngine::DeclareInput(const std::string &name, diff --git a/paddle/fluid/inference/tensorrt/engine.h b/paddle/fluid/inference/tensorrt/engine.h index 9397d4e89de..e6f58c8c8e8 100644 --- a/paddle/fluid/inference/tensorrt/engine.h +++ b/paddle/fluid/inference/tensorrt/engine.h @@ -321,6 +321,8 @@ class TensorRTEngine { "on the same GPU architecture;\n2. The Paddle Inference version of " "generating serialization file and doing inference are " "consistent.")); + + GetEngineInfo(); } void SetRuntimeBatch(size_t batch_size); @@ -538,6 +540,18 @@ class TensorRTEngine { } } + void GetEngineInfo() { +#if IS_TRT_VERSION_GE(8200) + std::unique_ptr infer_inspector( + infer_engine_->createEngineInspector()); + infer_inspector->setExecutionContext(context()); + VLOG(3) << infer_inspector->getEngineInformation( + nvinfer1::LayerInformationFormat::kJSON); +#else + VLOG(3) << "Inspector needs TensorRT version 8.2 and after."; +#endif + } + private: // Each ICudaEngine object is bound to a specific GPU when it is instantiated, // ensure that the thread is associated with the correct device by calling -- GitLab