MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / build

Method build

samples/sampleAlgorithmSelector/sampleAlgorithmSelector.cpp:431–521  ·  view source on GitHub ↗

\brief Creates the network, configures the builder and creates the network engine. \details This function creates the MNIST network by parsing the ONNX model and builds the engine that will be used to run MNIST (mEngine). \return true if the engine was created successfully and false otherwise.

Source from the content-addressed store, hash-verified

429//! \return true if the engine was created successfully and false otherwise.
430//!
431bool SampleAlgorithmSelector::build(IAlgorithmSelector* selector)
432{
433
434 auto builder = SampleUniquePtr<nvinfer1::IBuilder>(nvinfer1::createInferBuilder(sample::gLogger.getTRTLogger()));
435 if (!builder)
436 {
437 return false;
438 }
439 auto const networkFlags = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
440
441 auto network = SampleUniquePtr<nvinfer1::INetworkDefinition>(builder->createNetworkV2(networkFlags));
442 if (!network)
443 {
444 return false;
445 }
446
447 auto config = SampleUniquePtr<nvinfer1::IBuilderConfig>(builder->createBuilderConfig());
448 if (!config)
449 {
450 return false;
451 }
452
453 auto parser
454 = SampleUniquePtr<nvonnxparser::IParser>(nvonnxparser::createParser(*network, sample::gLogger.getTRTLogger()));
455 if (!parser)
456 {
457 return false;
458 }
459
460 auto constructed = constructNetwork(builder, network, config, parser);
461 if (!constructed)
462 {
463 return false;
464 }
465
466 builder->setMaxBatchSize(mParams.batchSize);
467 config->setAlgorithmSelector(selector);
468
469 if (mParams.fp16)
470 {
471 config->setFlag(BuilderFlag::kFP16);
472 }
473 if (mParams.int8)
474 {
475 config->setFlag(BuilderFlag::kINT8);
476 }
477
478 samplesCommon::enableDLA(builder.get(), config.get(), mParams.dlaCore, true /*GPUFallback*/);
479
480 if (mParams.int8)
481 {
482 // The sample fails for Int8 with kREJECT_EMPTY_ALGORITHMS flag set.
483 config->clearFlag(BuilderFlag::kREJECT_EMPTY_ALGORITHMS);
484 }
485
486 if (!mRuntime)
487 {
488 mRuntime = SampleUniquePtr<IRuntime>(createInferRuntime(sample::gLogger.getTRTLogger()));

Callers 1

mainFunction · 0.45

Calls 15

createInferBuilderFunction · 0.85
enableDLAFunction · 0.85
createInferRuntimeFunction · 0.85
makeCudaStreamFunction · 0.85
createNetworkV2Method · 0.80
createBuilderConfigMethod · 0.80
setAlgorithmSelectorMethod · 0.80
setFlagMethod · 0.80
clearFlagMethod · 0.80
setProfileStreamMethod · 0.80
deserializeCudaEngineMethod · 0.80

Tested by

no test coverage detected