MatmulConfig
Configures Matmul template information and related parameters. If the parameter is not set, the Norm template is enabled by default. For details, see template features. For details, see Table 2. MatmulConfig can be defined in the following ways:
- It can be set to one of the provided templates. Possible values are CFG_NORM, CFG_MDL, CFG_IBSHARE_NORM, and MM_CFG_BB, which correspond to the default Norm, MDL, IBShare, and BasicBlock templates, respectively. For details about each template, see Table 1.
- It can be customized using various APIs for obtaining templates to obtain custom templates. The APIs for obtaining templates include GetNormalConfig, GetMDLConfig, GetSpecialMDLConfig, GetIBShareNormConfig, GetBasicConfig, and GetSpecialBasicConfig.
- In addition, it can be split into level-2 sub-configs (MatmulShapeParams, MatmulQuantParams, MatmulBatchParams, and MatmulFuncParams). You can use the GetMMConfig API to set the required level-2 sub-configs and MatmulConfigMode to flexibly obtain the custom template parameter configuration MatmulConfig.
|
Template |
Implementation |
Advantage |
Applicable Scenario |
|---|---|---|---|
|
L1 can cache multiple base blocks. MTE2 moves base blocks from GM to L1 for multiple times, with one base block moved each time. The moved base blocks are not cleared. For example, if depthA1 in the tiling structure is set to 6, six base blocks of matrix A are moved to L1, one base block is moved at a time, and MTE2 moves blocks for six times. |
The MTE1 pipeline can be started in advance, because the subsequent computation of MTE1 can be performed after one base block is moved. |
The Norm template is enabled by default. |
|
|
L1 can cache multiple base blocks. The data movement of MTE2 from GM to L1 is a one-time "large-packet" movement. For example, if depthA1 in the tiling structure is set to 6, six base blocks of matrix A are moved to L1 at a time, and MTE2 moves blocks once. For details about the differences between the MDL template and the SpecialMDL template, see Table 2. |
In common large-shape scenarios, this can reduce MTE2 cyclic movement to improve performance. |
Large-shape scenarios |
|
|
IBShare |
In the MIX scenario, when the GM addresses of matrix A or matrix B are the same, L1 Buffer is shared to reduce MTE2 movement. |
This reduces MTE2 movement and improves performance. |
The GM addresses of matrix A or matrix B of multiple AIVs are the same in the MIX scenario. Note: To use the IBShare template, the matrix A or matrix B reused by multiple AIVs must be fully loaded on L1 Buffer. |
|
BasicBlock |
If there is no tail block and the base block size is fixed, the GetBasicConfig API can be used to configure the size of input base blocks, and fix the size of the matrix moved by MTE1 each time and the size of the matrix computed by matrix multiplication each time to reduce the parameter computation workload. |
This reduces the parameter computation overhead during MTE1 matrix movement and matrix multiplication computation. |
There is no tail block, and the size of the base block (baseM, baseN) is determined. |
|
Parameter |
Description |
Supported Templates: Norm, MDL, SpecialMDL, IBShare, and BasicBlock |
||
|---|---|---|---|---|
|
doNorm |
Whether to enable the Norm template. Values:
If no value is specified, the Norm template is enabled by default. |
Norm |
||
|
doBasicBlock |
Whether to enable the BasicBlock template. Values:
When GetBasicConfig is called to obtain the BasicBlock template, this parameter is set to true. Notes:
For the For the For the For the |
BasicBlock |
||
|
Whether to enable the MDL template. Values: |
MDL |
|||
|
basicM |
Equivalent to the baseM parameter in the TCubeTiling structure. It indicates the length of the M axis of a base block during Matmul computation. The unit is element. |
BasicBlock |
||
|
basicN |
Equivalent to the baseN parameter in the TCubeTiling structure. It indicates the length of the N axis of a base block during Matmul computation. The unit is element. |
BasicBlock |
||
|
basicK |
Equivalent to the baseK parameter in the TCubeTiling structure. It indicates the length of the K axis of a base block during Matmul computation. The unit is element. |
BasicBlock |
||
|
intrinsicsCheck |
Whether to enable cyclic data move-in from the Global Memory to L1 Buffer when the inner axis (last axis) of the left or right matrix on a single core is greater than or equal to 65535 (number of elements). For example, for the left matrix A [M, K], if singleCoreK of the inner axis on a single core is greater than 65535 and this parameter is set to true, data is moved in cyclically in the API. Values:
|
All templates |
||
|
Whether to enable multi-batch input and output. This parameter is valid only for BatchMatmul. After this parameter is enabled, only the Norm template is supported, and IterateNBatch needs to be called to implement multi-batch input and output. Values:
|
Norm |
|||
|
enVecND2NZ |
Whether to enable ND2NZ (converting data from ND format to NZ format) using vector. To enable this function, you need to set SetLocalWorkspace. Values:
For |
All templates |
||
|
doSpecialBasicBlock |
Whether to enable the SpecialBasicBlock template. Values:
It is also a BasicBlock template, but it eliminates scalar computation of overhead. |
Reserved parameter |
||
|
doMTE2Preload |
Whether to enable the preloading function in the M/N direction when MTE2 pipeline gap and the M/N value are large. After this function is enabled, the MTE2 pipeline gap is reduced and the performance is improved. The preloading function is valid only for the MDL template. Values:
Note: When preloading in the M/N direction is enabled, ensure that the data is fully loaded in the K direction and DoubleBuffer is enabled in the M/N direction. The condition for full load in the M direction is that singleCoreK/baseK is less than or equal to stepKa, and that in the N direction is singleCoreK/baseK is less than or equal to stepKb. For details about how to use this parameter, see Matmul operator sample for preloading in the M and N directions. |
MDL |
||
|
singleCoreM |
Shape size of a single core on the M axis, in elements. |
Reserved parameter |
||
|
singleCoreN |
Shape size of a single core in the N axis, in elements. |
Reserved parameter |
||
|
singleCoreK |
Shape size of a single core in the K axis, in elements. |
Reserved parameter |
||
|
stepM |
A multiple of baseM of the left matrix in the bufferM direction buffered in A1. |
Reserved parameter |
||
|
stepN |
A multiple of baseN of the right matrix in the bufferN direction buffered in B1. |
Reserved parameter |
||
|
baseMN |
Size of baseM × baseN. |
Reserved parameter |
||
|
singleCoreMN |
Size of singleCoreM × singleCoreN. |
Reserved parameter |
||
|
enUnitFlag |
Whether to enable the UnitFlag function to allow parallel execution of computation and data movement for performance improvement. By default, the function is enabled when the Norm and IBShare templates are used and disabled when the MDL template is used. Values:
For details about how to use this parameter, see matmul_unitflag operator sample. |
MDL, Norm, and IBShare |
||
|
isPerTensor |
Whether quantization for matrix B is conducted per tensor or per channel in the scenario where matrix A's input type is half and matrix B's input type is int8_t.
|
MDL and SpecialMDL |
||
|
hasAntiQuantOffset |
Whether to use the offset coefficient when matrix B quantization is enabled in the scenario where matrix A's input type is half and matrix B's input type is int8_t. |
MDL and SpecialMDL |
||
|
Whether to enable the IBShare template. Values:
IBShare is used to reuse the same matrix A or B data on L1. After IBShare is enabled, repeated data movement to L1 can be avoided for data reuse. |
IBShare |
|||
|
doSpecialMDL |
Whether to enable the SpecialMDL template. Values:
Special scenario of the MDL template: When the MDL template is not fully loaded in the Matmul K direction (singleCoreK/baseK > stepKb), stepN can be set to 1 by default. After the SpecialMDL template is enabled, stepN can be set to 2. Note: When the SpecialMDL template is enabled, the value of doMultiDataLoad must be false. |
SpecialMDL |
||
|
enableInit |
Whether to enable the Init function. If the Init function is disabled, the constant propagation effect can be improved and the performance can be optimized. By default, it is enabled.
|
All templates |
||
|
Relationship between the total amount of multi-batch data for input matrices A and B in a BatchMatmul operation and the size of L1 Buffer when the layout type is set to Normal in the BatchMatmul scenario. Values:
|
Norm |
|||
|
enableEnd |
Whether to call the End function during Matmul computation. This parameter can be used to optimize performance. Values:
|
All templates |
||
|
enableGetTensorC |
Whether to call the GetTensorC function during Matmul computation. This parameter can be used to optimize performance. Values:
|
All templates |
||
|
enableSetOrgShape |
Whether to call the SetOrgShape function during Matmul computation. This parameter can be used to optimize performance. Values:
|
All templates |
||
|
enableSetBias |
Whether to compute bias. This parameter can be used to optimize performance. Values:
|
MDL |
||
|
enableSetTail |
Whether to call the SetTail function during Matmul computation. This parameter can be used to optimize performance. Values:
|
All templates |
||
|
enableQuantVector |
Whether to call the SetQuantVector and SetQuantScalar functions during Matmul computation. This parameter can be used to optimize performance. Values:
|
All templates |
||
|
enableSetDefineData |
Whether to enable the setting of information such as the computation data required by the callback function or the data address stored on GM when MatmulCallBack (custom callback function) is enabled. Values:
|
MDL |
||
|
iterateMode |
Iteration mode, used to optimize the Matmul computation overhead. Specifically, it is used for the optimization through Iterate APIs (including Iterate, IterateAll, IterateBatch, and IterateNBatch). When a mode is enabled, only one Iterate API corresponding to the mode is called during the Matmul computation, and the code related to other Iterate APIs is deleted during compilation to optimize performance. This parameter is of the IterateMode type. Values:
For the For the For the For the |
All templates |
||
|
enableReuse |
Whether dataPtr in the callback function set by SetSelfDefineDatafunction directly transfers the computation data. If the SetSelfDefineData function is not called to set dataPtr, this parameter can only be set to the default value true. Values:
|
Norm and MDL |
||
|
enableUBReuse |
Whether to enable Unified Buffer reuse. When the Unified Buffer has sufficient capacity (its size is greater than four times the value of transLength of TCubeTiling), enabling this parameter divides the Unified Buffer into two non-overlapping regions. These two regions store the data for two consecutive Matmul iterations. With Unified Buffer reuse enabled, the data of the next iteration can be loaded into the second region. It no longer needs to wait for the previous iteration's Unified Buffer region to be released. This optimizes pipeline and improves overall performance. Values:
For For For For |
MDL |
||
|
enableL1CacheUB |
Whether to cache Unified Buffer computing blocks in L1 Buffer. It is recommended that this parameter be used in scenarios where the MTE3 and MTE2 pipelines are frequently used in serial mode. Values:
To cache Unified Buffer computing blocks in L1 Buffer, you must call SetMatmulConfigParams in the tiling implementation to set enableL1CacheUBIn to true. For For For For |
MDL |
||
|
Whether to enable the accumulation of a single computation result (matrix slices with the size of baseM × baseN) of two AIV cores on L0C Buffer in the case of fused vector and cube computation on the separated architecture. Values:
For the For the For the For the |
Norm |
|||
|
IterateOrder |
Iteration sequence for Matmul to perform cube computation. The meaning of this parameter is the same as that of iterateOrder in Table 1. This parameter is valid only when ScheduleType is set to ScheduleType::OUTER_PRODUCT. Values:
Note: When the Norm template (Matmul scenario) and the MDL template are used, if IterateOrder is set to ORDER_M, the value of stepN in the TCubeTiling structure must be greater than 1. If IterateOrder is set to ORDER_N, the value of stepM in the TCubeTiling structure must be greater than 1. For details about how to use this parameter, see Matmul operator sample for pipeline parallelism in the M and N directions. For For For For |
Norm and MDL |
||
|
scheduleType |
Matmul data movement mode. Values:
Note:
For For For For |
Norm and MDL |
||
|
enableDoubleCache |
Whether to cache two blocks in L1 Buffer after the IBShare template is enabled. Values:
Note: If this parameter is set to true, the base block size must be controlled to ensure that the cached data blocks do not exceed the L1 Buffer capacity. |
IBShare |
||
|
isBiasBatch |
Whether the bias size includes batch axes in the BatchMatmul scenario. Values:
For For For For |
Norm |
||
|
enableStaticPadZeros |
Whether to automatically pad zeros based on the sizes of singleM, singleN, singleK, baseM, baseN, and baseK when the static tiling parameters are used and the left and right matrices are moved to L1 Buffer. For details about the static tiling parameters, see GetMatmulApiTiling. Only the ND2NZ format of the GM input supports padding zeros. In other scenarios, you need to pad zeros manually. Values:
|
Norm and MDL |
||
|
Whether to enable the PartialOutput function. This parameter controls how Matmul computes and outputs base blocks along the K axis. In other words, this parameter determines whether to accumulate the partial results along the K axis when Matmul runs one Iterate step. Values:
For For For For |
MDL |
|||
|
Whether to enable MixDualMaster (dual-master mode). Different from the MIX mode (including cube computation and vector computation) that drives the AIC to run using the message mechanism, the dual-master mode enables the AIC and AIV to run independently without depending on the message mechanism. The default value is false. This parameter can be set to true only in the following scenarios:
Note that the following conditions must be met to enable MixDualMaster:
For details about how to use this parameter, see operator sample for enabling the active-active mode. For For For For |
Norm |
|||
|
isA2B2Shared |
Whether to enable the global management of A2 and B2, that is, whether all Matmul objects share the double buffering mechanism of A2 and B2. As this is a global configuration, the parameter values for all Matmul objects must be the same. When it is enabled, the base block sizes of matrix A and matrix B cannot exceed 32 KB. Values:
For For For For When this parameter is set to true, you are advised to set enUnitFlag to true so that the data transfer and computation pipeline can be performed in parallel mode, improving performance. For details about the example of using this parameter, see global management sample of Matmul A2 and B2. |
Norm and MDL |
||
|
Whether to enable the channel_split function. In normal cases, the fractal size of the matrix C in CubeFormat::NZ format computed by Matmul is 16 × 16. Assume that the number of fractals is x. The channel_split function is used to obtain the fractal size of matrix C as 16 × 8, and the number of fractals changes to 2x. Note that this parameter can be enabled only when the format of matrix C computed by Matmul is CubeFormat::NZ, the type is float, and the output is to the global memory. Values:
For For For For |
All templates |
|||
|
enableKdimReorderLoad |
Whether to enable staggered loading of data on the K axis. During Matmul computation based on the same tiling parameters, if the left or right matrices of multiple cores are the same and stored in the global memory, multiple cores may access the same address at the same time to load matrix data, causing access conflicts and affecting performance. After this parameter is enabled, during multi-core Matmul computation, the multiple cores try to access different global memory addresses at the same time to reduce the probability of address access conflicts and improve performance. This parameter is supported only for the MDL template. You are advised to enable this parameter when the K axis is large and the left and right matrices are not fully loaded. For details, see operator sample for staggered data loading along the K axis. Values:
For For For For |
MDL |
||
|
isCO1Shared |
Whether to enable the CO1 memory sharing. This parameter and sharedCO1BufferSize specify the number of blocks allocated to CO1. The number of data blocks cached in CO1 must not exceed that of blocks allocated to CO1, that is, the number of results computed by Iterate that are not obtained by GetTensorC must not exceed the number of blocks allocated to CO1. As this parameter is a global configuration, the parameter value for all Matmul objects must be the same. Values:
For the For the For the For the |
Norm and IBShare |
||
|
sharedCO1BufferSize |
Size of a shared buffer of CO1. The value is of the uint32_t type and can be 32*1024, 64*1024, or 128*1024. For the For the For the For |
Norm and IBShare |
||
|
bmmOutMode |
Reserved parameter |
Reserved parameter |
||
|
Whether to enable bank conflict optimization on L1. The Tiling module determines whether this parameter can be enabled by calling EnableL1BankConflictOptimise. Combined with TilingKey, the Kernel inserts the corresponding code path when this optimization is enabled. When this parameter is enabled, for MatMul operations using identical tiling parameters, the A and B matrices and the ScaleA and ScaleB matrices in MxMatmul scenarios are no longer allocated contiguously in L1 Buffer. In DoubleBuffer scenario, the data used for parallel computation is allocated in two separate regions of L1 Buffer: upper half and lower half. In non-DoubleBuffer scenario, data is allocated in the upper half of L1 Buffer. Bias is always allocated in the upper half of L1 Buffer. In vector quantization/dequantization scenarios, the quantization coefficients are allocated in the lower half of L1 Buffer. Values:
For For For For |
MDL |
|||
|
enableRelu |
Whether a ReLU (Rectified Linear Unit) activation function is applied to the output matrix C after the matrix multiplication is completed. After this function is enabled, the negative value in the output matrix is corrected to 0. Values:
For For For For |
All templates |