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

Method build

samples/sampleIOFormats/sampleIOFormats.cpp:303–394  ·  view source on GitHub ↗

\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

Source from the content-addressed store, hash-verified

301//! \return true if the engine was created successfully and false otherwise
302//!
303bool 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)

Callers 2

processFunction · 0.45
runFP32ReferenceFunction · 0.45

Calls 15

createInferBuilderFunction · 0.85
setAllDynamicRangesFunction · 0.85
makeCudaStreamFunction · 0.85
createInferRuntimeFunction · 0.85
createNetworkV2Method · 0.80
createBuilderConfigMethod · 0.80
setAllowedFormatsMethod · 0.80
setFlagMethod · 0.80
setTypeMethod · 0.80
setProfileStreamMethod · 0.80
deserializeCudaEngineMethod · 0.80

Tested by

no test coverage detected