昇腾社区首页
中文
注册

cast_to

功能说明

数据类型转换,把data中的数据转换为dtype类型。

您可以在“te/lang/cce/te_compute/common.py”查看接口定义。

约束说明

表1 支持的类型转换

源数据类型

目的数据类型

取整模式

float32

float16

不涉及

float32

int8

舍弃小数,直接取整数

float32

uint8

舍弃小数,直接取整数

float16

float32

不涉及

float16

int8

舍弃小数,直接取整数

float16

uint8

舍弃小数,直接取整数

float16

int32

舍弃小数,直接取整数

int8

float16

不涉及

int8

uint8

舍弃小数,直接取整数

int32

float16

不涉及

int32

int8

舍弃小数,直接取整数

int32

uint8

舍弃小数,直接取整数

函数原型

te.lang.cce.cast_to(data, dtype, f1628IntegerFlag=True)

参数说明

  • data:输入tensor,tvm.tensor类型。
  • dtype:目的数据类型,字符串类型。
  • f1628IntegerFlag:默认值为True。如果转换前数据的小数部分为0,参数f1628IntegerFlag需要设为True;如果转换前数据的小数部分不为0,参数f1628IntegerFlag需要设为False。

返回值

res_tensor:转换后的数据,tvm.tensor类型

支持的芯片型号

Atlas 200/300/500 推理产品

Atlas 训练系列产品

调用示例

shape = (1024,1024)
input_dtype = "float16"
data = tvm.placeholder(shape, name="data", dtype=input_dtype)
res = te.lang.cce.cast_to(data,"float32")