Skip to content

Commit

Permalink
fix: update trt api (autowarefoundation#1472)
Browse files Browse the repository at this point in the history
* fix: update trt api

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>

* compatible build with tensorrt 8.2

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>

* revert changes for caffe parser

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
  • Loading branch information
wep21 authored and boyali committed Oct 3, 2022
1 parent b46bf6a commit 812a8c5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions perception/lidar_apollo_instance_segmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
${PCL_LIBRARIES}
)

target_compile_options(tensorrt_apollo_cnn_lib
PUBLIC
-Wno-deprecated-declarations
)

ament_auto_add_library(lidar_apollo_instance_segmentation SHARED
src/node.cpp
src/detector.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ LidarApolloInstanceSegmentation::LidarApolloInstanceSegmentation(rclcpp::Node *
RCLCPP_ERROR(node_->get_logger(), "can not find output named %s", output_node.c_str());
}
network->markOutput(*output);
const int batch_size = 1;
builder->setMaxBatchSize(batch_size);
#if (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 8400
config->setMemoryPoolLimit(nvinfer1::MemoryPoolType::kWORKSPACE, 1 << 30);
#else
config->setMaxWorkspaceSize(1 << 30);
#endif
nvinfer1::IHostMemory * plan = builder->buildSerializedNetwork(*network, *config);
assert(plan != nullptr);
std::ofstream outfile(engine_file, std::ofstream::binary);
Expand Down
4 changes: 4 additions & 0 deletions perception/lidar_centerpoint/lib/network/tensorrt_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ bool TensorRTWrapper::parseONNX(
std::cout << "Fail to create config" << std::endl;
return false;
}
#if (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 8400
config->setMemoryPoolLimit(nvinfer1::MemoryPoolType::kWORKSPACE, workspace_size);
#else
config->setMaxWorkspaceSize(workspace_size);
#endif
if (precision == "fp16") {
if (builder->platformHasFastFp16()) {
std::cout << "use TensorRT FP16 Inference" << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions perception/tensorrt_yolo/lib/src/trt_yolo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ Net::Net(
if (fp16 || int8) {
config->setFlag(nvinfer1::BuilderFlag::kFP16);
}
#if (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 8400
config->setMemoryPoolLimit(nvinfer1::MemoryPoolType::kWORKSPACE, workspace_size);
#else
config->setMaxWorkspaceSize(workspace_size);
#endif

// Parse ONNX FCN
std::cout << "Building " << precision << " core model..." << std::endl;
Expand Down
8 changes: 5 additions & 3 deletions perception/traffic_light_classifier/utils/trt_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ TrtCommon::TrtCommon(std::string model_path, std::string precision)
precision_(precision),
input_name_("input_0"),
output_name_("output_0"),
is_initialized_(false),
max_batch_size_(1)
is_initialized_(false)
{
runtime_ = UniquePtr<nvinfer1::IRuntime>(nvinfer1::createInferRuntime(logger_));
}
Expand Down Expand Up @@ -106,8 +105,11 @@ bool TrtCommon::buildEngineFromOnnx(std::string onnx_file_path, std::string outp
return false;
}

builder->setMaxBatchSize(max_batch_size_);
#if (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 8400
config->setMemoryPoolLimit(nvinfer1::MemoryPoolType::kWORKSPACE, 16 << 20);
#else
config->setMaxWorkspaceSize(16 << 20);
#endif

if (precision_ == "fp16") {
config->setFlag(nvinfer1::BuilderFlag::kFP16);
Expand Down
1 change: 0 additions & 1 deletion perception/traffic_light_classifier/utils/trt_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class TrtCommon
std::string input_name_;
std::string output_name_;
bool is_initialized_;
size_t max_batch_size_;
};

} // namespace Tn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ Net::Net(
if (fp16 || int8) {
config->setFlag(nvinfer1::BuilderFlag::kFP16);
}
#if (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 8400
config->setMemoryPoolLimit(nvinfer1::MemoryPoolType::kWORKSPACE, workspace_size);
#else
config->setMaxWorkspaceSize(workspace_size);
#endif

// Parse ONNX FCN
std::cout << "Building " << precision << " core model..." << std::endl;
Expand Down

0 comments on commit 812a8c5

Please sign in to comment.