\brief Prepares the model for inference by creating an execution context and allocating buffers. \details This function sets up the sample for inference. This involves allocating buffers for the inputs and outputs, as well as creating TensorRT execution contexts for both engines. This only needs to be called a single time. \return false if error in build preprocessor or predict context.
| 344 | //! \return false if error in build preprocessor or predict context. |
| 345 | //! |
| 346 | bool SampleDynamicReshape::prepare() |
| 347 | { |
| 348 | mPreprocessorContext = makeUnique(mPreprocessorEngine->createExecutionContext()); |
| 349 | if (!mPreprocessorContext) |
| 350 | { |
| 351 | sample::gLogError << "Preprocessor context build failed." << std::endl; |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | mPredictionContext = makeUnique(mPredictionEngine->createExecutionContext()); |
| 357 | if (!mPredictionContext) |
| 358 | { |
| 359 | sample::gLogError << "Prediction context build failed." << std::endl; |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | // Since input dimensions are not known ahead of time, we only allocate the output buffer and preprocessor output |
| 364 | // buffer. |
| 365 | mPredictionInput.resize(mPredictionInputDims); |
| 366 | mOutput.hostBuffer.resize(mPredictionOutputDims); |
| 367 | mOutput.deviceBuffer.resize(mPredictionOutputDims); |
| 368 | return true; |
| 369 | } |
| 370 | |
| 371 | //! |
| 372 | //! \brief Runs inference for this sample |
no test coverage detected