triton.language.cast

triton.language.cast(input, dtype: dtype, fp_downcast_rounding: str | None = None, bitcast: bool = False)

将张量转换为给定的 dtype

参数:
  • dtype (tl.dtype) – 目标数据类型。

  • fp_downcast_rounding (str, optional) – 浮点值向下转换的舍入模式。此参数仅在 self 为浮点张量且 dtype 是具有较小位宽的浮点类型时使用。支持的值为 "rtne"(就近舍入,遇半数向偶数舍入)和 "rtz"(向零舍入)。

  • bitcast (bool, optional) – 如果为 true,张量将按位转换为给定的 dtype,而不是进行数值转换。

此函数也可以作为 tensor 的成员函数调用,形式为 x.cast(...),而不是 cast(x, ...)