Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update trt api #1472

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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