SetShape

Function

Sets the shape m, n, k for Matmul computation. This shape can represent either the original full matrix or a local sub-matrix, with units measured in elements. The matrix multiplication defined by this shape can be executed by either a single core or multiple cores.

When this API is used, parameters can be transferred in either of the following ways:

  • Pass the shape m, n, k for Matmul computation. When GetTiling is called, the tiling parameters are calculated and returned based on m, n, and k.
  • If any of m, n, and k are set to -1, when GetTiling is called, the position will take the original shape M, N, K, or Ka/Kb defined in SetOrgShape. The API will then internally compute the optimal tiling parameters. As shown in the figure below, the original A matrix has a final column in the K direction that contains dirty data (not used in computation). In the SetOrgShape API, set the original shape including that column. In the SetShape API, set the actual K direction size for Matmul computation. At the same time, set both m and n to -1, which means the tiling will be calculated according to the original shape M and N.
Figure 1 Scenario where any of m, n, and k are set to -1

Prototype

1
int32_t SetShape(int32_t m, int32_t n, int32_t k)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

m

Input

Sets the size of the M dimension for Matmul computation, in elements.

n

Input

Sets the size of the N dimension for Matmul computation, in elements.

k

Input

Sets the size of the K dimension for Matmul computation, in elements.

Returns

-1: setting failed; 0: setting succeeded.

Restrictions

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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); // Set the shape for Matmul computation.
tiling.SetOrgShape(1024, 1024, 1024);   
tiling.SetBias(true);   
tiling.SetBufferSpace(-1, -1, -1);
optiling::TCubeTiling tilingData;   
int ret = tiling.GetTiling(tilingData);