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

Function modelToBuildEnv

samples/common/sampleEngines.cpp:1228–1281  ·  view source on GitHub ↗

\brief Parse a given model, create a network and an engine.

Source from the content-addressed store, hash-verified

1226//! \brief Parse a given model, create a network and an engine.
1227//!
1228bool modelToBuildEnv(
1229 ModelOptions const& model, BuildOptions const& build, SystemOptions& sys, BuildEnvironment& env, std::ostream& err)
1230{
1231 env.builder.reset(createBuilder());
1232 SMP_RETVAL_IF_FALSE(env.builder != nullptr, "Builder creation failed", false, err);
1233 env.builder->setErrorRecorder(&gRecorder);
1234 auto networkFlags
1235 = (build.maxBatch) ? 0U : 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
1236
1237 for (auto const& pluginPath : sys.dynamicPlugins)
1238 {
1239 env.builder->getPluginRegistry().loadLibrary(pluginPath.c_str());
1240 }
1241 env.network.reset(env.builder->createNetworkV2(networkFlags));
1242
1243 std::vector<std::string> vcPluginLibrariesUsed;
1244 SMP_RETVAL_IF_FALSE(env.network != nullptr, "Network creation failed", false, err);
1245 env.parser
1246 = modelToNetwork(model, build, *env.network, err, build.versionCompatible ? &vcPluginLibrariesUsed : nullptr);
1247 SMP_RETVAL_IF_FALSE(env.parser.operator bool(), "Parsing model failed", false, err);
1248
1249 if (build.versionCompatible && !sys.ignoreParsedPluginLibs && !vcPluginLibrariesUsed.empty())
1250 {
1251 sample::gLogInfo << "The following plugin libraries were identified by the parser as required for a "
1252 "version-compatible engine:"
1253 << std::endl;
1254 for (auto const& lib : vcPluginLibrariesUsed)
1255 {
1256 sample::gLogInfo << " " << lib << std::endl;
1257 }
1258 if (!build.excludeLeanRuntime)
1259 {
1260 sample::gLogInfo << "These libraries will be added to --setPluginsToSerialize since --excludeLeanRuntime "
1261 "was not specified."
1262 << std::endl;
1263 std::copy(vcPluginLibrariesUsed.begin(), vcPluginLibrariesUsed.end(),
1264 std::back_inserter(sys.setPluginsToSerialize));
1265 }
1266 sample::gLogInfo << "These libraries will be added to --dynamicPlugins for use at inference time." << std::endl;
1267 std::copy(vcPluginLibrariesUsed.begin(), vcPluginLibrariesUsed.end(), std::back_inserter(sys.dynamicPlugins));
1268
1269 // Implicitly-added plugins from ONNX parser should be loaded into plugin registry as well.
1270 for (auto const& pluginPath : vcPluginLibrariesUsed)
1271 {
1272 env.builder->getPluginRegistry().loadLibrary(pluginPath.c_str());
1273 }
1274
1275 sample::gLogInfo << "Use --ignoreParsedPluginLibs to disable this behavior." << std::endl;
1276 }
1277
1278 SMP_RETVAL_IF_FALSE(
1279 networkToSerializedEngine(build, sys, *env.builder, env, err), "Building engine failed", false, err);
1280 return true;
1281}
1282
1283namespace
1284{

Callers 1

getEngineBuildEnvFunction · 0.85

Calls 8

modelToNetworkFunction · 0.85
c_strMethod · 0.80
createNetworkV2Method · 0.80
createBuilderFunction · 0.70
resetMethod · 0.45
setErrorRecorderMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected