@@ -164,35 +164,70 @@ void Net::save(const std::string & path)
164
164
file.write (reinterpret_cast <const char *>(plan_->data ()), plan_->size ());
165
165
}
166
166
167
- void Net::infer (std::vector<void *> & buffers, const int batch_size)
167
+ void Net::infer ([[maybe_unused]] std::vector<void *> & buffers, const int batch_size)
168
168
{
169
169
if (!context_) {
170
170
throw std::runtime_error (" Fail to create context" );
171
171
}
172
- auto input_dims = engine_->getBindingDimensions (0 );
172
+
173
+ #if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
174
+ const auto input_dims = engine_->getTensorShape (engine_->getIOTensorName (0 ));
175
+ context_->setInputShape (
176
+ engine_->getIOTensorName (0 ),
177
+ nvinfer1::Dims4 (batch_size, input_dims.d [1 ], input_dims.d [2 ], input_dims.d [3 ]));
178
+ context_->enqueueV3 (stream_);
179
+ #else
180
+ // Deprecated since 8.5
181
+ const auto input_dims = engine_->getBindingDimensions (0 );
173
182
context_->setBindingDimensions (
174
183
0 , nvinfer1::Dims4 (batch_size, input_dims.d [1 ], input_dims.d [2 ], input_dims.d [3 ]));
175
184
context_->enqueueV2 (buffers.data (), stream_, nullptr );
185
+ #endif
176
186
cudaStreamSynchronize (stream_);
177
187
}
178
188
179
189
std::vector<int > Net::getInputSize ()
180
190
{
181
- auto dims = engine_->getBindingDimensions (0 );
191
+ #if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
192
+ const auto dims = engine_->getTensorShape (engine_->getIOTensorName (0 ));
193
+ #else
194
+ // Deprecated since 8.5
195
+ const auto dims = engine_->getBindingDimensions (0 );
196
+ #endif
182
197
return {dims.d [1 ], dims.d [2 ], dims.d [3 ]};
183
198
}
184
199
185
200
std::vector<int > Net::getOutputScoreSize ()
186
201
{
187
- auto dims = engine_->getBindingDimensions (1 );
202
+ #if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
203
+ const auto dims = engine_->getTensorShape (engine_->getIOTensorName (1 ));
204
+ #else
205
+ // Deprecated since 8.5
206
+ const auto dims = engine_->getBindingDimensions (1 );
207
+ #endif
188
208
return {dims.d [1 ], dims.d [2 ]};
189
209
}
190
210
191
211
int Net::getMaxBatchSize ()
192
212
{
213
+ #if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
214
+ return engine_
215
+ ->getProfileShape (engine_->getIOTensorName (0 ), 0 , nvinfer1::OptProfileSelector::kMAX )
216
+ .d [0 ];
217
+ #else
218
+ // Deprecated since 8.5
193
219
return engine_->getProfileDimensions (0 , 0 , nvinfer1::OptProfileSelector::kMAX ).d [0 ];
220
+ #endif
194
221
}
195
222
196
- int Net::getMaxDetections () { return engine_->getBindingDimensions (1 ).d [1 ]; }
223
+ int Net::getMaxDetections ()
224
+ {
225
+ #if (NV_TENSORRT_MAJOR * 10000) + (NV_TENSORRT_MINOR * 100) + NV_TENSOR_PATCH >= 80500
226
+ return engine_->getTensorShape (engine_->getIOTensorName (1 )).d [1 ];
227
+ #else
228
+ // Deprecated since 8.5
229
+ return engine_->getBindingDimensions (1 ).d [1 ];
230
+ #endif
231
+ }
197
232
198
233
} // namespace ssd
0 commit comments