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 Type | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | u16 | s32 | u32 | s64 | u64 | bool | c32 | c64 | c128 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| f32 | f32 | f32 | f64 | f32 | f32 | f32 | f32 | N/A | f32 | N/A | f32 | N/A | f32 | c64 | c64 | c128 |
| f16 | f32 | f16 | f64 | f32 | f16 | f16 | f16 | N/A | f16 | N/A | f16 | N/A | f16 | c32 | c64 | c128 |
| f64 | f64 | f64 | f64 | f64 | f64 | f64 | f64 | N/A | f64 | N/A | f64 | N/A | f64 | c128 | c128 | c128 |
| bf16 | f32 | f32 | f64 | bf16 | bf16 | bf16 | bf16 | N/A | bf16 | N/A | bf16 | N/A | bf16 | c32 | c64 | c128 |
| s8 | f32 | f16 | f64 | bf16 | s8 | s16 | s16 | N/A | s32 | N/A | s64 | N/A | s8 | c32 | c64 | c128 |
| u8 | f32 | f16 | f64 | bf16 | s16 | u8 | s16 | N/A | s32 | N/A | s64 | N/A | u8 | c32 | c64 | c128 |
| s16 | f32 | f16 | f64 | bf16 | s16 | s16 | s16 | N/A | s32 | N/A | s64 | N/A | s16 | c32 | c64 | c128 |
| u16 | N/A | N/A | N/A | N/A | N/A | N/A | N/A | u16 | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A |
| s32 | f32 | f16 | f64 | bf16 | s32 | s32 | s32 | N/A | s32 | N/A | s64 | N/A | s32 | c32 | c64 | c128 |
| u32 | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | u32 | N/A | N/A | N/A | N/A | N/A | N/A |
| s64 | f32 | f16 | f64 | bf16 | s64 | s64 | s64 | N/A | s64 | N/A | s64 | N/A | s64 | c32 | c64 | c128 |
| u64 | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | u64 | N/A | N/A | N/A | N/A |
| bool | f32 | f16 | f64 | bf16 | s8 | u8 | s16 | N/A | s32 | N/A | s64 | N/A | bool | c32 | c64 | c128 |
| c32 | c64 | c32 | c128 | c32 | c32 | c32 | c32 | N/A | c32 | N/A | c32 | N/A | c32 | c32 | c64 | c128 |
| c64 | c64 | c64 | c128 | c64 | c64 | c64 | c64 | N/A | c64 | N/A | c64 | N/A | c64 | c64 | c64 | c128 |
| c128 | c128 | c128 | c128 | c128 | c128 | c128 | c128 | N/A | c128 | N/A | c128 | N/A | c128 | c128 | c128 | c128 |
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.