TensorDesc¶
- class tensorrt.plugin.TensorDesc(shape_expr: ShapeExprs | None = None, dtype: DataType | None = None, format: TensorFormat | None = None, scale: float | None = None)¶
Descriptor for a tensor A TensorDesc never contains nor refers to any tensor data.
- Parameters:
shape_expr (ShapeExprs) – The data with which to initialize the tensor.
dtype (trt.DataType) – The data type of the tensor.
format (trt.TensorFormat) – Format (layout) of the tensor.
scale (float) – Scale for INT8 data type.
Creates a TensorDesc with constant shape expressions¶1tensor = trt.TensorDesc((10, 2, 32, 32), dtype=trt.float32)
Creates a TensorDesc from shape expression of another TensorDesc¶1tensor = trt.from_shape_expr(other.shape_expr, dtype=trt.float32)
- aliased() TensorDesc ¶
- Returns:
Returns a TensorDesc which has identical properties and is aliased to this tensor (would result in a Tensor during enqueue sharing the same data buffer). Returned TensorDesc is immutable.
Communicate that output tensor has identical properties to the input tensor¶1@tensorrt.plugin.register("my::plugin") 2def _(inp: tensorrt.plugin.TensorDesc) -> tensorrt.plugin.TensorDesc: 3 return inp.aliased()
- property dtype: DataType¶
Data type of the tensor.
- property format: TensorFormat¶
The format of the tensor.
Warning
Only accessible when TensorDesc.has_shape is true.
- get_aliased() TensorDesc ¶
- Returns:
Returns a TensorDesc for the tensor which this tensor is aliased to. Returns None is this tensor is not aliased to any other tensor.
- property has_shape: bool¶
True if this tensor has concrete shape information, False otherwise.
- property has_shape_expr: bool¶
True if this tensor has symbolic shape expressions, False otherwise.
- property is_aliased: bool¶
True if this tensor is aliased to another tensor, False otherwise.
- property is_dynamic: bool¶
True if this tensor has at least one dynamic dimension, False otherwise.
- like() TensorDesc ¶
- Returns:
Returns a TensorDesc which has identical properties to this tensor, and is mutable.
Communicate that output tensor has identical properties to the input tensor¶1@tensorrt.plugin.register("my::plugin") 2def _(inp: tensorrt.plugin.TensorDesc) -> tensorrt.plugin.TensorDesc: 3 return inp.like()
- property ndim: int¶
Number of dimensions
- numel() int ¶
- Returns:
Returns an int with the number of elements of the tensor.
Warning
Should only be called when TensorDesc.has_shape is true. If a symbolic expression for the number of elements is required, query TensorDesc.shape_expr.numel().
- property scale: float¶
Scale for INT8 data type.
Warning
Only accessible when TensorDesc.has_shape is true.
- property shape: Shape¶
The (concrete) shape of the tensor.
Warning
Only accessible when TensorDesc.has_shape is true.
- property shape_expr: ShapeExprs¶
Symbolic expressions for the tensor shape.
- class tensorrt.plugin.SizeTensorDesc(opt: ShapeExpr, upper_bound: ShapeExpr)¶
Extends
TensorDesc
Descriptor for a size tensor: a scalar of either INT32 or INT64 data type used to express the extent of a data-dependent dimension.
- Parameters:
Note
It is recommended to construct a size tensor using
size_tensor()
instead of using this constructor directly- expr() SizeTensorShapeExpr ¶
Symbolic expression for this size tensor
- property index: int¶
Output index at which this size tensor resides