TensorDesc

class tensorrt.plugin.TensorDesc(shape_expr: ShapeExprs | None = None, dtype`: DataType | None = None, format`: TensorFormat | None = None, scale`: float | None = None)

张量的描述符。TensorDesc 永远不包含或引用任何张量数据。

参数:
  • shape_expr (ShapeExprs) – 用于初始化张量的数据。

  • dtype (trt.DataType) – 张量的数据类型。

  • format (trt.TensorFormat) – 张量的格式(布局)。

  • scale (float) – INT8 数据类型的缩放比例。

创建具有恒定形状表达式的 TensorDesc
1tensor = trt.TensorDesc((10, 2, 32, 32), dtype=trt.float32)
从另一个 TensorDesc 的形状表达式创建 TensorDesc
1tensor = trt.from_shape_expr(other.shape_expr, dtype=trt.float32)
aliased() TensorDesc
返回:

返回一个 TensorDesc,它具有相同的属性,并且是此张量的别名(在入队期间会产生一个 Tensor,共享相同的数据缓冲区)。返回的 TensorDesc 是不可变的。

表明输出张量与输入张量具有相同的属性
1@tensorrt.plugin.register("my::plugin")
2def _(inp: tensorrt.plugin.TensorDesc) -> tensorrt.plugin.TensorDesc:
3    return inp.aliased()
property dtype: DataType

张量的数据类型。

property format`: TensorFormat

张量的格式。

警告

仅当 TensorDesc.has_shape 为 true 时可访问。

get_aliased() TensorDesc
返回:

返回此张量所别名的张量的 TensorDesc。如果此张量未别名到任何其他张量,则返回 None。

property has_shape`: bool

如果此张量具有具体的形状信息,则为 True,否则为 False。

property has_shape_expr`: bool

如果此张量具有符号形状表达式,则为 True,否则为 False。

property is_aliased`: bool

如果此张量别名到另一个张量,则为 True,否则为 False。

property is_dynamic`: bool

如果此张量至少有一个动态维度,则为 True,否则为 False

like() TensorDesc
返回:

返回一个 TensorDesc,它具有与此张量相同的属性,并且是可变的。

表明输出张量与输入张量具有相同的属性
1@tensorrt.plugin.register("my::plugin")
2def _(inp: tensorrt.plugin.TensorDesc) -> tensorrt.plugin.TensorDesc:
3    return inp.like()
property ndim`: int

维度数量

numel() int
返回:

返回一个整数,表示张量的元素数量。

警告

仅当 TensorDesc.has_shape 为 true 时才应调用。如果需要元素数量的符号表达式,请查询 TensorDesc.shape_expr.numel()。

property scale`: float

INT8 数据类型的缩放比例。

警告

仅当 TensorDesc.has_shape 为 true 时可访问。

property shape`: Shape

张量的(具体)形状。

警告

仅当 TensorDesc.has_shape 为 true 时可访问。

property shape_expr`: ShapeExprs

张量形状的符号表达式。

class tensorrt.plugin.SizeTensorDesc(opt`: ShapeExpr, upper_bound`: ShapeExpr)

继承自 TensorDesc

大小张量的描述符:一个标量,数据类型为 INT32 或 INT64,用于表示数据相关维度的范围。

参数:
  • opt (ShapeExpr) – 此大小张量的范围的符号表达式,用于引擎构建的自动调优过程

  • upper_bound (ShapeExpr) – 此大小张量的上限的符号表达式

注意

建议使用 size_tensor() 构建大小张量,而不是直接使用此构造函数

expr() SizeTensorShapeExpr

此大小张量的符号表达式

property index`: int

此大小张量所在的输出索引

property opt`: ShapeExpr

此大小张量的范围的符号表达式,用于引擎构建的自动调优过程

property upper_bound`: ShapeExpr

此大小张量的上限的符号表达式