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

Function setTensorDynamicRange

samples/common/sampleEngines.cpp:459–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

457}
458
459bool setTensorDynamicRange(INetworkDefinition const& network, float inRange = 2.0F, float outRange = 4.0F)
460{
461 // Ensure that all layer inputs have a dynamic range.
462 for (int32_t l = 0; l < network.getNbLayers(); l++)
463 {
464 auto* layer = network.getLayer(l);
465 for (int32_t i = 0; i < layer->getNbInputs(); i++)
466 {
467 ITensor* input{layer->getInput(i)};
468 // Optional inputs are nullptr here and are from RNN layers.
469 if (input && !input->dynamicRangeIsSet())
470 {
471 // Concat should propagate dynamic range from outputs to inputs to avoid
472 // Re-quantization during the concatenation
473 auto dynRange = (layer->getType() == LayerType::kCONCATENATION) ? outRange : inRange;
474 if (!input->setDynamicRange(-dynRange, dynRange))
475 {
476 return false;
477 }
478 }
479 }
480 for (int32_t o = 0; o < layer->getNbOutputs(); o++)
481 {
482 ITensor* output{layer->getOutput(o)};
483 // Optional outputs are nullptr here and are from RNN layers.
484 if (output && !output->dynamicRangeIsSet())
485 {
486 // Pooling must have the same input and output dynamic range.
487 if (layer->getType() == LayerType::kPOOLING)
488 {
489 if (!output->setDynamicRange(-inRange, inRange))
490 {
491 return false;
492 }
493 }
494 else
495 {
496 if (!output->setDynamicRange(-outRange, outRange))
497 {
498 return false;
499 }
500 }
501 }
502 }
503 }
504 return true;
505}
506
507void setLayerPrecisions(INetworkDefinition& network, LayerPrecisions const& layerPrecisions)
508{

Callers 1

setupNetworkAndConfigFunction · 0.85

Calls 9

getLayerMethod · 0.80
dynamicRangeIsSetMethod · 0.80
getNbLayersMethod · 0.45
getNbInputsMethod · 0.45
getInputMethod · 0.45
getTypeMethod · 0.45
setDynamicRangeMethod · 0.45
getNbOutputsMethod · 0.45
getOutputMethod · 0.45

Tested by

no test coverage detected