Template Argument Declaration
Function
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 30 31 32 33 34 35 |
// 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_DATATYPE_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_KERNEL_TYPE_DECL(x, ...) ParamStruct{#x, ASCENDC_TPL_SHARED_KERNEL_TYPE, ASCENDC_TPL_8_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_DATATYPE_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_KERNEL_TYPE_SEL(...) ParamStruct{"kernel_type", ASCENDC_TPL_KERNEL_TYPE, ASCENDC_TPL_8_BW, {__VA_ARGS__}, "SEL"} #define ASCENDC_TPL_DETERMINISTIC_SEL(...) ParamStruct{"deterministic", ASCENDC_TPL_DETERMINISTIC, ASCENDC_TPL_1_BW, {__VA_ARGS__}, "SEL"} #define ASCENDC_TPL_SHARED_KERNEL_TYPE_SEL(x, ...) ParamStruct{#x, ASCENDC_TPL_SHARED_KERNEL_TYPE, ASCENDC_TPL_8_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__ } |
Parameters
|
Macro |
Function |
Description |
|---|---|---|
|
ASCENDC_TPL_SEL(...) |
Overall template argument selection of an operator. |
Template argument selection that contains multiple operators. |
|
ASCENDC_TPL_ARGS_SEL(...) |
Template argument selection of an operator. |
Template argument selection of an operator. |
|
ASCENDC_TPL_KERNEL_TYPE_SEL(args0) |
Sets the kernel type of the operator template parameter combination. However, this parameter cannot be passed as a template parameter of the kernel function. |
args0: kernel type of the operator in the template parameter combination. If this parameter is not specified, the automatic derivation process is used. For all operators under ASCENDC_TPL_SEL, the kernel type must be the same. Currently, the following kernel types are supported:
|
|
ASCENDC_TPL_DTYPE_SEL(args0, ...) |
Customized template parameter combination of the DataType type. |
|
|
ASCENDC_TPL_DATATYPE_SEL(args0, ...) |
Template parameter combination of the native DataType type |
|
|
ASCENDC_TPL_FORMAT_SEL(args0, ...) |
Template argument selection of Format. |
|
|
ASCENDC_TPL_UINT_SEL(args0, args1, args2, ...) |
Template argument selection of the UINT type. |
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. |
|
ASCENDC_TPL_DETERMINISTIC_SEL(args0) |
This template parameter combination is used to configure whether to enable deterministic computing. |
args0: indicates the parameter name. The value can be true, false, 1, or 0. [true/1] indicates that deterministic computing is enabled for the template parameter combination, and [false/0] indicates that deterministic computing is disabled. Note that this value is not used as the input parameter of the operator template. When this value is enabled for compilation, -DDETERMINISTIC_MODE=1 is added, and a JSON file and an .o file ending with _deterministic are generated, for example, "AddCustomTemplate_816f04e052850554f4b3cacb35f8e8c6_deterministic.json"/"AddCustomTemplate_816f04e052850554f4b3cacb35f8e8c6_deterministic.o". Note: If the deterministic computing version is compiled using the ASCENDC_TPL_DETERMINISTIC_SEL(true) API, the deterministic computing switch needs to be turned on during operator calling. For example, when the aclnn single-operator is called, the aclrtCtxSetSysParamOpt API needs to be used to perform related configurations. This parameter is supported only by the following models:
|
|
ASCENDC_TPL_SHARED_KERNEL_TYPE_SEL(args0, ...) |
Sets the kernel type of the operator template parameter combination. This parameter can be transferred as the template parameter of the kernel function. |
args0: argument name. args1-argsn: kernel type of the operator in the template parameter combination. The subsequent parameters are several kernel types. This API cannot be used together with the ASCENDC_TPL_KERNEL_TYPE_SEL API. If the KERNEL_TASK_TYPE_DEFAULT(value) API is also used, this API has a higher priority. |
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.