\brief Builds the two engines required for inference. \details This function creates one TensorRT engine for resizing inputs to the correct sizes, then creates a TensorRT network by parsing the ONNX model and builds an engine that will be used to run inference (mPredictionEngine). \return false if error in build preprocessor or predict engine.
| 113 | //! \return false if error in build preprocessor or predict engine. |
| 114 | //! |
| 115 | bool SampleDynamicReshape::build() |
| 116 | { |
| 117 | auto builder = makeUnique(nvinfer1::createInferBuilder(sample::gLogger.getTRTLogger())); |
| 118 | if (!builder) |
| 119 | { |
| 120 | sample::gLogError << "Create inference builder failed." << std::endl; |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | auto runtime = makeUnique(nvinfer1::createInferRuntime(sample::gLogger.getTRTLogger())); |
| 125 | if (!runtime) |
| 126 | { |
| 127 | sample::gLogError << "Runtime object creation failed." << std::endl; |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | // This function will also set mPredictionInputDims and mPredictionOutputDims, |
| 132 | // so it needs to be called before building the preprocessor. |
| 133 | try |
| 134 | { |
| 135 | // CUDA stream used for profiling by the builder. |
| 136 | auto profileStream = samplesCommon::makeCudaStream(); |
| 137 | if (!profileStream) |
| 138 | { |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | bool result = buildPredictionEngine(builder, runtime, *profileStream) |
| 143 | && buildPreprocessorEngine(builder, runtime, *profileStream); |
| 144 | return result; |
| 145 | } |
| 146 | catch (std::runtime_error& e) |
| 147 | { |
| 148 | sample::gLogError << e.what() << std::endl; |
| 149 | return false; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | //! |
| 154 | //! \brief Builds an engine for preprocessing (mPreprocessorEngine). |
no test coverage detected