Mutual Derivation Relationship

Derivation Rules

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

For the data types supported by aclTensor, see Data Types. Some of these types satisfy the following derivation rules, and the derivation principle is similar to PyTorch's Type Promotion.

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 derived, and the corresponding cell in the table indicates the derived data type.
  • A cross (×) in the table indicates that the two types cannot be used for derivation computation.

Table 1 Data type derivation relationship

Data Typef32f16f64bf16s8u8s16u16s32u32s64u64boolc32c64c128
f32f32f32f64f32f32f32f32N/Af32N/Af32N/Af32c64c64c128
f16f32f16f64f32f16f16f16N/Af16N/Af16N/Af16c32c64c128
f64f64f64f64f64f64f64f64N/Af64N/Af64N/Af64c128c128c128
bf16f32f32f64bf16bf16bf16bf16N/Abf16N/Abf16N/Abf16c32c64c128
s8f32f16f64bf16s8s16s16N/As32N/As64N/As8c32c64c128
u8f32f16f64bf16s16u8s16N/As32N/As64N/Au8c32c64c128
s16f32f16f64bf16s16s16s16N/As32N/As64N/As16c32c64c128
u16N/AN/AN/AN/AN/AN/AN/Au16N/AN/AN/AN/AN/AN/AN/AN/A
s32f32f16f64bf16s32s32s32N/As32N/As64N/As32c32c64c128
u32N/AN/AN/AN/AN/AN/AN/AN/AN/Au32N/AN/AN/AN/AN/AN/A
s64f32f16f64bf16s64s64s64N/As64N/As64N/As64c32c64c128
u64N/AN/AN/AN/AN/AN/AN/AN/AN/AN/AN/Au64N/AN/AN/AN/A
boolf32f16f64bf16s8u8s16N/As32N/As64N/Aboolc32c64c128
c32c64c32c128c32c32c32c32N/Ac32N/Ac32N/Ac32c32c64c128
c64c64c64c128c64c64c64c64N/Ac64N/Ac64N/Ac64c64c64c128
c128c128c128c128c128c128c128c128N/Ac128N/Ac128N/Ac128c128c128c128

Derivation 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.