From 0b2bbe8ea75ebb81bb9ac8a1f8ad3c9be3fc453d Mon Sep 17 00:00:00 2001 From: kobayu858 <129580202+kobayu858@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:09:47 +0900 Subject: [PATCH] fix(autoware_tensorrt_common): fix bugprone-integer-division (#9660) fix: bugprone-error Signed-off-by: kobayu858 --- .../src/tensorrt_common.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/perception/autoware_tensorrt_common/src/tensorrt_common.cpp b/perception/autoware_tensorrt_common/src/tensorrt_common.cpp index 897010d22bb4b..990433ee277a0 100644 --- a/perception/autoware_tensorrt_common/src/tensorrt_common.cpp +++ b/perception/autoware_tensorrt_common/src/tensorrt_common.cpp @@ -311,12 +311,13 @@ void TrtCommon::printNetworkInfo(const std::string & onnx_file_path) int groups = conv->getNbGroups(); int stride = s_dims.d[0]; int num_weights = (dim_in.d[1] / groups) * dim_out.d[1] * k_dims.d[0] * k_dims.d[1]; - float gflops = (2 * num_weights) * (dim_in.d[3] / stride * dim_in.d[2] / stride / 1e9); - ; + float gflops = (2.0 * num_weights) * (static_cast(dim_in.d[3]) / stride * + static_cast(dim_in.d[2]) / stride / 1e9); total_gflops += gflops; total_params += num_weights; std::cout << "L" << i << " [conv " << k_dims.d[0] << "x" << k_dims.d[1] << " (" << groups - << ") " << "/" << s_dims.d[0] << "] " << dim_in.d[3] << "x" << dim_in.d[2] << "x" + << ") " + << "/" << s_dims.d[0] << "] " << dim_in.d[3] << "x" << dim_in.d[2] << "x" << dim_in.d[1] << " -> " << dim_out.d[3] << "x" << dim_out.d[2] << "x" << dim_out.d[1]; std::cout << " weights:" << num_weights; @@ -336,8 +337,10 @@ void TrtCommon::printNetworkInfo(const std::string & onnx_file_path) } else if (p_type == nvinfer1::PoolingType::kMAX_AVERAGE_BLEND) { std::cout << "max avg blend "; } - float gflops = dim_in.d[1] * dim_window.d[0] / dim_stride.d[0] * dim_window.d[1] / - dim_stride.d[1] * dim_in.d[2] * dim_in.d[3] / 1e9; + float gflops = static_cast(dim_in.d[1]) * + (static_cast(dim_window.d[0]) / static_cast(dim_stride.d[0])) * + (static_cast(dim_window.d[1]) / static_cast(dim_stride.d[1])) * + static_cast(dim_in.d[2]) * static_cast(dim_in.d[3]) / 1e9; total_gflops += gflops; std::cout << "pool " << dim_window.d[0] << "x" << dim_window.d[1] << "]"; std::cout << " GFLOPs:" << gflops; @@ -381,7 +384,8 @@ bool TrtCommon::buildEngineFromOnnx( if (num_available_dla > 0) { std::cout << "###" << num_available_dla << " DLAs are supported! ###" << std::endl; } else { - std::cout << "###Warning : " << "No DLA is supported! ###" << std::endl; + std::cout << "###Warning : " + << "No DLA is supported! ###" << std::endl; } config->setDefaultDeviceType(nvinfer1::DeviceType::kDLA); config->setDLACore(build_config_->dla_core_id);