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

Method build

samples/sampleINT8API/sampleINT8API.cpp:494–610  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

492//! \return true if the engine was created successfully and false otherwise
493//!
494sample::Logger::TestResult SampleINT8API::build()
495{
496 auto builder = SampleUniquePtr<nvinfer1::IBuilder>(nvinfer1::createInferBuilder(sample::gLogger.getTRTLogger()));
497 if (!builder)
498 {
499 sample::gLogError << "Unable to create builder object." << std::endl;
500 return sample::Logger::TestResult::kFAILED;
501 }
502
503 if (!builder->platformHasFastInt8())
504 {
505 sample::gLogError << "Platform does not support INT8 inference. sampleINT8API can only run in INT8 Mode." << std::endl;
506 return sample::Logger::TestResult::kWAIVED;
507 }
508
509 const auto explicitBatch = 1U << static_cast<uint32_t>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
510 auto network = SampleUniquePtr<nvinfer1::INetworkDefinition>(builder->createNetworkV2(explicitBatch));
511 if (!network)
512 {
513 sample::gLogError << "Unable to create network object." << mParams.referenceFileName << std::endl;
514 return sample::Logger::TestResult::kFAILED;
515 }
516
517 auto config = SampleUniquePtr<nvinfer1::IBuilderConfig>(builder->createBuilderConfig());
518 if (!config)
519 {
520 sample::gLogError << "Unable to create config object." << mParams.referenceFileName << std::endl;
521 return sample::Logger::TestResult::kFAILED;
522 }
523
524 auto parser
525 = SampleUniquePtr<nvonnxparser::IParser>(nvonnxparser::createParser(*network, sample::gLogger.getTRTLogger()));
526 if (!parser)
527 {
528 sample::gLogError << "Unable to create parser object." << mParams.referenceFileName << std::endl;
529 return sample::Logger::TestResult::kFAILED;
530 }
531
532 // Parse ONNX model file to populate TensorRT INetwork
533 int verbosity = (int) nvinfer1::ILogger::Severity::kERROR;
534 if (!parser->parseFromFile(mParams.modelFileName.c_str(), verbosity))
535 {
536 sample::gLogError << "Unable to parse ONNX model file: " << mParams.modelFileName << std::endl;
537 return sample::Logger::TestResult::kFAILED;
538 }
539
540 if (mParams.writeNetworkTensors)
541 {
542 writeNetworkTensorNames(network);
543 return sample::Logger::TestResult::kWAIVED;
544 }
545
546 // Configure buider
547 config->setFlag(BuilderFlag::kGPU_FALLBACK);
548
549 // Enable INT8 model. Required to set custom per-tensor dynamic range or INT8 Calibration
550 config->setFlag(BuilderFlag::kINT8);
551 // Mark calibrator as null. As user provides dynamic range for each tensor, no calibrator is required

Callers 1

mainFunction · 0.45

Calls 15

createInferBuilderFunction · 0.85
makeCudaStreamFunction · 0.85
createInferRuntimeFunction · 0.85
platformHasFastInt8Method · 0.80
createNetworkV2Method · 0.80
createBuilderConfigMethod · 0.80
c_strMethod · 0.80
setFlagMethod · 0.80
setInt8CalibratorMethod · 0.80
setProfileStreamMethod · 0.80
deserializeCudaEngineMethod · 0.80

Tested by

no test coverage detected