This case shows the optimized operator performance when MTE2 Preload is enabled in the matrix multiplication of the high-level Matmul API in the matrix multiplication operator scenario. The doMTE2Preload parameter in MatmulConfig is used to enable the preload function in the M or N direction of the matrix, which means that the data of matrix A or B is loaded in advance during the MTE2 interval. After the preload function is enabled, the MTE2 interval can be reduced, thereby improving operator performance. For details about the doMTE2Preload parameter, see MatmulConfig.
The MTE2 pipeline gap is large, and the value of M or N is large.
The operator specifications are as follows.
|
Input |
Shape |
Data Type |
Format |
|---|---|---|---|
|
a |
128, 512 |
float16 |
ND |
|
b |
512, 24576 |
float16 |
ND |
On the AI processor used in the current case, there are 24 cores in total, and the high-level API Matmul in CUBE_ONLY is enabled for the operator. Use the MDL template. The tiling parameters are as follows:
Use the msProf tool to obtain the Operator Simulation Pipeline and On-board Profiling data, and focus on analyzing Cube and FixPipe pipelines.

Enable MTE2 Preload: When creating a Matmul object, enable doMTE2Preload. For details about the sample of enabling MTE2 Preload, see Matmul operator sample for preloading in the M direction. The specific procedure is as follows:
1 2 |
// preloadMode = 2 static constexpr MatmulConfig MM_CFG = GetMDLConfig(false, false, preloadMode); |
1 2 3 4 |
AscendC::Matmul<AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, aType>, AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, bType>, AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, cType>, AscendC::MatmulType<AscendC::TPosition::GM, CubeFormat::ND, biasType>, MM_CFG> matmulObj; |

When the MTE2 pipeline gap is large and the value of M or N is large, you can enable MTE2 Preload to load the data of matrix A or B in advance.