SetMatmulConfigParams

Function Usage

Sets the MatmulConfig parameters in Table 1 before the GetTiling API is called during tiling computation. The functions of parameters configured in this API must be the same in tiling and in the kernel. Therefore, the parameter settings in this API must be the same as the settings of the MatmulConfig parameters in the kernel. For details about the MatmulConfig parameters, see Table 2.

Prototype

1
void SetMatmulConfigParams(int32_t mmConfigTypeIn = 1, bool enableL1CacheUBIn = false, ScheduleType scheduleTypeIn = ScheduleType::INNER_PRODUCT, MatrixTraverse traverseIn = MatrixTraverse::NOSET, bool enVecND2NZIn = false)
1
void SetMatmulConfigParams(const MatmulConfigParams& configParams)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

mmConfigTypeIn

Input

Matmul template type, which must be the same as the template created by the Matmul object. Currently, the value can only be 0 or 1.

  • 0: indicates the Norm template
  • 1 (default): indicates the MDL template.

enableL1CacheUBIn

Input

Whether to cache UB computing blocks in L1. It can be enabled in scenarios where MTE3 and MTE2 serial pipelines are applied.

  • false (default): does not cache UB computing blocks in L1.
  • true: caches UB computing blocks in L1.

scheduleTypeIn

Input

Matmul data movement mode. Values:

  • ScheduleType::INNER_PRODUCT or 0 (default): performs MTE1 cyclic movement in the K direction.
  • ScheduleType::OUTER_PRODUCT or 1: performs MTE1 cyclic movement in the M or N direction.

traverseIn

Input

Cyclic iteration order for Matmul to perform matrix computation, that is, the order in which Matmul automatically offsets to the output position of Matrix C for the next iteration after a matrix C slice with the size of [baseM, baseN] is computed in one iteration. Values:

1
2
3
4
5
enum class MatrixTraverse{
    NOSET = 0,   // Invalid currently.
    FIRSTM,      // Offset to the M-axis direction and then to the N-axis direction.
    FIRSTN,      // Offset to the N-axis direction and then to the M-axis direction.
};

enVecND2NZIn

Input

Whether to enable ND2NZ.

configParams

Input

config parameter. It is of the MatmulConfigParams type. The structure is defined as follows: For details about the parameters, see Table 2.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
struct MatmulConfigParams
{
    int32_t mmConfigType;
    bool enableL1CacheUB;
    ScheduleType scheduleType;
    MatrixTraverse traverse;
    bool enVecND2NZ;
    MatmulConfigParams(int32_t mmConfigTypeIn = 1, bool enableL1CacheUBIn = false,
        ScheduleType scheduleTypeIn = ScheduleType::INNER_PRODUCT, MatrixTraverse traverseIn = MatrixTraverse::NOSET,
        bool enVecND2NZIn = false) {
        mmConfigType = mmConfigTypeIn;
        enableL1CacheUB = enableL1CacheUBIn;
        scheduleType = scheduleTypeIn;
        traverse = traverseIn;
        enVecND2NZ = enVecND2NZIn;
    }
};
Table 2 Parameters in the MatmulConfigParams structure

Parameter

Description

mmConfigType

Matmul template type, which must be the same as the template created by the Matmul object. Currently, the value can only be 0 or 1.

  • 0: indicates the Norm template
  • 1 (default): indicates the MDL template.

enableL1CacheUB

Whether to cache UB computing blocks in L1. It can be enabled in scenarios where MTE3 and MTE2 serial pipelines are applied.

  • false (default): does not cache UB computing blocks in L1.
  • true: caches UB computing blocks in L1.

scheduleType

Matmul data movement mode. Values:

  • ScheduleType::INNER_PRODUCT or 0 (default): performs MTE1 cyclic movement in the K direction.
  • ScheduleType::OUTER_PRODUCT or 1: performs MTE1 cyclic movement in the M or N direction.

traverse

Cyclic iteration order for Matmul to perform matrix computation, that is, the order in which Matmul automatically offsets to the output position of Matrix C for the next iteration after a matrix C slice with the size of [baseM, baseN] is computed in one iteration. Values:

1
2
3
4
5
enum class MatrixTraverse{
    NOSET = 0,   // Invalid currently.
    FIRSTM,      // Offset to the M-axis direction and then to the N-axis direction.
    FIRSTN,      // Offset to the N-axis direction and then to the M-axis direction.
};

enVecND2NZ

Whether to enable ND2NZ.

Returns

None

Precautions

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::MatmulApiTiling tiling(ascendcPlatform); 
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.SetOrgShape(1024, 1024, 1024);  
tiling.SetBias(true);   
tiling.SetBufferSpace(-1, -1, -1);
tiling.SetMatmulConfigParams(0);  // Additional settings
// tiling.SetMatmulConfigParams({1, false, ScheduleType::OUTER_PRODUCT, MatrixTraverse::FIRSTM});
optiling::TCubeTiling tilingData;   
int ret = tiling.GetTiling(tilingData);