目录

TilingData Structure Definition

Function Description

Defines a TilingData class and adds required member variables (TilingData fields) to store required TilingData parameters. After the TilingData class is defined, it can inherit the TilingDef class (base class for storing and processing user-defined member variables of the Tiling structure) to provide the following APIs:

Function Prototype

Parameters

Table 1 BEGIN_TILING_DATA_DEF parameters

Parameter Input/Output Description
class_name Input Developer-defined tiling structure name, whose naming rule must be consistent with that of the C++ variable name.

Table 2 TILING_DATA_FIELD_DEF parameters

Parameter Input/Output Description
data_type Input Specifies the data type of the column.
field_name Input Field name, whose naming rule must be consistent with that of the C++ variable name.

Table 3 TILING_DATA_FIELD_DEF_ARR parameters

Parameter Input/Output Description
arr_type Input Data type of array elements.
arr_size Input Number of elements in the array
field_name Input Field name, whose naming rule must be consistent with that of the C++ variable name.

Table 4 TILING_DATA_FIELD_DEF_STRUCT parameters

Parameter Input/Output Description
struct_type Input Struct type.
field_name Input Field name, whose naming rule must be consistent with that of the C++ variable name.

Restrictions

Calling Example

#include "register/tilingdata_base.h"
 
// Define the TilingData class.
namespace optiling {
BEGIN_TILING_DATA_DEF(Matmul)
  TILING_DATA_FIELD_DEF(uint16_t, mmVar);
  TILING_DATA_FIELD_DEF_ARR(uint16_t, 3, mmArr);
END_TILING_DATA_DEF;
// Register an intermediate structure. The first parameter is fixed to struct_name#Op, and the second parameter is struct_name. For example, if struct_name is Matmul, the first parameter is MatmulOp and the second parameter is Matmul.
REGISTER_TILING_DATA_CLASS(MatmulOp, Matmul) // Register an intermediate structure.
 
BEGIN_TILING_DATA_DEF(AddCustomTilingData) // Register a tiling class and uses the tiling name as the input parameter.
  TILING_DATA_FIELD_DEF(uint32_t, blkDim); // Add a tiling field of the variable type to compute the number of cores.
  TILING_DATA_FIELD_DEF(uint32_t, totalSize); // Add a tiling field of the variable type to compute the total data size.
  TILING_DATA_FIELD_DEF(uint32_t, splitTile); // Add a tiling field of the variable type and compute data processed by each core by block.
  TILING_DATA_FIELD_DEF_ARR(uint16_t, 3, arrSample); // Add a tiling field of the array type.
  TILING_DATA_FIELD_DEF_STRUCT(Matmul, mm); // Add a tiling field of the structure type.
END_TILING_DATA_DEF; // Definition ends.
// Register the operator TilingData class with the corresponding AddCustom operator.
REGISTER_TILING_DATA_CLASS(AddCustom, AddCustomTilingData)
}
 
// Set parameter values and use tiling parameters on the host.
static void TilingAddInit(AddCustomTilingData *tiling, uint32_t blockDim)
{
  // Set parameter values.
  tiling->set_blkDim(blockDim); // Assign a value to the blockDim variable of a common data type.
  uint16_t arr[] = {10,2,8,2,3,4,5,2,1,2,4,4,5,};
  tiling->set_arrSample(arr); // Assign a value to the arrSample array variable of a common data type. Only the first three pieces of arr data are copied, which are the same as those in arr_size in TILING_DATA_FIELD_DEF_ARR.
  tiling->mm.set_mmVar(1); // Assign a value to the mmVar variable of a common data type in the nested structure.
  tiling->mm.set_mmArr(arr); // Assign a value to the mmArr array of a common data type in the nested structure.
   
  // Use the parameter values.
  uint32_t useBlockDim = tiling->get_blkDim(); // Obtain the blockDim variable of a common data type.
  uint32_t* arrPoint = tiling->get_arrSample(); // Obtain the arrSample array variable of a common data type.
  useBlockDim = tiling->mm.get_mmVar(); // Obtain the mmVar variable of a common data type in the nested structure.
  arrPoint = tiling->mm.get_mmArr(); // Obtain the mmArr array of the common data type in the nested structure.
}