TensorRT  7.0.0.11
nvinfer1::IExecutionContext Class Referenceabstract

Context for executing inference using an engine, with functionally unsafe features. More...

#include <NvInferRuntime.h>

Public Member Functions

virtual bool execute (int batchSize, void **bindings) noexcept=0
 Synchronously execute inference on a batch. More...
 
virtual bool enqueue (int batchSize, void **bindings, cudaStream_t stream, cudaEvent_t *inputConsumed) noexcept=0
 Asynchronously execute inference on a batch. More...
 
virtual void setDebugSync (bool sync) noexcept=0
 Set the debug sync flag. More...
 
virtual bool getDebugSync () const noexcept=0
 Get the debug sync flag. More...
 
virtual void setProfiler (IProfiler *) noexcept=0
 Set the profiler. More...
 
virtual IProfilergetProfiler () const noexcept=0
 Get the profiler. More...
 
virtual const ICudaEnginegetEngine () const noexcept=0
 Get the associated engine. More...
 
virtual void destroy () noexcept=0
 Destroy this object.
 
virtual void setName (const char *name) noexcept=0
 Set the name of the execution context. More...
 
virtual const char * getName () const noexcept=0
 Return the name of the execution context. More...
 
virtual void setDeviceMemory (void *memory) noexcept=0
 set the device memory for use by this execution context. More...
 
virtual Dims getStrides (int bindingIndex) const noexcept=0
 Return the strides of the buffer for the given binding. More...
 
virtual bool setOptimizationProfile (int profileIndex) noexcept=0
 Select an optimization profile for the current context. More...
 
virtual int getOptimizationProfile () const noexcept=0
 Get the index of the currently selected optimization profile. More...
 
virtual bool setBindingDimensions (int bindingIndex, Dims dimensions) noexcept=0
 Set the dynamic dimensions of a binding. More...
 
virtual Dims getBindingDimensions (int bindingIndex) const noexcept=0
 Get the dynamic dimensions of a binding. More...
 
virtual bool setInputShapeBinding (int bindingIndex, const int32_t *data) noexcept=0
 Set values of input tensor required by shape calculations. More...
 
virtual bool getShapeBinding (int bindingIndex, int32_t *data) const noexcept=0
 Get values of an input tensor required for shape calculations or an output tensor produced by shape calculations. More...
 
virtual bool allInputDimensionsSpecified () const noexcept=0
 Whether all dynamic dimensions of input tensors have been specified. More...
 
virtual bool allInputShapesSpecified () const noexcept=0
 Whether all input shape bindings have been specified. More...
 
virtual void setErrorRecorder (IErrorRecorder *recorder) noexcept=0
 Set the ErrorRecorder for this interface. More...
 
virtual IErrorRecordergetErrorRecorder () const noexcept=0
 get the ErrorRecorder assigned to this interface. More...
 
virtual bool executeV2 (void **bindings) noexcept=0
 Synchronously execute inference a network. More...
 
virtual bool enqueueV2 (void **bindings, cudaStream_t stream, cudaEvent_t *inputConsumed) noexcept=0
 Asynchronously execute inference. More...
 

Detailed Description

Context for executing inference using an engine, with functionally unsafe features.

Multiple execution contexts may exist for one ICudaEngine instance, allowing the same engine to be used for the execution of multiple batches simultaneously. If the engine supports dynamic shapes, each execution context in concurrent use must use a separate optimization profile.

Warning
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.

Member Function Documentation

virtual bool nvinfer1::IExecutionContext::allInputDimensionsSpecified ( ) const
pure virtualnoexcept

Whether all dynamic dimensions of input tensors have been specified.

Returns
True if all dynamic dimensions of input tensors have been specified by calling setBindingDimensions().

Trivially true if network has no dynamically shaped input tensors.

See also
setBindingDimensions(bindingIndex,dimensions)
virtual bool nvinfer1::IExecutionContext::allInputShapesSpecified ( ) const
pure virtualnoexcept

Whether all input shape bindings have been specified.

Returns
True if all input shape bindings have been specified by setInputShapeBinding().

Trivially true if network has no input shape bindings.

See also
isShapeBinding(bindingIndex)
virtual bool nvinfer1::IExecutionContext::enqueue ( int  batchSize,
void **  bindings,
cudaStream_t  stream,
cudaEvent_t inputConsumed 
)
pure virtualnoexcept

Asynchronously execute inference on a batch.

This method requires an array of input and output buffers. The mapping from tensor names to indices can be queried using ICudaEngine::getBindingIndex()

Parameters
batchSizeThe batch size. This is at most the value supplied when the engine was built.
bindingsAn array of pointers to input and output buffers for the network.
streamA cuda stream on which the inference kernels will be enqueued
inputConsumedAn optional event which will be signaled when the input buffers can be refilled with new data
Returns
True if the kernels were enqueued successfully.
See also
ICudaEngine::getBindingIndex() ICudaEngine::getMaxBatchSize()
virtual bool nvinfer1::IExecutionContext::enqueueV2 ( void **  bindings,
cudaStream_t  stream,
cudaEvent_t inputConsumed 
)
pure virtualnoexcept

Asynchronously execute inference.

This method requires an array of input and output buffers. The mapping from tensor names to indices can be queried using ICudaEngine::getBindingIndex(). This method only works for execution contexts built with full dimension networks.

Parameters
bindingsAn array of pointers to input and output buffers for the network.
streamA cuda stream on which the inference kernels will be enqueued
inputConsumedAn optional event which will be signaled when the input buffers can be refilled with new data
Returns
True if the kernels were enqueued successfully.
See also
ICudaEngine::getBindingIndex() ICudaEngine::getMaxBatchSize()
virtual bool nvinfer1::IExecutionContext::execute ( int  batchSize,
void **  bindings 
)
pure virtualnoexcept

Synchronously execute inference on a batch.

This method requires an array of input and output buffers. The mapping from tensor names to indices can be queried using ICudaEngine::getBindingIndex()

Parameters
batchSizeThe batch size. This is at most the value supplied when the engine was built.
bindingsAn array of pointers to input and output buffers for the network.
Returns
True if execution succeeded.
See also
ICudaEngine::getBindingIndex() ICudaEngine::getMaxBatchSize()
virtual bool nvinfer1::IExecutionContext::executeV2 ( void **  bindings)
pure virtualnoexcept

Synchronously execute inference a network.

This method requires an array of input and output buffers. The mapping from tensor names to indices can be queried using ICudaEngine::getBindingIndex(). This method only works for execution contexts built with full dimension networks.

Parameters
bindingsAn array of pointers to input and output buffers for the network.
Returns
True if execution succeeded.
See also
ICudaEngine::getBindingIndex() ICudaEngine::getMaxBatchSize()
virtual Dims nvinfer1::IExecutionContext::getBindingDimensions ( int  bindingIndex) const
pure virtualnoexcept

Get the dynamic dimensions of a binding.

If the engine was built with an implicit batch dimension, same as ICudaEngine::getBindingDimensions.

If setBindingDimensions() has been called on this binding (or if there are no dynamic dimensions), all dimensions will be positive. Otherwise, it is necessary to call setBindingDimensions() before enqueue() or execute() may be called.

If the bindingIndex is out of range, an invalid Dims with nbDims == -1 is returned. The same invalid Dims will be returned if the engine was not built with an implicit batch dimension and if the execution context is not currently associated with a valid optimization profile (i.e. if getOptimizationProfile() returns -1).

If ICudaEngine::bindingIsInput(bindingIndex) is false, then both allInputDimensionsSpecified() and allInputShapesSpecified() must be true before calling this method.

Returns
Currently selected binding dimensions
virtual bool nvinfer1::IExecutionContext::getDebugSync ( ) const
pure virtualnoexcept

Get the debug sync flag.

See also
setDebugSync()
virtual const ICudaEngine& nvinfer1::IExecutionContext::getEngine ( ) const
pure virtualnoexcept

Get the associated engine.

See also
ICudaEngine
virtual IErrorRecorder* nvinfer1::IExecutionContext::getErrorRecorder ( ) const
pure virtualnoexcept

get the ErrorRecorder assigned to this interface.

Retrieves the assigned error recorder object for the given class. A default error recorder does not exist, so a nullptr will be returned if setErrorRecorder has not been called.

Returns
A pointer to the IErrorRecorder object that has been registered.
See also
setErrorRecorder
virtual const char* nvinfer1::IExecutionContext::getName ( ) const
pure virtualnoexcept

Return the name of the execution context.

See also
setName()
virtual int nvinfer1::IExecutionContext::getOptimizationProfile ( ) const
pure virtualnoexcept

Get the index of the currently selected optimization profile.

If the profile index has not been set yet (implicitly to 0 for the first execution context to be created, or explicitly for all subsequent contexts), an invalid value of -1 will be returned and all calls to enqueue() or execute() will fail until a valid profile index has been set.

virtual IProfiler* nvinfer1::IExecutionContext::getProfiler ( ) const
pure virtualnoexcept

Get the profiler.

See also
IProfiler setProfiler()
virtual bool nvinfer1::IExecutionContext::getShapeBinding ( int  bindingIndex,
int32_t *  data 
) const
pure virtualnoexcept

Get values of an input tensor required for shape calculations or an output tensor produced by shape calculations.

Parameters
bindingIndexindex of an input or output tensor for which ICudaEngine::isShapeBinding(bindingIndex) is true.
datapointer to where values will be written. The number of values written is the product of the dimensions returned by getBindingDimensions(bindingIndex).

If ICudaEngine::bindingIsInput(bindingIndex) is false, then both allInputDimensionsSpecified() and allInputShapesSpecified() must be true before calling this method. The method will also fail if no valid optimization profile has been set for the current execution context, i.e. if getOptimizationProfile() returns -1.

See also
isShapeBinding(bindingIndex)
virtual Dims nvinfer1::IExecutionContext::getStrides ( int  bindingIndex) const
pure virtualnoexcept

Return the strides of the buffer for the given binding.

Note that strides can be different for different execution contexts with dynamic shapes.

Parameters
bindingIndexThe binding index.
virtual bool nvinfer1::IExecutionContext::setBindingDimensions ( int  bindingIndex,
Dims  dimensions 
)
pure virtualnoexcept

Set the dynamic dimensions of a binding.

Requires the engine to be built without an implicit batch dimension. The binding must be an input tensor, and all dimensions must be compatible with the network definition (i.e. only the wildcard dimension -1 can be replaced with a new dimension > 0). Furthermore, the dimensions must be in the valid range for the currently selected optimization profile, and the corresponding engine must not be safety-certified. This method will fail unless a valid optimization profile is defined for the current execution context (getOptimizationProfile() must not be -1).

For all dynamic non-output bindings (which have at least one wildcard dimension of -1), this method needs to be called before either enqueue() or execute() may be called. This can be checked using the method allInputDimensionsSpecified().

Returns
false if an error occurs (e.g. index out of range), else true
virtual void nvinfer1::IExecutionContext::setDebugSync ( bool  sync)
pure virtualnoexcept

Set the debug sync flag.

If this flag is set to true, the engine will log the successful execution for each kernel during execute(). It has no effect when using enqueue().

See also
getDebugSync()
virtual void nvinfer1::IExecutionContext::setDeviceMemory ( void *  memory)
pure virtualnoexcept

set the device memory for use by this execution context.

The memory must be aligned with cuda memory alignment property (using cudaGetDeviceProperties()), and its size must be at least that returned by getDeviceMemorySize(). If using enqueue() to run the network, The memory is in use from the invocation of enqueue() until network execution is complete. If using execute(), it is in use until execute() returns. Releasing or otherwise using the memory for other purposes during this time will result in undefined behavior.

See also
ICudaEngine::getDeviceMemorySize() ICudaEngine::createExecutionContextWithoutDeviceMemory()
virtual void nvinfer1::IExecutionContext::setErrorRecorder ( IErrorRecorder recorder)
pure virtualnoexcept

Set the ErrorRecorder for this interface.

Assigns the ErrorRecorder to this interface. The ErrorRecorder will track all errors during execution. This function will call incRefCount of the registered ErrorRecorder at least once. Setting recorder to nullptr unregisters the recorder with the interface, resulting in a call to decRefCount if a recorder has been registered.

Parameters
recorderThe error recorder to register with this interface.
See also
getErrorRecorder
virtual bool nvinfer1::IExecutionContext::setInputShapeBinding ( int  bindingIndex,
const int32_t *  data 
)
pure virtualnoexcept

Set values of input tensor required by shape calculations.

Parameters
bindingIndexindex of an input tensor for which ICudaEngine::isShapeBinding(bindingIndex) and ICudaEngine::bindingIsInput(bindingIndex) are both true.
datapointer to values of the input tensor. The number of values should be the product of the dimensions returned by getBindingDimensions(bindingIndex).

If ICudaEngine::isShapeBinding(bindingIndex) and ICudaEngine::bindingIsInput(bindingIndex) are both true, this method must be called before enqueue() or execute() may be called. This method will fail unless a valid optimization profile is defined for the current execution context (getOptimizationProfile() must not be -1).

virtual void nvinfer1::IExecutionContext::setName ( const char *  name)
pure virtualnoexcept

Set the name of the execution context.

This method copies the name string.

See also
getName()
virtual bool nvinfer1::IExecutionContext::setOptimizationProfile ( int  profileIndex)
pure virtualnoexcept

Select an optimization profile for the current context.

Parameters
profileIndexIndex of the profile. It must lie between 0 and getEngine().getNbOptimizationProfiles() - 1

The selected profile will be used in subsequent calls to execute() or enqueue().

If the associated CUDA engine has dynamic inputs, this method must be called at least once with a unique profileIndex before calling execute or enqueue (i.e. the profile index may not be in use by another execution context that has not been destroyed yet). For the first execution context that is created for an engine, setOptimizationProfile(0) is called implicitly.

If the associated CUDA engine does not have inputs with dynamic shapes, this method need not be called, in which case the default profile index of 0 will be used (this is particularly the case for all safe engines).

setOptimizationProfile() must be called before calling setBindingDimensions() and setInputShapeBinding() for all dynamic input tensors or input shape tensors, which in turn must be called before either execute() or enqueue().

Returns
true if the call succeeded, else false (e.g. input out of range)
See also
ICudaEngine::getNbOptimizationProfiles()
virtual void nvinfer1::IExecutionContext::setProfiler ( IProfiler )
pure virtualnoexcept

Set the profiler.

See also
IProfiler getProfiler()

The documentation for this class was generated from the following file: