To implement multi-core parallelism for higher efficiency, matrix data needs to be tiled and allocated across cores for processing. There are two main tiling policies: K-axis tiling and non-K-axis tiling.
The policies for tiling only the M and N axes but not the K axis are as follows:
As shown in the following figure, eight cores participate in the compute. 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 only one block (for example, the green part in the figure is the data computed on core5). The matrix A block with the size of singleCoreM × K is multiplied by the matrix B block with the size of singleCoreN × K to obtain the matrix C block with the size of singleCoreM × singleCoreN.

The following figure shows the policies of tiling the M, N, and K axes.
As shown in the following figure, matrix R blocks in matrix C are obtained by accumulating A1 × B1 + A2 × B2 + A3 × B3, where A1 × B1, A2 × B2, and A3 × B3 can be computed in parallel on multiple cores.

SetDim sets the number of available cores of the AI Processor. The number of cores actually used for Matmul computation is calculated by tiling. The number of cores actually used is smaller than or equal to the number of available cores of the AI Processor. Configure SetBlockDim according to the actual number of used cores.
Matmul matrix computation with multiple cores.
None
The key sample code for this scenario is as follows. For details about the complete example in the Matmul multi-core aligned scenario, see the following samples: matmul multi-core kernel launch sample (multi-core M and N tiling) and operator sample for multi-core K splitting (multi-core K tiling).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Construct a multi-core tiling object. auto ascendcPlatform = platform_ascendc::PlatformAscendCManager::GetInstance(socVersion); matmul_tiling::MultiCoreMatmulTiling cubeTiling(*ascendcPlatform); // For operators that involve Cube computation only, set the number of cores that can participate in matrix multiplication to the number of Cube cores on the AI Processor. cubeTiling.SetDim(ascendcPlatform.GetCoreNumAic()); cubeTiling.SetAType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT16); cubeTiling.SetBType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT16); cubeTiling.SetCType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT); cubeTiling.SetBiasType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT); cubeTiling.SetOrgShape(M, N, K); cubeTiling.SetShape(M, N, K); cubeTiling.EnableBias(isBias); optiling::TCubeTiling tilingData; // Obtain tiling parameters. int ret = cubeTiling.GetTiling(tilingData); // if ret = -1, gen tiling failed |