triton.language.cast

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

将张量转换为指定的 dtype

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

  • fp_downcast_rounding (str, optional) – 浮点数值向下转换时的舍入模式。该参数仅在self为浮点张量且dtype为较小位宽的浮点类型时使用。支持的值为"rtne"(四舍五入到最近值,平局时取偶数)和"rtz"(向零舍入)。

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

此函数也可以作为成员函数在tensor上调用, 即使用x.cast(...)而非 cast(x, ...)