Overview of Matmul Performance Optimization Strategies
This section provides a series of performance tuning cases for operators involving Matmul computation. You can refer to the optimization methods and ideas in the cases and apply them to your specific scenarios. The following table describes the case categories and introduction. For details, see the following sections.
Category |
Subcategory |
Application Scenario |
Case |
|---|---|---|---|
Tiling optimization |
Tiling optimization: Optimize the strategy for tiling cores and basic blocks. |
Large-shape scenarios with enough data size |
|
Parallelism optimization |
Inter-core task parallelism: Properly allocate data to different cores to execute tasks. |
Scenarios where the K-axis of the matrix is large and the M-axis and N-axis are smaller than the K-axis. |
|
Inter-core data access parallelism: Optimize the multi-core data parallel access mechanism, for example, optimize the address access conflicts of the same memory data in multi-core scenarios, to improve the multi-core data access efficiency. |
Scenarios where Matmul is executed on multiple cores, the K-axis of the input matrix is large, and the K-axis is not fully loaded. |
||
Intra-core pipeline parallelism: Different instruction queues can be executed independently and in parallel, which can be used to optimize intra-core pipeline parallelism. |
The MMAD pipeline and FIXPIPE pipeline of the operator are executed in serial mode. The synchronization waiting time accounts for a large proportion of the total execution time of the operator. |
||
MTE2 Bound and the MTE2 pipeline are executed in serial mode with other pipelines. |
|||
Memory optimization |
Memory sharing and reuse: Reduce the overhead caused by repeated data movement through buffer sharing and cache reuse. |
In the MIX scenario, the GM addresses of matrix A or matrix B of multiple AIVs are the same, and the matrix A or matrix B reused by multiple AIVs are fully loaded on L1 Buffer. |
|
Memory alignment: Ensure that the processed data meets specific alignment requirements. Use different data movement strategies for unaligned data to improve the data movement efficiency. |
Scenarios where the axis in the input matrix is not 256-byte aligned and the data size is large. |
||
Scalar optimization |
Static tiling: Complete Matmul tiling computation during kernel compilation. Convert variables into constants and spread them to the system to reduce scalar computations and improve performance. |
|
|
CUBE_ONLY: Reduce the extra Scalar overhead caused by the message processing mechanism. |
Compared with the MIX mode, the Vector computation is not performed, and only Cube computation is performed. |
||
Movement optimization |
Movement throughput optimization: Properly control the size of the data block to be moved to improve the bandwidth utilization and movement efficiency. |
Large-shape scenarios with a large number of MTE2 cyclic movements. |
|
Scenarios where the size of input and output data exceeds the L2 cache size. |
|||
Preloading movement: Preload the data blocks to be moved to reduce the gap between pipelines. |
Scenarios where the MTE2 pipeline gap is large and the value of M or N is large. |