Skip to main content

IOptimizationProfile

Struct IOptimizationProfile 

Source
pub struct IOptimizationProfile { /* private fields */ }
Expand description

IOptimizationProfile Optimization profile for dynamic input dimensions and shape tensors.

When building an ICudaEngine from an INetworkDefinition that has dynamically resizable inputs (at least one input tensor has one or more of its dimensions specified as -1) or shape input tensors, users need to specify at least one optimization profile. Optimization profiles are numbered 0, 1, … The first optimization profile that has been defined (with index 0) will be used by the ICudaEngine whenever no optimization profile has been selected explicitly. If none of the inputs are dynamic, the default optimization profile will be generated automatically unless it is explicitly provided by the user (this is possible but not required in this case). If more than a single optimization profile is defined, users may set a target how much additional weight space should be maximally allocated to each additional profile (as a fraction of the maximum, unconstrained memory).

Users set optimum input tensor dimensions, as well as minimum and maximum input tensor dimensions. The builder selects the kernels that result in the lowest runtime for the optimum input tensor dimensions, and are valid for all input tensor sizes in the valid range between minimum and maximum dimensions. A runtime error will be raised if the input tensor dimensions fall outside the valid range for this profile. Likewise, users provide minimum, optimum, and maximum values for all shape tensor input values.

See IBuilderConfig::addOptimizationProfile()

Implementations§

Source§

impl IOptimizationProfile

Source

pub unsafe fn setDimensions( self: Pin<&mut IOptimizationProfile>, inputName: *const c_char, select: OptProfileSelector, dims: &Dims64, ) -> bool

Set the minimum / optimum / maximum dimensions for a dynamic input tensor.

This function must be called three times (for the minimum, optimum, and maximum) for any network input tensor that has dynamic dimensions. If minDims, optDims, and maxDims are the minimum, optimum, and maximum dimensions, and networkDims are the dimensions for this input tensor that are provided to the INetworkDefinition object, then the following conditions must all hold:

(1) minDims.nbDims == optDims.nbDims == maxDims.nbDims == networkDims.nbDims (2) 0 <= minDims.d[i] <= optDims.d[i] <= maxDims.d[i] for i = 0, …, networkDims.nbDims-1 (3) if networkDims.d[i] != -1, then minDims.d[i] == optDims.d[i] == maxDims.d[i] == networkDims.d[i]

This function may (but need not be) called for an input tensor that does not have dynamic dimensions. In this case, the third argument must always equal networkDims.

  • inputName The input tensor name
  • select Whether to set the minimum, optimum, or maximum dimensions
  • dims The minimum, optimum, or maximum dimensions for this input tensor

false if an inconsistency was detected (e.g. the rank does not match another dimension that was previously set for the same input), true if no inconsistency was detected. Note that inputs can be validated only partially; a full validation is performed at engine build time.

If run on DLA, minimum, optimum, and maximum dimensions must to be the same.

The string inputName must be null-terminated, and be at most 4096 bytes including the terminator.

Source

pub unsafe fn getDimensions( self: &IOptimizationProfile, inputName: *const c_char, select: OptProfileSelector, ) -> Dims64

Get the minimum / optimum / maximum dimensions for a dynamic input tensor.

If the dimensions have not been previously set via setDimensions(), return an invalid Dims with nbDims == -1.

The string inputName must be null-terminated, and be at most 4096 bytes including the terminator.

Source

pub unsafe fn getNbShapeValues( self: &IOptimizationProfile, inputName: *const c_char, ) -> i32

Get the number of values for an input shape tensor.

This will return the number of shape values if setShapeValuesV2() has been called before for this input tensor. Otherwise, return -1.

The string inputName must be null-terminated, and be at most 4096 bytes including the terminator.

Source

pub fn setExtraMemoryTarget( self: Pin<&mut IOptimizationProfile>, target: f32, ) -> bool

Set a target for extra GPU memory that may be used by this profile.

  • target Additional memory that the builder should aim to maximally allocate for this profile, as a fraction of the memory it would use if the user did not impose any constraints on memory. This unconstrained case is the default; it corresponds to target == 1.0. If target == 0.0, the builder aims to create the new optimization profile without allocating any additional weight memory. Valid inputs lie between 0.0 and 1.0. This parameter is only a hint, and TensorRT does not guarantee that the target will be reached. This parameter is ignored for the first (default) optimization profile that is defined.

true if the input is in the valid range (between 0 and 1 inclusive), else false.

Source

pub fn getExtraMemoryTarget(self: &IOptimizationProfile) -> f32

Get the extra memory target that has been defined for this profile.

This defaults to 1.0F.

the valid value set by setExtraMemoryTarget or 1.0F.

Source

pub fn isValid(self: &IOptimizationProfile) -> bool

Check whether the optimization profile can be passed to an IBuilderConfig object.

This function performs partial validation, by e.g. checking that whenever one of the minimum, optimum, or maximum dimensions of a tensor have been set, the others have also been set and have the same rank, as well as checking that the optimum dimensions are always as least as large as the minimum dimensions, and that the maximum dimensions are at least as large as the optimum dimensions. Some validation steps require knowledge of the network definition and are deferred to engine build time.

true if the optimization profile is valid and may be passed to an IBuilderConfig, else false.

Source

pub unsafe fn setShapeValuesV2( self: Pin<&mut IOptimizationProfile>, inputName: *const c_char, select: OptProfileSelector, values: *const i64, nbValues: i32, ) -> bool

Set the minimum / optimum / maximum values for an input shape tensor.

This function must be called three times for every input tensor t that is a shape tensor (t.isShape() == true). This implies that the dimensions of t are fixed at network definition time and the volume does not exceed 64. This function must not be called for any input tensor that is not a shape tensor.

Each time this function is called for the same input tensor, the same nbValues must be supplied (either 1 if the tensor rank is 0, or dims.d[0] if the rank is 1). Furthermore, if minVals, optVals, maxVals are the minimum, optimum, and maximum values, it must be true that minVals[i] <= optVals[i] <= maxVals[i] for i = 0, …, nbValues - 1. Execution of the network must be valid for the optVals.

Shape tensors are tensors that contribute to shape calculations in some way. While input shape tensors can be type kINT32 or kINT64, the values used to set the minimum, optimum, and maximum values must fit in int64_t.

Examples:

  • A shape tensor used as the second input to IShuffleLayer can contain a -1 wildcard. The corresponding minVal[i] should be -1.

  • A shape tensor used as the stride input to ISliceLayer can contain any valid strides. The values could be positive, negative, or zero.

  • A shape tensor subtracted from zero to compute the size input of an ISliceLayer can contain any non-positive values that yield a valid slice operation.

Tightening the minVals and maxVals bounds to cover only values that are necessary may help optimization.

  • inputName The input tensor name
  • select Whether to set the minimum, optimum, or maximum input values.
  • values An array of length nbValues containing the minimum, optimum, or maximum shape tensor elements. For multidimensional tensors, the array is in row-major order.
  • nbValues The length of the value array, which must equal the number of shape tensor elements (>= 1)

false if an inconsistency was detected (e.g. nbValues does not match a previous call for the same tensor), else true. As for setDimensions(), a full validation can only be performed at engine build time.

If run on DLA, minimum, optimum, and maximum shape values must to be the same.

The string inputName must be null-terminated, and be at most 4096 bytes including the terminator.

Source

pub unsafe fn getShapeValuesV2( self: &IOptimizationProfile, inputName: *const c_char, select: OptProfileSelector, ) -> *const i64

Get the minimum / optimum / maximum values for an input shape tensor.

If the shape values have not been set previously with setShapeValuesV2(), this returns nullptr.

The string inputName must be null-terminated, and be at most 4096 bytes including the terminator.

Trait Implementations§

Source§

impl ExternType for IOptimizationProfile

Source§

type Id = (n, v, i, n, f, e, r, _1, (), I, O, p, t, i, m, i, z, a, t, i, o, n, P, r, o, f, i, l, e)

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

type Kind = Opaque

Source§

impl MakeCppStorage for IOptimizationProfile

Source§

unsafe fn allocate_uninitialized_cpp_storage() -> *mut IOptimizationProfile

Allocates heap space for this type in C++ and return a pointer to that space, but do not initialize that space (i.e. do not yet call a constructor). Read more
Source§

unsafe fn free_uninitialized_cpp_storage(arg0: *mut IOptimizationProfile)

Frees a C++ allocation which has not yet had a constructor called. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.