Deduction Relationship

Tensor Deduction Relationship

Deduction Rules

When the input aclTensor data types of an API (such as aclnnAdd, aclnnMul, etc.) are inconsistent, the API internally deduces a data type and converts the input data to that data type for computation.

For the data types supported by aclTensor, see data type. Some of these types follow the deduction rules below. The deduction principle is similar to Type Promotion of PyTorch.

The type deduction rules are as follows:

NOTE

  • For ease of description, the data types used in the table are in abbreviated form, with the following meanings: ACL_FLOAT(f32), ACL_FLOAT16(f16), ACL_DOUBLE(f64), ACL_BF16(bf16), ACL_INT8(s8), ACL_UINT8(u8), ACL_INT16(s16), ACL_UINT16(u16), ACL_INT32(s32), ACL_UINT32(u32), ACL_INT64(s64), ACL_UINT64(u64), ACL_BOOL(bool), ACL_COMPLEX32(c32), ACL_COMPLEX64(c64), ACL_COMPLEX128(c128).
  • The table header and the leftmost column represent the two input data types to be deduced, and the corresponding cell in the table indicates the deduced data type.
  • A cross (×) in the table indicates that the two types cannot be used for deduction computation.

Table 1 Data type deduction relationship

Data Typef32f16f64bf16s8u8s16u16s32u32s64u64boolc32c64c128
f32f32f32f64f32f32f32f32×f32×f32×f32c64c64c128
f16f32f16f64f32f16f16f16×f16×f16×f16c32c64c128
f64f64f64f64f64f64f64f64×f64×f64×f64c128c128c128
bf16f32f32f64bf16bf16bf16bf16×bf16×bf16×bf16c32c64c128
s8f32f16f64bf16s8s16s16×s32×s64×s8c32c64c128
u8f32f16f64bf16s16u8s16×s32×s64×u8c32c64c128
s16f32f16f64bf16s16s16s16×s32×s64×s16c32c64c128
u16×××××××u16××××××××
s32f32f16f64bf16s32s32s32×s32×s64×s32c32c64c128
u32×××××××××u32××××××
s64f32f16f64bf16s64s64s64×s64×s64×s64c32c64c128
u64×××××××××××u64××××
boolf32f16f64bf16s8u8s16×s32×s64×boolc32c64c128
c32c64c32c128c32c32c32c32×c32×c32×c32c32c64c128
c64c64c64c128c64c64c64c64×c64×c64×c64c64c64c128
c128c128c128c128c128c128c128c128×c128×c128×c128c128c128c128

Deduction Examples

  • When calling the aclnnAdd API, if the input parameters have inconsistent data types — one being float16 and the other float32 — the API internally converts the float16 data type to float32 and then performs the computation.
  • When calling the aclnnAdd API, if the input parameters have inconsistent data types — one being float32 and the other bool — the API internally converts the bool data type to float32 and then performs the computation.

Deduction Relationship between Tensor and Scalar

Deduction Rules

When the input Tensor data type and the input Scalar data type of an API (such as aclnnAdds, aclnnMuls, etc.) are inconsistent, the API internally deduces a data type and converts the input data to that data type for computation.

For the data types supported by aclTensor, see data type. Some of these types follow the deduction rules below. The deduction principle is similar to Type Promotion of PyTorch.

The type deduction rules are as follows:

NOTE

  • For ease of description, the data types used in the table are abbreviated. Their meanings are: ACL_FLOAT(f32), ACL_FLOAT16(f16), ACL_DOUBLE(f64), ACL_BF16(bf16), ACL_INT8(s8), ACL_UINT8(u8), ACL_INT16(s16), ACL_UINT16(u16), ACL_INT32(s32), ACL_UINT32(u32), ACL_INT64(s64), ACL_UINT64(u64), ACL_BOOL(bool), ACL_COMPLEX32(c32), ACL_COMPLEX64(c64), ACL_COMPLEX128(c128).
  • In the table, the header row represents the input Tensor data type to be deduced, the leftmost column represents the input Scalar data type to be deduced, and the corresponding cell in the table indicates the deduced data type.
  • A cross mark (x) in the table indicates that the two types cannot undergo deduction computation.

Table 2 Data type deduction relationship

Data Typef32f16f64bf16s8u8s16u16s32u32s64u64boolc32c64c128
f32f32f16f64bf16f32f32f32xf32xf32xf32c32c64c128
f16f32f16f64bf16f32f32f32xf32xf32xf32c32c64c128
f64f32f16f64bf16f32f32f32xf32xf32xf32c128c128c128
bf16f32f16f64bf16f32f32f32xf32xf32xf32c32c64c128
s8f32f16f64bf16s8u8s16u16s32u32s64u64s8c32c64c128
u8f32f16f64bf16s8u8s16u16s32u32s64u64u8c32c64c128
s16f32f16f64bf16s8u8s16u16s32u32s64u64s16c32c64c128
u16f32f16f64bf16s8u8s16u16s32u32s64u64xc32c64c128
s32f32f16f64bf16s8u8s16u16s32u32s64u64s32c32c64c128
u32f32f16f64bf16s8u8s16u16s32u32s64u64xc32c64c128
s64f32f16f64bf16s8u8s16u16s32u32s64u64s64c32c64c128
u64f32f16f64bf16s8u8s16u16s32u32s64u64xc32c64c128
boolf32f16f64bf16s8u8s16u16s32u32s64u64boolc32c64c128
c32c64c32c128c64c64c64c64c64c64c64c64c64c64c32c64c128
c64c64c32c128c64c64c64c64c64c64c64c64c64c64c32c64c128
c128c64c32c128c64c64c64c64c64c64c64c64c64c64c32c64c128

Deduction Examples

  • If the data type of the input Tensor is float16 and the data type of the input Scalar is float32, the API internally converts the float32 data type of the input Scalar to float16 before performing the computation.
  • If the data type of the input Tensor is bool and the data type of the input Scalar is float32, the API internally converts the bool data type of the input Tensor to float32 before performing the computation.