GetMMConfig
Applicability
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
|
|
x |
|
|
x |
Function
Allows to flexibly customize Matmul template parameters. You can set MatmulConfigMode, MatmulShapeParams, MatmulQuantParams, MatmulBatchParams, and MatmulFuncParams to obtain the custom MatmulConfig templates.
MatmulConfigMode specifies the MatmulConfig templates to be obtained and modified. For details about each template, see Table 1. You can modify the parameters of the MatmulConfig templates by setting one or more variable parameters, that is, MatmulShapeParams, MatmulQuantParams, MatmulBatchParams and MatmulFuncParams in any sequence. Compared with the GetNormalConfig and GetMDLConfig APIs used to obtain templates, this API provides a more flexible way to customize Matmul template parameters.
Prototype
1 2 |
template <MatmulConfigMode configMode, typename... ArgTypes> __aicore__ inline constexpr MatmulConfig GetMMConfig(ArgTypes&&... args) |
Parameters
|
Parameter |
Description |
|---|---|
|
configMode |
Obtained MatmulConfig template |
|
ArgTypes |
Variable template parameter |
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
args |
Input |
Variable parameter that can be configured by importing one or more of MatmulShapeParams, MatmulQuantParams, MatmulBatchParams and MatmulFuncParams as needed in any sequence. |
|
Parameter |
Description |
|---|---|
|
CONFIG_NORM |
Sets MatmulConfig to the Norm template by default. |
|
CONFIG_MDL |
Sets MatmulConfig to the MDL template by default. |
|
CONFIG_SPECIALMDL |
Sets MatmulConfig to the SpecialMDL template by default. |
|
CONFIG_IBSHARE |
Sets MatmulConfig to the IBShare template by default. |
|
Parameter |
Data Type |
Description |
|---|---|---|
|
singleCoreM |
uint32_t |
Shape size of a single core on the M axis, in elements. |
|
singleCoreN |
uint32_t |
Shape size of a single core in the N axis, in elements. |
|
singleCoreK |
uint32_t |
Shape size of a single core in the K axis, in elements. |
|
basicM |
uint32_t |
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. |
|
basicN |
uint32_t |
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. |
|
basicK |
uint32_t |
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. |
|
Parameter |
Data Type |
Description |
|---|---|---|
|
isPerTensor |
bool |
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.
|
|
hasAntiQuantOffset |
bool |
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. |
|
Parameter |
Data Type |
Description |
|---|---|---|
|
isNBatch |
bool |
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:
|
|
batchMode |
BatchMode |
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:
|
|
isBiasBatch |
bool |
Whether the bias size includes batch axes in the BatchMatmul scenario. Values:
|
|
bmmOutMode |
BatchOutMode |
Reserved parameter |
|
Parameter |
Data Type |
Description |
||
|---|---|---|---|---|
|
intrinsicsLimit |
bool |
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:
|
||
|
enVecND2NZ |
bool |
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 |
||
|
enableDoubleCache |
bool |
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. |
||
|
enableL1CacheUB |
bool |
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 |
||
|
doMTE2Preload |
uint32_t |
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. |
||
|
iterateOrder |
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 |
||
|
scheduleType |
ScheduleType |
Matmul data movement mode. Values:
Note:
For For For For |
||
|
enableReuse |
bool |
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:
|
||
|
enableUBReuse |
bool |
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 |
||
|
isPartialOutput |
bool |
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 |
||
|
isA2B2Shared |
bool |
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 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. |
||
|
isEnableChannelSplit |
bool |
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:
|
||
|
enableKdimReorderLoad |
bool |
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 |
Returns
Restrictions
None
Examples
1 2 3 4 5 6 7 8 9 10 11 |
// Obtain the MatmulConfig template and set it as the Norm template. constexpr static MatmulConfigMode configMode = MatmulConfigMode::CONFIG_NORM; // singleCoreM, singleCoreN, singleCoreK, basicM, basicN, and basicK constexpr static MatmulShapeParams shapeParams = {128, 128, 128, 64, 64, 64}; // Conduct quantization for matrix B per channel without using the offset coefficient. constexpr static MatmulQuantParams quantParams = {false, false}; // Disable the multi-batch parameters. constexpr static MatmulBatchParams batchParams{false}; // Disable the verification for the address offset for chip instruction movement, and enable ND2NZ using vector. constexpr static MatmulFuncParams funcParams{false, true}; constexpr static MatmulConfig mmConfig = GetMMConfig<configMode>(shapeParams, quantParams, batchParams, funcParams); |