\brief Creates the network, configures the builder and creates the network engine \details This function creates the network definition by parsing the Onnx model and builds the engine that will be used to run the model (mEngine) \return true if the engine was created successfully and false otherwise
| 128 | //! \return true if the engine was created successfully and false otherwise |
| 129 | //! |
| 130 | bool SampleNamedDimensions::build() |
| 131 | { |
| 132 | auto builder = SampleUniquePtr<nvinfer1::IBuilder>(nvinfer1::createInferBuilder(sample::gLogger.getTRTLogger())); |
| 133 | if (!builder) |
| 134 | { |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | auto const explicitBatch = 1U << static_cast<uint32_t>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH); |
| 139 | auto network = SampleUniquePtr<nvinfer1::INetworkDefinition>(builder->createNetworkV2(explicitBatch)); |
| 140 | if (!network) |
| 141 | { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | auto config = SampleUniquePtr<nvinfer1::IBuilderConfig>(builder->createBuilderConfig()); |
| 146 | if (!config) |
| 147 | { |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | auto parser |
| 152 | = SampleUniquePtr<nvonnxparser::IParser>(nvonnxparser::createParser(*network, sample::gLogger.getTRTLogger())); |
| 153 | if (!parser) |
| 154 | { |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | auto constructed = constructNetwork(builder, network, config, parser); |
| 159 | if (!constructed) |
| 160 | { |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | ASSERT(network->getNbInputs() == 2); |
| 165 | mInputDims.push_back(network->getInput(0)->getDimensions()); |
| 166 | mInputDims.push_back(network->getInput(1)->getDimensions()); |
| 167 | ASSERT(mInputDims[0].nbDims == 2); |
| 168 | ASSERT(mInputDims[1].nbDims == 2); |
| 169 | |
| 170 | ASSERT(network->getNbOutputs() == 1); |
| 171 | mOutputDims.push_back(network->getOutput(0)->getDimensions()); |
| 172 | ASSERT(mOutputDims[0].nbDims == 2); |
| 173 | |
| 174 | // CUDA stream used for profiling by the builder. |
| 175 | auto profileStream = samplesCommon::makeCudaStream(); |
| 176 | if (!profileStream) |
| 177 | { |
| 178 | return false; |
| 179 | } |
| 180 | config->setProfileStream(*profileStream); |
| 181 | |
| 182 | addOptimizationProfile(config, builder); |
| 183 | |
| 184 | SampleUniquePtr<IHostMemory> plan{builder->buildSerializedNetwork(*network, *config)}; |
| 185 | if (!plan) |
| 186 | { |
| 187 | return false; |
no test coverage detected