From 44417831bab3cb14742c670c84efc57293ed4714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Wed, 21 Dec 2022 20:44:22 +0300 Subject: [PATCH] fix(tensorrt): update tensorrt code of traffic_light_ssd_fine_detector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: M. Fatih Cırıt --- .../lib/include/trt_ssd.hpp | 2 +- .../lib/src/trt_ssd.cpp | 45 ++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/perception/traffic_light_ssd_fine_detector/lib/include/trt_ssd.hpp b/perception/traffic_light_ssd_fine_detector/lib/include/trt_ssd.hpp index cfb6c8a6d5754..7455001b1e810 100644 --- a/perception/traffic_light_ssd_fine_detector/lib/include/trt_ssd.hpp +++ b/perception/traffic_light_ssd_fine_detector/lib/include/trt_ssd.hpp @@ -72,7 +72,7 @@ class Net void save(const std::string & path); // Infer using pre-allocated GPU buffers {data, scores, boxes} - void infer(std::vector & buffers, const int batch_size); + void infer([[maybe_unused]] std::vector & buffers, const int batch_size); // Get (c, h, w) size of the fixed input std::vector getInputSize(); diff --git a/perception/traffic_light_ssd_fine_detector/lib/src/trt_ssd.cpp b/perception/traffic_light_ssd_fine_detector/lib/src/trt_ssd.cpp index d810eb5275058..480fccbdad262 100644 --- a/perception/traffic_light_ssd_fine_detector/lib/src/trt_ssd.cpp +++ b/perception/traffic_light_ssd_fine_detector/lib/src/trt_ssd.cpp @@ -164,35 +164,70 @@ void Net::save(const std::string & path) file.write(reinterpret_cast(plan_->data()), plan_->size()); } -void Net::infer(std::vector & buffers, const int batch_size) +void Net::infer([[maybe_unused]] std::vector & buffers, const int batch_size) { if (!context_) { throw std::runtime_error("Fail to create context"); } - auto input_dims = engine_->getBindingDimensions(0); + +#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500 + const auto input_dims = engine_->getTensorShape(engine_->getIOTensorName(0)); + context_->setInputShape( + engine_->getIOTensorName(0), + nvinfer1::Dims4(batch_size, input_dims.d[1], input_dims.d[2], input_dims.d[3])); + context_->enqueueV3(stream_); +#else + // Deprecated since 8.5 + const auto input_dims = engine_->getBindingDimensions(0); context_->setBindingDimensions( 0, nvinfer1::Dims4(batch_size, input_dims.d[1], input_dims.d[2], input_dims.d[3])); context_->enqueueV2(buffers.data(), stream_, nullptr); +#endif cudaStreamSynchronize(stream_); } std::vector Net::getInputSize() { - auto dims = engine_->getBindingDimensions(0); +#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500 + const auto dims = engine_->getTensorShape(engine_->getIOTensorName(0)); +#else + // Deprecated since 8.5 + const auto dims = engine_->getBindingDimensions(0); +#endif return {dims.d[1], dims.d[2], dims.d[3]}; } std::vector Net::getOutputScoreSize() { - auto dims = engine_->getBindingDimensions(1); +#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500 + const auto dims = engine_->getTensorShape(engine_->getIOTensorName(1)); +#else + // Deprecated since 8.5 + const auto dims = engine_->getBindingDimensions(1); +#endif return {dims.d[1], dims.d[2]}; } int Net::getMaxBatchSize() { +#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500 + return engine_ + ->getProfileShape(engine_->getIOTensorName(0), 0, nvinfer1::OptProfileSelector::kMAX) + .d[0]; +#else + // Deprecated since 8.5 return engine_->getProfileDimensions(0, 0, nvinfer1::OptProfileSelector::kMAX).d[0]; +#endif } -int Net::getMaxDetections() { return engine_->getBindingDimensions(1).d[1]; } +int Net::getMaxDetections() +{ +#if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500 + return engine_->getTensorShape(engine_->getIOTensorName(1)).d[1]; +#else + // Deprecated since 8.5 + return engine_->getBindingDimensions(1).d[1]; +#endif +} } // namespace ssd