Kernel for converting tensors of various datatypes and formats.
- Kernel requires input tensor ( \( X \)) to be available in memory
- The output tensor ( \( Y \)) is computed as shown below
- \(Y = (X - inZf) \times scale + outZf \\ \hspace{1.25ex} = X \times scale - (inZf \times scale + outZf) \\ \hspace{1.25ex} = X \times scale + q \)
- For integer to floating-point conversions and vice versa, the mapping is as shown below
- \( Y = X \times scale + q_1 \times q_2 \)
- For integer-to-integer conversions, the mapping is as shown below
- \( Y = \text{shiftAndRound}(X \times scale + q_1 \times q_2) \\ \hspace{1.25ex} = \begin{bmatrix} scale \times I & Q_1\end{bmatrix} \times \begin{bmatrix} X \\ Q_2\end{bmatrix} \text{where, }Q_1 \text{is a constant matrix and } \text{shiftAndRound is performed within MMA} \\ \)
- Example configuration with two rows allocated to handle precision for qauntization; MMALIB_CNN_tensor_convert_ixX_oxX_InitArgs::numRowsQuant = 2
- \( Y = \begin{bmatrix} s & 0 & \cdots & 0 & q_1 & q_1 \\ 0 & s & \cdots & 0 & q_1 & q_1 \\ \vdots & \cdots & \ddots & 0 & q_1 & q_1 \\ 0 & 0 & 0 & s & q_1 & q_1 \\ \end{bmatrix}\times \begin{bmatrix} x_{(0,0)} & x_{(0,1)} & \cdots & x_{(0,61)} & 0 & 0 \\ x_{(1,0)} & x_{(1,1)} & \cdots & x_{(1,61)} & 0 & 0 \\ \vdots & \vdots & \ddots & \vdots & 0 & 0 \\ x_{(61,0)} & x_{(61,1)} & \cdots & x_{(61,61)} & 0 & 0 \\ q_{2(0,0)} & q_{2(0,1)} & \cdots & q_{2(0,61)} & 0 & 0 \\ q_{2(1,0)} & q_{2(1,1)} & \cdots & q_{2(1,61)} & 0 & 0 \\ \end{bmatrix} \)
- Output pad (MMALIB_CNN_tensor_convert_ixX_oxX_InitArgs::outPad) is always zero if output tensor format is NHWC (MMALIB_HWC)
- Performance estimates is TBD, "Arch. Compute cyc." and "Est. Compute
cyc." are yet to be analyzed; right now printed as "0"
- Signedness of Q2: since we use B buffers of MMA to hold the input tensor and Q2 during compute, it is required that the signedness of Q2 is the same as the input tensor
- For example, Q2 cannot be int8_t when converting from uint8_t to int8_t
- Signedness of Scale: Scale is always signed and the same precision as the max precision involved in the conversion
- For example, scale is int16_t when converting from uint8_t to uint16_t
- Only the below conversion formats are supported