Apollo 11.0
自动驾驶开放平台
apollo::prediction::MultiAgentPedestrianTensorrt类 参考

#include <multi_agent_pedestrian_tensorrt.h>

类 apollo::prediction::MultiAgentPedestrianTensorrt 继承关系图:
apollo::prediction::MultiAgentPedestrianTensorrt 的协作图:

Public 成员函数

 MultiAgentPedestrianTensorrt ()
 Construct a new Multi Agent Vectornet Tensorrt object
 
 ~MultiAgentPedestrianTensorrt ()
 Destroy the Multi Agent Vectornet Tensorrt object
 
virtual bool Init ()
 parse model description class and load the model
 
virtual bool Inference (const std::vector< void * > &input_buffer, unsigned int input_size, std::vector< void * > *output_buffer, unsigned int output_size)
 performing network inference
 
virtual bool LoadModel ()
 load the model from file
 
virtual void Destory ()
 free all memory requested, gpu or cpu
 
- Public 成员函数 继承自 apollo::prediction::ModelBase
 ModelBase ()
 
 ~ModelBase ()
 

额外继承的成员函数

- Public 属性 继承自 apollo::prediction::ModelBase
std::string model_path_
 
uint8_t init_ = 0
 

详细描述

在文件 multi_agent_pedestrian_tensorrt.h35 行定义.

构造及析构函数说明

◆ MultiAgentPedestrianTensorrt()

apollo::prediction::MultiAgentPedestrianTensorrt::MultiAgentPedestrianTensorrt ( )
inline

Construct a new Multi Agent Vectornet Tensorrt object

在文件 multi_agent_pedestrian_tensorrt.h41 行定义.

41{}

◆ ~MultiAgentPedestrianTensorrt()

apollo::prediction::MultiAgentPedestrianTensorrt::~MultiAgentPedestrianTensorrt ( )
inline

Destroy the Multi Agent Vectornet Tensorrt object

在文件 multi_agent_pedestrian_tensorrt.h47 行定义.

47 {
48 Destory();
49 }
virtual void Destory()
free all memory requested, gpu or cpu

成员函数说明

◆ Destory()

void apollo::prediction::MultiAgentPedestrianTensorrt::Destory ( )
virtual

free all memory requested, gpu or cpu

返回
memory release result, true for success

实现了 apollo::prediction::ModelBase.

在文件 multi_agent_pedestrian_tensorrt.cc181 行定义.

181 {
182 cudaStreamDestroy(stream_);
183 cudaFree(buffers_[input_multi_obstacle_pos_index_]);
184 cudaFree(buffers_[input_multi_obstacle_pos_step_index_]);
185 cudaFree(buffers_[input_vector_data_index_]);
186 cudaFree(buffers_[input_bool_vector_mask_index_]);
187 cudaFree(buffers_[input_bool_polyline_mask_index_]);
188 cudaFree(buffers_[input_rand_mask_index_]);
189 cudaFree(buffers_[input_polyline_id_index_]);
190 cudaFree(buffers_[input_obs_position_index_]);
191 cudaFree(buffers_[output_index_]);
192}

◆ Inference()

bool apollo::prediction::MultiAgentPedestrianTensorrt::Inference ( const std::vector< void * > &  input_buffer,
unsigned int  input_size,
std::vector< void * > *  output_buffer,
unsigned int  output_size 
)
virtual

performing network inference

参数
input_buffervector of input tensor
input_sizesize of input_buffer
output_buffervector of output tensor
output_sizesize of output_buffer
返回
init result, true for success

实现了 apollo::prediction::ModelBase.

在文件 multi_agent_pedestrian_tensorrt.cc106 行定义.

110 {
111 ACHECK(input_size == input_buffer.size() && input_size == 8);
112 ACHECK(output_size == output_buffer->size() && output_size == 1);
113
114 if (init_ == 0) {
115 Init();
116 }
117
118 // ensure thread safe for inference
119 std::lock_guard<std::mutex> lck(mtx);
120
121 cudaMemcpyAsync(
122 buffers_[input_multi_obstacle_pos_index_],
123 input_buffer[0],
124 1 * max_agent_num * 20 * 2 * sizeof(float),
125 cudaMemcpyHostToDevice,
126 stream_);
127 cudaMemcpyAsync(
128 buffers_[input_multi_obstacle_pos_step_index_],
129 input_buffer[1],
130 1 * max_agent_num * 20 * 2 * sizeof(float),
131 cudaMemcpyHostToDevice,
132 stream_);
133 cudaMemcpyAsync(
134 buffers_[input_vector_data_index_],
135 input_buffer[2],
136 1 * 450 * 50 * 9 * sizeof(float),
137 cudaMemcpyHostToDevice,
138 stream_);
139 cudaMemcpyAsync(
140 buffers_[input_bool_vector_mask_index_],
141 input_buffer[3],
142 1 * 450 * 50 * sizeof(bool),
143 cudaMemcpyHostToDevice,
144 stream_);
145 cudaMemcpyAsync(
146 buffers_[input_bool_polyline_mask_index_],
147 input_buffer[4],
148 1 * 450 * sizeof(bool),
149 cudaMemcpyHostToDevice,
150 stream_);
151 cudaMemcpyAsync(
152 buffers_[input_rand_mask_index_],
153 input_buffer[5],
154 1 * 450 * sizeof(bool),
155 cudaMemcpyHostToDevice,
156 stream_);
157 cudaMemcpyAsync(
158 buffers_[input_polyline_id_index_],
159 input_buffer[6],
160 1 * 450 * 2 * sizeof(float),
161 cudaMemcpyHostToDevice,
162 stream_);
163 cudaMemcpyAsync(
164 buffers_[input_obs_position_index_],
165 input_buffer[7],
166 1 * max_agent_num * 3 * sizeof(float),
167 cudaMemcpyHostToDevice,
168 stream_);
169 if (!context_->enqueueV2(buffers_.data(), stream_, nullptr)) {
170 return false;
171 }
172 cudaMemcpyAsync(
173 (*output_buffer)[0], buffers_[output_index_],
174 1 * max_agent_num * 30 * 2 * sizeof(float),
175 cudaMemcpyDeviceToHost,
176 stream_);
177 cudaStreamSynchronize(stream_);
178 return true;
179}
virtual bool Init()
parse model description class and load the model
#define ACHECK(cond)
Definition log.h:80

◆ Init()

bool apollo::prediction::MultiAgentPedestrianTensorrt::Init ( )
virtual

parse model description class and load the model

参数
model_configclass to describe model
返回
init result, true for success

实现了 apollo::prediction::ModelBase.

在文件 multi_agent_pedestrian_tensorrt.cc194 行定义.

194 {
195 ModelConf model_config;
196 int status = 0;
197
198 if (init_ != 0) {
199 return true;
200 }
201
202 std::string class_name = abi::__cxa_demangle(
203 typeid(*this).name(), 0, 0, &status);
204 std::string default_config_path
206 GetPluginConfPath<ModelBase>(class_name, "conf/default_conf.pb.txt");
207
208 if (!cyber::common::GetProtoFromFile(default_config_path, &model_config)) {
209 AERROR << "Unable to load model conf file: " << default_config_path;
210 return false;
211 }
212 model_path_ = model_config.model_path();
213 init_ = 1;
214
215 return LoadModel();
216}
static PluginManager * Instance()
get singleton instance of PluginManager
#define AERROR
Definition log.h:44
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

◆ LoadModel()

bool apollo::prediction::MultiAgentPedestrianTensorrt::LoadModel ( )
virtual

load the model from file

返回
loading result, true for success

实现了 apollo::prediction::ModelBase.

在文件 multi_agent_pedestrian_tensorrt.cc29 行定义.

29 {
30 std::ifstream engine_file(model_path_, std::ios::binary);
31 engine_file.seekg(0, std::ifstream::end);
32 int64_t engine_size = engine_file.tellg();
33 ACHECK(engine_size > 0);
34 engine_file.seekg(0, std::ifstream::beg);
35
36 void* engine_blob = malloc(engine_size);
37 engine_file.read(reinterpret_cast<char*>(engine_blob), engine_size);
38
39 runtime_ = nvinfer1::createInferRuntime(rt_gLogger);
40 if (!runtime_) {
41 AERROR << "create runtime failed";
42 return false;
43 }
44
45 engine_ = runtime_->deserializeCudaEngine(engine_blob, engine_size);
46 if (!engine_) {
47 AERROR << "create engine failed";
48 return false;
49 }
50
51 context_ = engine_->createExecutionContext();
52 if (!context_) {
53 AERROR << "create context failed";
54 return false;
55 }
56 // check model input output
57 ACHECK(engine_->getNbBindings() == 9);
58
59 input_multi_obstacle_pos_index_ =
60 engine_->getBindingIndex(INPUT_MULTI_OBSTACLE_POS_NAME);
61 input_multi_obstacle_pos_step_index_ =
62 engine_->getBindingIndex(INPUT_MULTI_OBSTACLE_POS_STEP_NAME);
63 input_vector_data_index_ =
64 engine_->getBindingIndex(INPUT_VECTOR_DATA_NAME);
65 input_bool_vector_mask_index_ =
66 engine_->getBindingIndex(INPUT_BOOL_VECTOR_MASK_NAME);
67 input_bool_polyline_mask_index_ =
68 engine_->getBindingIndex(INPUT_BOOL_POLYLINE_MASK_NAME);
69 input_rand_mask_index_ =
70 engine_->getBindingIndex(INPUT_RAND_MASK_NAME);
71 input_polyline_id_index_ =
72 engine_->getBindingIndex(INPUT_POLYLINE_ID_NAME);
73 input_obs_position_index_ =
74 engine_->getBindingIndex(INPUT_OBS_POSITION_NAME);
75 output_index_ =
76 engine_->getBindingIndex(OUTPUT_NAME);
77
78 buffers_ = std::vector<void*>{nullptr, nullptr, nullptr, nullptr,
79 nullptr, nullptr, nullptr, nullptr, nullptr};
80
81 // size based on the shape of model input and output
82 cudaMalloc(&buffers_[input_multi_obstacle_pos_index_],
83 1 * max_agent_num * 20 * 2 * sizeof(float));
84 cudaMalloc(&buffers_[input_multi_obstacle_pos_step_index_],
85 1 * max_agent_num * 20 * 2 * sizeof(float));
86 cudaMalloc(&buffers_[input_vector_data_index_],
87 1 * 450 * 50 * 9 * sizeof(float));
88 cudaMalloc(&buffers_[input_bool_vector_mask_index_],
89 1 * 450 * 50 * sizeof(bool));
90 cudaMalloc(&buffers_[input_bool_polyline_mask_index_],
91 1 * 450 * sizeof(bool));
92 cudaMalloc(&buffers_[input_rand_mask_index_],
93 1 * 450 * sizeof(bool));
94 cudaMalloc(&buffers_[input_polyline_id_index_],
95 1 * 450 * 2 * sizeof(float));
96 cudaMalloc(&buffers_[input_obs_position_index_],
97 1 * max_agent_num * 3 * sizeof(float));
98 cudaMalloc(&buffers_[output_index_],
99 1 * max_agent_num * 30 * 2 * sizeof(float));
100
101 cudaStreamCreate(&stream_);
102
103 return true;
104}

该类的文档由以下文件生成: