Context for executing inference using an engine, with functionally unsafe features.
More...
|
bool | execute (int32_t batchSize, void *const *bindings) noexcept |
| Synchronously execute inference on a batch. More...
|
|
bool | enqueue (int32_t batchSize, void *const *bindings, cudaStream_t stream, cudaEvent_t *inputConsumed) noexcept |
| Asynchronously execute inference on a batch. More...
|
|
void | setDebugSync (bool sync) noexcept |
| Set the debug sync flag. More...
|
|
bool | getDebugSync () const noexcept |
| Get the debug sync flag. More...
|
|
void | setProfiler (IProfiler *profiler) noexcept |
| Set the profiler. More...
|
|
IProfiler * | getProfiler () const noexcept |
| Get the profiler. More...
|
|
const ICudaEngine & | getEngine () const noexcept |
| Get the associated engine. More...
|
|
TRT_DEPRECATED void | destroy () noexcept |
| Destroy this object. More...
|
|
void | setName (const char *name) noexcept |
| Set the name of the execution context. More...
|
|
const char * | getName () const noexcept |
| Return the name of the execution context. More...
|
|
TRT_DEPRECATED void | setDeviceMemory (void *memory) noexcept |
| Set the device memory for use by this execution context. More...
|
|
Dims | getStrides (int32_t bindingIndex) const noexcept |
| Return the strides of the buffer for the given binding. More...
|
|
TRT_DEPRECATED bool | setOptimizationProfile (int32_t profileIndex) noexcept |
| Select an optimization profile for the current context. More...
|
|
int32_t | getOptimizationProfile () const noexcept |
| Get the index of the currently selected optimization profile. More...
|
|
bool | setBindingDimensions (int32_t bindingIndex, Dims dimensions) noexcept |
| Set the dynamic dimensions of a binding. More...
|
|
Dims | getBindingDimensions (int32_t bindingIndex) const noexcept |
| Get the dynamic dimensions of a binding. More...
|
|
bool | setInputShapeBinding (int32_t bindingIndex, int32_t const *data) noexcept |
| Set values of input tensor required by shape calculations. More...
|
|
bool | getShapeBinding (int32_t bindingIndex, int32_t *data) const noexcept |
| Get values of an input tensor required for shape calculations or an output tensor produced by shape calculations. More...
|
|
bool | allInputDimensionsSpecified () const noexcept |
| Whether all dynamic dimensions of input tensors have been specified. More...
|
|
bool | allInputShapesSpecified () const noexcept |
| Whether all input shape bindings have been specified. More...
|
|
void | setErrorRecorder (IErrorRecorder *recorder) noexcept |
| Set the ErrorRecorder for this interface. More...
|
|
IErrorRecorder * | getErrorRecorder () const noexcept |
| Get the ErrorRecorder assigned to this interface. More...
|
|
bool | executeV2 (void *const *bindings) noexcept |
| Synchronously execute inference a network. More...
|
|
bool | enqueueV2 (void *const *bindings, cudaStream_t stream, cudaEvent_t *inputConsumed) noexcept |
| Asynchronously execute inference. More...
|
|
bool | setOptimizationProfileAsync (int32_t profileIndex, cudaStream_t stream) noexcept |
| Select an optimization profile for the current context with async semantics. More...
|
|
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.
Dims nvinfer1::IExecutionContext::getBindingDimensions |
( |
int32_t |
bindingIndex | ) |
const |
|
inlinenoexcept |
Dims nvinfer1::IExecutionContext::getStrides |
( |
int32_t |
bindingIndex | ) |
const |
|
inlinenoexcept |
Return the strides of the buffer for the given binding.
The strides are in units of elements, not components or bytes. For example, for TensorFormat::kHWC8, a stride of one spans 8 scalars.
Note that strides can be different for different execution contexts with dynamic shapes.
If the bindingIndex is invalid or there are dynamic dimensions that have not been set yet, returns Dims with Dims::nbDims = -1.
- Parameters
-
bindingIndex | The binding index. |
- See also
- getBindingComponentsPerElement
bool nvinfer1::IExecutionContext::setBindingDimensions |
( |
int32_t |
bindingIndex, |
|
|
Dims |
dimensions |
|
) |
| |
|
inlinenoexcept |
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().
- Warning
- This function will trigger layer resource updates on the next call of enqueue[V2]()/execute[V2](), possibly resulting in performance bottlenecks, if the dimensions are different than the previous set dimensions.
- Returns
- false if an error occurs (e.g. index out of range), else true
- See also
- ICudaEngine::getBindingIndex
void nvinfer1::IExecutionContext::setErrorRecorder |
( |
IErrorRecorder * |
recorder | ) |
|
|
inlinenoexcept |
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.
If an error recorder is not set, messages will be sent to the global log stream.
- Parameters
-
recorder | The error recorder to register with this interface. |
- See also
- getErrorRecorder()
TRT_DEPRECATED bool nvinfer1::IExecutionContext::setOptimizationProfile |
( |
int32_t |
profileIndex | ) |
|
|
inlinenoexcept |
Select an optimization profile for the current context.
- Parameters
-
profileIndex | Index 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().
When an optimization profile is switched via this API, TensorRT may enqueue GPU memory copy operations required to set up the new profile during the subsequent enqueue() operations. To avoid these calls during enqueue(), use setOptimizationProfileAsync() instead.
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().
- Warning
- This function will trigger layer resource updates on the next call of enqueue[V2]()/execute[V2](), possibly resulting in performance bottlenecks.
- Returns
- true if the call succeeded, else false (e.g. input out of range)
- Deprecated:
- This API is superseded by setOptimizationProfileAsync and will be removed in TensorRT 9.0.
- See also
- ICudaEngine::getNbOptimizationProfiles() IExecutionContext::setOptimizationProfileAsync()
bool nvinfer1::IExecutionContext::setOptimizationProfileAsync |
( |
int32_t |
profileIndex, |
|
|
cudaStream_t |
stream |
|
) |
| |
|
inlinenoexcept |
Select an optimization profile for the current context with async semantics.
- Parameters
-
profileIndex | Index of the profile. The value must lie between 0 and getEngine().getNbOptimizationProfiles() - 1 |
stream | A cuda stream on which the cudaMemcpyAsyncs may be enqueued |
When an optimization profile is switched via this API, TensorRT may require that data is copied via cudaMemcpyAsync. It is the application’s responsibility to guarantee that synchronization between the profile sync stream and the enqueue stream occurs.
The selected profile will be used in subsequent calls to execute() or enqueue(). If the associated CUDA engine has inputs with dynamic shapes, the optimization profile must be set with a unique profileIndex before calling execute or enqueue. 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.
setOptimizationProfileAsync() 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().
- Warning
- This function will trigger layer resource updates on the next call of enqueue[V2]()/execute[V2](), possibly resulting in performance bottlenecks.
-
Not synchronizing the stream used at enqueue with the stream used to set optimization profile asynchronously using this API will result in undefined behavior.
- Returns
- true if the call succeeded, else false (e.g. input out of range)
- See also
- ICudaEngine::getNbOptimizationProfiles()
-
IExecutionContext::setOptimizationProfile()