scalar_conv
功能说明
标量精度转换(值转换)。
支持如下几种数据类型的转换:
- 从int32转换成float32
- 从float32转换成int32
- 从float32转换成float16
- 从float16转换成float32
函数原型
scalar_conv(round_mode, dst, src)
参数说明
参数名称 |
输入/输出 |
含义 |
---|---|---|
dst |
输出 |
目的操作数,支持的数据类型为:Scalar(float32, float16, int32) |
round_mode |
输入 |
转换模式支持情况如下:
该接口支持的精度转换及每一种转换对应的round_mode如表2所示。 |
src |
输入 |
源操作数。 支持的数据类型为:Scalar(float32, float16, int32) |
支持的型号
Atlas 训练系列产品
Atlas推理系列产品(Ascend 310P处理器)AI Core
Atlas推理系列产品(Ascend 310P处理器)Vector Core
Atlas A2训练系列产品/Atlas 800I A2推理产品
Atlas 200/500 A2推理产品
注意事项
在转换过程中,可能导致精度损失。
值 |
round |
floor |
ceil/ceiling |
away-zero |
to-zero |
odd |
---|---|---|---|---|---|---|
1.8 |
2 |
1 |
2 |
2 |
1 |
2 |
1.5 |
2 |
1 |
2 |
2 |
1 |
1 |
1.2 |
1 |
1 |
2 |
2 |
1 |
1 |
0.8 |
1 |
0 |
1 |
1 |
0 |
1 |
0.5 |
0 |
0 |
1 |
1 |
0 |
1 |
0.2 |
0 |
0 |
1 |
1 |
0 |
0 |
-0.2 |
0 |
-1 |
0 |
-1 |
0 |
0 |
-0.5 |
0 |
-1 |
0 |
-1 |
0 |
-1 |
-0.8 |
-1 |
-1 |
0 |
-1 |
0 |
-1 |
-1.2 |
-1 |
-2 |
-1 |
-2 |
-1 |
-1 |
-1.5 |
-2 |
-2 |
-1 |
-2 |
-1 |
-1 |
-1.8 |
-2 |
-2 |
-1 |
-2 |
-1 |
2 |
值 |
round |
floor |
ceil/ceiling |
away-zero |
to-zero |
odd |
---|---|---|---|---|---|---|
1.8 |
2 |
1 |
2 |
2 |
1 |
2 |
1.5 |
2 |
1 |
2 |
2 |
1 |
1 |
1.2 |
1 |
1 |
2 |
2 |
1 |
1 |
0.8 |
1 |
0 |
1 |
1 |
0 |
1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-1 |
-1 |
0 |
-1 |
0 |
-1 |
-1.2 |
-1 |
-2 |
-1 |
-1 |
-1 |
-1 |
-1.5 |
-2 |
-2 |
-1 |
-2 |
-1 |
-1 |
-1.8 |
-2 |
-2 |
-1 |
-2 |
-1 |
2 |
值 |
round |
floor |
ceil/ceiling |
away-zero |
to-zero |
odd |
---|---|---|---|---|---|---|
1.8 |
2 |
1 |
2 |
2 |
1 |
2 |
1.5 |
2 |
1 |
2 |
2 |
1 |
1 |
1.2 |
1 |
1 |
2 |
1 |
1 |
1 |
0.8 |
1 |
0 |
1 |
1 |
0 |
1 |
0.5 |
0 |
0 |
1 |
1 |
0 |
1 |
0.2 |
0 |
0 |
1 |
0 |
0 |
0 |
-0.2 |
0 |
-1 |
0 |
0 |
0 |
0 |
-0.5 |
0 |
-1 |
0 |
-1 |
0 |
-1 |
-0.8 |
-1 |
-1 |
0 |
-1 |
0 |
-1 |
-1.2 |
-1 |
-2 |
-1 |
-1 |
-1 |
-1 |
-1.5 |
-2 |
-2 |
-1 |
-2 |
-1 |
-1 |
-1.8 |
-2 |
-2 |
-1 |
-2 |
-1 |
2 |
返回值
无
调用示例
from tbe import tik tik_instance = tik.Tik() src_scalar = tik_instance.Scalar(dtype="float32") src_scalar.set_as(1.4) dst_scalar = tik_instance.Scalar(dtype="int32") round_mode = "ceiling" tik_instance.scalar_conv(round_mode, dst_scalar, src_scalar) """ round_mode=round dst_scalar= round_mode=away-zero dst_scalar=2 round_mode=to-zero dst_scalar=1 round_mode=floor dst_scalar=1 round_mode=ceil dst_scalar=2 round_mode=ceiling dst_scalar=2 """ tik_instance.BuildCCE(kernel_name="run_scalar_conv", inputs=[], outputs=[])