\brief Creates the network, configures the builder and creates the network engine \details This function creates the single layer network by manual insertion and builds the engine \return true if the engine was created successfully and false otherwise
| 301 | //! \return true if the engine was created successfully and false otherwise |
| 302 | //! |
| 303 | bool SampleIOFormats::build(int32_t dataWidth) |
| 304 | { |
| 305 | auto builder = SampleUniquePtr<nvinfer1::IBuilder>(nvinfer1::createInferBuilder(sample::gLogger.getTRTLogger())); |
| 306 | if (!builder) |
| 307 | { |
| 308 | return false; |
| 309 | } |
| 310 | auto const networkFlags = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH); |
| 311 | |
| 312 | auto network = SampleUniquePtr<nvinfer1::INetworkDefinition>(builder->createNetworkV2(networkFlags)); |
| 313 | if (!network) |
| 314 | { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | auto config = SampleUniquePtr<nvinfer1::IBuilderConfig>(builder->createBuilderConfig()); |
| 319 | if (!config) |
| 320 | { |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | auto parser |
| 325 | = SampleUniquePtr<nvonnxparser::IParser>(nvonnxparser::createParser(*network, sample::gLogger.getTRTLogger())); |
| 326 | if (!parser) |
| 327 | { |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | auto constructed = constructNetwork(builder, network, config, parser); |
| 332 | if (!constructed) |
| 333 | { |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | network->getInput(0)->setAllowedFormats(static_cast<TensorFormats>(1 << static_cast<int32_t>(mTensorFormat))); |
| 338 | network->getOutput(0)->setAllowedFormats(1U << static_cast<int32_t>(TensorFormat::kLINEAR)); |
| 339 | |
| 340 | mEngine.reset(); |
| 341 | |
| 342 | if (dataWidth == 1) |
| 343 | { |
| 344 | config->setFlag(BuilderFlag::kINT8); |
| 345 | network->getInput(0)->setType(DataType::kINT8); |
| 346 | network->getOutput(0)->setType(DataType::kINT8); |
| 347 | samplesCommon::setAllDynamicRanges(network.get(), 127.0F, 127.0F); |
| 348 | } |
| 349 | if (dataWidth == 2) |
| 350 | { |
| 351 | config->setFlag(BuilderFlag::kFP16); |
| 352 | network->getInput(0)->setType(DataType::kHALF); |
| 353 | network->getOutput(0)->setType(DataType::kHALF); |
| 354 | } |
| 355 | |
| 356 | config->setFlag(BuilderFlag::kGPU_FALLBACK); |
| 357 | |
| 358 | // CUDA stream used for profiling by the builder. |
| 359 | auto profileStream = samplesCommon::makeCudaStream(); |
| 360 | if (!profileStream) |
no test coverage detected