Skip to content

Commit 0b2bbe8

Browse files
authored
fix(autoware_tensorrt_common): fix bugprone-integer-division (#9660)
fix: bugprone-error Signed-off-by: kobayu858 <yutaro.kobayashi@tier4.jp>
1 parent e5243e4 commit 0b2bbe8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

perception/autoware_tensorrt_common/src/tensorrt_common.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,13 @@ void TrtCommon::printNetworkInfo(const std::string & onnx_file_path)
311311
int groups = conv->getNbGroups();
312312
int stride = s_dims.d[0];
313313
int num_weights = (dim_in.d[1] / groups) * dim_out.d[1] * k_dims.d[0] * k_dims.d[1];
314-
float gflops = (2 * num_weights) * (dim_in.d[3] / stride * dim_in.d[2] / stride / 1e9);
315-
;
314+
float gflops = (2.0 * num_weights) * (static_cast<float>(dim_in.d[3]) / stride *
315+
static_cast<float>(dim_in.d[2]) / stride / 1e9);
316316
total_gflops += gflops;
317317
total_params += num_weights;
318318
std::cout << "L" << i << " [conv " << k_dims.d[0] << "x" << k_dims.d[1] << " (" << groups
319-
<< ") " << "/" << s_dims.d[0] << "] " << dim_in.d[3] << "x" << dim_in.d[2] << "x"
319+
<< ") "
320+
<< "/" << s_dims.d[0] << "] " << dim_in.d[3] << "x" << dim_in.d[2] << "x"
320321
<< dim_in.d[1] << " -> " << dim_out.d[3] << "x" << dim_out.d[2] << "x"
321322
<< dim_out.d[1];
322323
std::cout << " weights:" << num_weights;
@@ -336,8 +337,10 @@ void TrtCommon::printNetworkInfo(const std::string & onnx_file_path)
336337
} else if (p_type == nvinfer1::PoolingType::kMAX_AVERAGE_BLEND) {
337338
std::cout << "max avg blend ";
338339
}
339-
float gflops = dim_in.d[1] * dim_window.d[0] / dim_stride.d[0] * dim_window.d[1] /
340-
dim_stride.d[1] * dim_in.d[2] * dim_in.d[3] / 1e9;
340+
float gflops = static_cast<float>(dim_in.d[1]) *
341+
(static_cast<float>(dim_window.d[0]) / static_cast<float>(dim_stride.d[0])) *
342+
(static_cast<float>(dim_window.d[1]) / static_cast<float>(dim_stride.d[1])) *
343+
static_cast<float>(dim_in.d[2]) * static_cast<float>(dim_in.d[3]) / 1e9;
341344
total_gflops += gflops;
342345
std::cout << "pool " << dim_window.d[0] << "x" << dim_window.d[1] << "]";
343346
std::cout << " GFLOPs:" << gflops;
@@ -381,7 +384,8 @@ bool TrtCommon::buildEngineFromOnnx(
381384
if (num_available_dla > 0) {
382385
std::cout << "###" << num_available_dla << " DLAs are supported! ###" << std::endl;
383386
} else {
384-
std::cout << "###Warning : " << "No DLA is supported! ###" << std::endl;
387+
std::cout << "###Warning : "
388+
<< "No DLA is supported! ###" << std::endl;
385389
}
386390
config->setDefaultDeviceType(nvinfer1::DeviceType::kDLA);
387391
config->setDLACore(build_config_->dla_core_id);

0 commit comments

Comments
 (0)