Tiling Strategy for Matmul Operator Optimization

Case Study

This case analyzes and optimizes the performance of the Matmul operator. The Matmul operator implements matrix multiplication, including data transfer in/out pipelines and Cube computation pipelines.

The following uses the matrix dimensions M = 4096, N = 5120, K = 4096, half type input, float type out, and output format ND as an example to describe how to optimize the Matmul operator on the Atlas A2 training product / Atlas A2 inference product , including optimizing the core division logic, optimizing basic blocks, and enabling large packet transfer.

Obtaining Profile Data

Use the msProf tool to obtain the profile data of the operator, focusing on the statuses of the MTE2, Cube, and Scalar pipelines.

Analyzing Main Bottlenecks

Figure 1 Profile data before optimization

According to the preceding profile data, the ratio of MTE2 time is high, implying that the performance bottleneck lies in MTE2 pipeline.

Developing Optimization Solutions

Verifying Optimization Benefits

Summary

Optimizations 1 and 2 require a large enough shape and data size to fully divide cores and enable optimal basic blocks. When the shape is large, you can refer to the optimization methods in this case for the MTE2 Bound operator.