Kernel provides compute functionality of Fully Connected Layer: \( Y^T = X^T \times H^T \).
Kernel requires feature map ( \( X^T \)) and coefficients (parameter matrix, \( H^T \)) to be available in memory
8- and 16-bit datatypes supported
Supported datatypes for feature map are 8- and 16-bit signed or unsigned
Supported datatypes for coefficients are 8- and 16-bit signed
Supported datatypes for output are 8- and 16-bit signed or unsigned
Original algorithm for batch size greater than one: \( Y = H \times X + B \)
Here, \( Y \) is output matrix, \( H \) is kernel matrix, \( X \) is feature matrix (column-major order), and \( B \) is bias matrix
Note: \( Y \) and \( X \) will be column matrices for batch size of one
After applying affine transformation, we obtain matrix structures as shown below
\( Y \) = \( \begin{bmatrix} H & B_1 \end{bmatrix} \times \begin{bmatrix} X \\ B_2 \end{bmatrix} \)
Note that \( B \) matrix is mathematically split into \( B_1 \) and \( B_2 \), and \( B_2 \) is constant matrix whose value is supplied via MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs::bias
\( B_2 \) is appended on-the-fly via predicate register; therefore, \( X\) matrix shall not be appended with \( B_2 \) when stored in memory
Since \( X \) is stored in row-major order in memory, we apply transpose to affine-transformed matrix structure mentioned above
\( Y^T \) = \( \begin{bmatrix} X^T & B_2^T \end{bmatrix} \times \begin{bmatrix} H^T \\ B_1^T \end{bmatrix} \)
This kernel requires specific data arrangement for the kernel matrix to alleviate bank conflicts in L2 when performing DMA transfers in conjunction to execution of this kernel
Desired physical bank-access pattern for streaming engines and DMA in L2 is {0,0,1,1,2,2,3,3,0,0,1,1,2,2,3,3, ...}
Re-ordering functionality of MMALIB_CNN_fullyConnected_ixX_ixX_oxX_reorderWeights maybe used
Below figure shows two examples where MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs::kDimRows (517) = MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs::Ni (512) + number of bias rows (5); Number of output features = 128 or 104
Filter Coefficient Buffer
The kernel also supports cases when parameter or feature map matrix does not fit in L2 memory
Three buffers of type MMALIB_bufParams2D_t : src0 \( \rightarrow X^T \); src1 \( \rightarrow H^T \); and dst \( \rightarrow Y^T \)
The multiPassX flag in structures MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs::multiPassX and MMALIB_CNN_fullyConnected_ixX_ixX_oxX_ExecArgs::multiPassX facilitate the feature when feature map matrix does not fit in L2 memory
Table below shows the flag combinations supported:
multiPassX multiPassH Status
False False Supported
False True Supported
True False Not supported
True True Supported