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

Function setupNetworkAndConfig

samples/common/sampleEngines.cpp:701–1173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

699} // namespace
700
701bool setupNetworkAndConfig(BuildOptions const& build, SystemOptions const& sys, IBuilder& builder,
702 INetworkDefinition& network, IBuilderConfig& config, std::unique_ptr<nvinfer1::IInt8Calibrator>& calibrator,
703 std::ostream& err, std::vector<std::vector<int8_t>>& sparseWeights)
704{
705 IOptimizationProfile* profile{nullptr};
706 if (build.maxBatch)
707 {
708 builder.setMaxBatchSize(build.maxBatch);
709 }
710 else
711 {
712 profile = builder.createOptimizationProfile();
713 }
714
715 bool hasDynamicShapes{false};
716
717 bool broadcastInputFormats = broadcastIOFormats(build.inputFormats, network.getNbInputs());
718
719 if (profile)
720 {
721 // Check if the provided input tensor names match the input tensors of the engine.
722 // Throw an error if the provided input tensor names cannot be found because it implies a potential typo.
723 for (auto const& shape : build.shapes)
724 {
725 bool tensorNameFound{false};
726 for (int32_t i = 0; i < network.getNbInputs(); ++i)
727 {
728 if (network.getInput(i)->getName() == shape.first)
729 {
730 tensorNameFound = true;
731 break;
732 }
733 }
734 if (!tensorNameFound)
735 {
736 sample::gLogError << "Cannot find input tensor with name \"" << shape.first << "\" in the network "
737 << "inputs! Please make sure the input tensor names are correct." << std::endl;
738 return false;
739 }
740 }
741 }
742
743 for (uint32_t i = 0, n = network.getNbInputs(); i < n; i++)
744 {
745 // Set formats and data types of inputs
746 auto* input = network.getInput(i);
747 if (!build.inputFormats.empty())
748 {
749 int inputFormatIndex = broadcastInputFormats ? 0 : i;
750 input->setType(build.inputFormats[inputFormatIndex].first);
751 input->setAllowedFormats(build.inputFormats[inputFormatIndex].second);
752 }
753 else
754 {
755 switch (input->getType())
756 {
757 case DataType::kINT32:
758 case DataType::kBOOL:

Callers 1

Calls 15

broadcastIOFormatsFunction · 0.85
setMemoryPoolLimitsFunction · 0.85
setPreviewFeaturesFunction · 0.85
sparsifyFunction · 0.85
setTensorDynamicRangeFunction · 0.85
setLayerPrecisionsFunction · 0.85
setLayerOutputTypesFunction · 0.85
setLayerDeviceTypesFunction · 0.85
setTypeMethod · 0.80
setAllowedFormatsMethod · 0.80

Tested by

no test coverage detected