SetDim
Function
Sets the number of cores that participate in multi-core Matmul computation. The rules vary in different scenarios.
- Cube-only mode (only matrix computation)
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 less than or equal to the number of available cores of the AI Processor. SetBlockDim is configured by users based on the actual number of used cores. All the cores loaded by SetBlockDimSetBlockDim are used for computation of the Matmul API.
- MIX mode (matrix computation and vector computation)
- Separated mode: The Matmul API is always initiated from the AIV. When the Iterate API is called for computation, AIV only instructs AIC to perform matrix computation. After the computation is complete, AIC sends a notification to AIV. At the developer level, the number of AIV cores is perceived. In this case, SetDim is set to the number of available AIV cores of the AI Processor, and the number of AIV cores actually used is computed through tiling. SetBlockDim is set to the number of AI Cores (AIC and AIV) actually used. For example, if SetDim is set to 40, 40 AIV cores can be used to initiate multi-core Matmul computation, and the number of AIV cores actually used is 20 (computed through tiling). If the ratio of AIC to AIV cores of the AI Processor is 1:2, SetBlockDim is set to 10, indicating that 10 AI Cores (AIC and AIV) are actually used.
- Coupled mode: SetDim sets the number of available cores of the AI Processor. The number of cores actually used is computed through tiling. The number of cores actually used is less than or equal to the number of available cores of the AI Processor. SetBlockDimSetBlockDim is configured by users based on the actual number of used cores. All the cores loaded by SetBlockDimSetBlockDim are used for computation of the Matmul API.
Prototype
1
|
int32_t SetDim(int32_t dim) |
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
dim |
Input |
Number of cores that can be used in the multi-core Matmul tiling computation. In MIX mode, the value of this parameter must be less than or equal to the number of AI Cores started in coupled mode or the number of AIV cores started in separated mode. |
Returns
-1: setting failed; 0: setting succeeded.
Restrictions
None
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
auto ascendcPlatform = platform_ascendc::PlatformAscendC(context->GetPlatformInfo()); matmul_tiling::MultiCoreMatmulTiling tiling(ascendcPlatform); tiling.SetDim (1); // Set the number of cores involved in the computation. tiling.SetAType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT16); tiling.SetBType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT16); tiling.SetCType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT); tiling.SetBiasType(matmul_tiling::TPosition::GM, matmul_tiling::CubeFormat::ND, matmul_tiling::DataType::DT_FLOAT); tiling.SetShape(1024, 1024, 1024); tiling.SetSingleShape(1024, 1024, 1024); tiling.SetOrgShape(1024, 1024, 1024); tiling.SetBias(true); tiling.SetBufferSpace(-1, -1, -1); optiling::TCubeTiling tilingData; int ret = tiling.GetTiling(tilingData); |