目录

Basic Knowledge

This section describes how to use high-level APIs to perform matrix multiplication. In matrix programming, check the product models supported by the high-level APIs in Matmul.

Overview of Matrix Multiplication

Matmul formula: C = A x B + bias.

Matrix Multiplication Data Flow

Before learning about the matrix multiplication data flow, you need to review several important concepts of logical storage locations.

Matrix multiplication data flow refers to the flow direction of the input and output of the matrix multiplication between storage locations. The following figure shows the data flow of logical locations. (To simplify the description, bias is not listed.)

Data Formats

Two fractal formats ND and NZ are involved in completing Matmul.

Data Tiling

[h2]Multi-Core Tiling

To implement multi-core parallelism, matrix data needs to be tiled and allocated across cores for processing. The tiling strategies are as follows:

As shown in the following figure, eight cores participate in the computation. Matrix A is tiled into four blocks along the M axis, and matrix B is tiled into two blocks along the N axis. A single core processes one block only (for example, the green part in the figure is the data computed on core3). The matrix A block with the size of singleCoreM x K is multiplied by the matrix B block with the size of singleCoreN x K to obtain the matrix C block with the size of singleCoreM x singleCoreN.

[h2]Intra-Core Tiling

In most cases, the local memory cannot completely store the operator input and output. Therefore, you need to pass some inputs for multiple times until the complete final result is obtained. This process is intra-core tiling. Tiling policies:

In addition to baseM, baseN, and baseK, there are some common tiling parameters. The meanings of these parameters are as follows: