Template Argument Definition

Function Usage

Defines the template argument declaration ASCENDC_TPL_ARGS_DECL and template argument selection ASCENDC_TPL_ARGS_SEL (available template). For details, see Tiling Template Programming.

Prototype

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// ParamStruct is a structure that stores the template argument declaration ASCENDC_TPL_ARGS_DECL and template argument selection ASCENDC_TPL_ARGS_SEL set by the user. It is used for subsequent encoding and decoding between the TilingKey and template arguments and can be ignored.
struct ParamStruct {
    const char* name;
    uint32_t paramType;
    uint8_t bitWidth;
    std::vector<uint64_t> vals;
    const char* macroType;
    ParamStruct(const char* inName, uint32_t inParamType, uint8_t inBitWidth, std::vector<uint64_t> inVals,
        const char* inMacroType):
        name(inName), paramType(inParamType), bitWidth(inBitWidth), vals(std::move(inVals)),
        macroType(inMacroType) {}
};
using TilingDeclareParams = std::vector<ParamStruct>;
using TilingSelectParams = std::vector<std::vector<ParamStruct>>;

// APIs for defining template arguments
#define ASCENDC_TPL_DTYPE_DECL(x, ...) ParamStruct{#x, ASCENDC_TPL_DTYPE, ASCENDC_TPL_8_BW, {__VA_ARGS__}, "DECL"}
#define ASCENDC_TPL_FORMAT_DECL(x, ...) ParamStruct{#x, ASCENDC_TPL_FORMAT, ASCENDC_TPL_8_BW, {__VA_ARGS__}, "DECL"}
#define ASCENDC_TPL_UINT_DECL(x, bw, ...) ParamStruct{#x, ASCENDC_TPL_UINT, bw, {__VA_ARGS__}, "DECL"}
#define ASCENDC_TPL_BOOL_DECL(x, ...) ParamStruct{#x, ASCENDC_TPL_BOOL, ASCENDC_TPL_1_BW, {__VA_ARGS__}, "DECL"}

#define ASCENDC_TPL_DTYPE_SEL(x, ...) ParamStruct{#x, ASCENDC_TPL_DTYPE, ASCENDC_TPL_8_BW, {__VA_ARGS__}, "SEL"}
#define ASCENDC_TPL_FORMAT_SEL(x, ...) ParamStruct{#x, ASCENDC_TPL_FORMAT, ASCENDC_TPL_8_BW, {__VA_ARGS__}, "SEL"}
#define ASCENDC_TPL_UINT_SEL(x, ...) ParamStruct{#x, ASCENDC_TPL_UINT, 0, {__VA_ARGS__}, "SEL"}
#define ASCENDC_TPL_BOOL_SEL(x, ...) ParamStruct{#x, ASCENDC_TPL_BOOL, ASCENDC_TPL_1_BW, {__VA_ARGS__}, "SEL"}

#define ASCENDC_TPL_ARGS_DECL(x, ...) static TilingDeclareParams g_tilingDeclareParams{ __VA_ARGS__ }
#define ASCENDC_TPL_ARGS_SEL(...) { __VA_ARGS__}
#define ASCENDC_TPL_SEL(...) static TilingSelectParams g_tilingSelectParams{ __VA_ARGS__ }

Arguments

Table 1 Arguments in the tiling template

Macro

Function

Description

ASCENDC_TPL_ARGS_DECL(args0, ...)

Overall template argument declaration of an operator.

  • args0: operator type.
  • args1-argsn: template argument definitions of DTYPE, FORMAT, UINT, and BOOL through ASCENDC_TPL_DTYPE_DECL, ASCENDC_TPL_FORMAT_DECL, ASCENDC_TPL_UINT_DECL, and ASCENDC_TPL_BOOL_DECL.

ASCENDC_TPL_DTYPE_DECL(args0, ...)

Template argument declaration of DataType.

  • args0: argument name.
  • args1-argsn: enumerated values of DataType.

ASCENDC_TPL_FORMAT_DECL(args0, ...)

Template argument declaration of Format.

  • args0: argument name.
  • args1-argsn: enumerated values of Format.

ASCENDC_TPL_UINT_DECL(args0, args1, args2, ...)

Template argument declaration of the unsigned integer (UINT) type.

  • args0: argument name.
  • args1: maximum bit width, which defines an upper limit for the number of template arguments.
  • args2: mode defined by an argument. The following three modes are supported:
    • ASCENDC_TPL_UI_RANGE: range mode. The first value indicates the number of ranges. Every two values following the first value are grouped indicating the start and end positions of the range. Note that the number of defined ranges must be the same as the number of subsequent groups.

      Example: ASCENDC_TPL_UINT_DECL(ASCENDC_TPL_UI_RANGE,2,0,2,3,5) indicates two groups of arguments. The ranges of the two groups of arguments are {0, 2} and {3, 5}. Therefore, the valid values for the UINT type defined by this argument are {0, 1, 2, 3, 4, 5}.

    • ASCENDC_TPL_UI_LIST: exhaustive mode. If this mode is set, all argument values will be listed.

      Example: ASCENDC_TPL_UINT_DECL(ASCENDC_TPL_UI_LIST,10,12,13,9,8,7,6) indicates a group of exhaustive arguments. [10, 12, 13, 9, 8, 7, 6] are exhaustive values. Therefore, the valid values for this argument are {10, 12, 13, 9, 8, 7, 6}.

    • ASCENDC_TPL_UI_MIX: mixed mode. If this mode is set, the first n values are the argument definitions of the range mode, and the last m values are the argument definitions of the exhaustive mode.

      Example:

      ASCENDC_TPL_UINT_DECL(ASCENDC_TPL_UI_MIX,2,0,2,3, 5, 10, 12, 13, 9, 8) indicates two groups of exhaustive arguments. The two groups are {0, 2} and {3, 5}. [10, 12, 13, 9, 8] are exhaustive values. Therefore, the valid values of UINT defined by this argument are {0, 1, 2, 3, 4, 5, 10, 12, 13, 9, 8}.

  • args3-argsn: argument values corresponding to different range modes.

ASCENDC_TPL_BOOL_DECL(args0, ...)

Template argument declaration of the bool type.

args0: argument name.

args1-args2: The value can be 0 or 1.

Table 2 Definition of tiling template argument selection

Macro

Function

Description

ASCENDC_TPL_SEL(...)

Overall template argument selection of an operator.

Template argument selection that contains multiple operators.

ASCENDC_TPL_ARGS_DSEL(...)

Template argument selection of an operator.

Template argument selection of an operator.

ASCENDC_TPL_DTYPE_SEL(args0, ...)

Template argument selection of DataType.

  • args0: argument name.
  • args1-argsn: subset of the argument ranges defined in ASCENDC_TPL_DTYPE_DECL.

ASCENDC_TPL_FORMAT_SEL(args0, ...)

Template argument selection of Format.

  • args0: argument name.
  • args1-argsn: subset of the argument ranges defined in ASCENDC_TPL_FORMAT_DECL.

ASCENDC_TPL_UINT_SEL(args0, args1, args2, ...)

Template argument selection of the UINT type.

  • args0: argument name.
  • args1: mode defined by an argument. The following values are supported:
    • ASCENDC_TPL_UI_RANGE: range mode.
    • ASCENDC_TPL_UI_LIST: exhaustive mode.
    • ASCENDC_TPL_UI_MIX: mixed mode.
  • args2-argsn: subset of the argument ranges defined in ASCENDC_TPL_UINT_DECL.

For details about how to configure the mode and arguments, see ASCENDC_TPL_UINT_DECL(args0, args1, args2, ...).

ASCENDC_TPL_BOOL_SEL(args0, ...)

Template argument selection of the bool type.

args0: argument name.

args1-args2: subset of the argument ranges defined in ASCENDC_TPL_BOOL_DECL.

Returns

None

Constraints

After the values of template arguments are modified or added, the custom operator package needs to be recompiled. The original operator binary files cannot be used.