SetCheckSupport
Function Usage
If you need to verify operator parameters during operator fusion, you can implement a callback function for operator parameter verification and register it by calling this API. In addition, set NeedCheckSupportFlag to true, so that the registered operator parameter verification function can be called to verify related information during operator build and fusion.
If specific operator parameters pass the verification, it means that the AI Core supports these operator parameters and will select the corresponding operator on the AI Core for execution; otherwise, it will continue to query the AI CPU operator package and then execute found operators.
Prototype
OpAICoreDef &SetCheckSupport(optiling::OP_CHECK_FUNC func);
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
func |
Input |
Parameter verification function. The OP_CHECK_FUNC type is defined as follows: using OP_CHECK_FUNC = ge::graphStatus (*)(const ge::Operator &op, ge::AscendString &result); The input parameters of this function are operator descriptions, including the operator inputs, outputs, and properties. The output parameters are character strings that contain the verification return codes and reasons. The format of the character string is as follows: {"ret_code": "1","reason": "your reason"}
If the verification is successful, the function returns ge::GRAPH_SUCCESS. If the verification fails, the function returns ge::GRAPH_FAILED. |
Returns
For details about OpAICoreDef, see OpAICoreDef.
Constraints
None
Example
The following provides examples of implementing and registering the parameter verification function of the customized Add operator.
- Implementation of the parameter verification function: Verify the shape of the first input parameter. The first dimension of the input x's shape can only be 8. Other situations are not supported.
static ge::graphStatus CheckSupported(const ge::Operator &op, ge::AscendString &result) { std::string resultJsonStr; // The first dimension of the first input parameter's shape can only be 8. Other shapes are not supported. if (op.GetInputDesc(0).GetShape().GetDim(0) == 8) { resultJsonStr = R"({"ret_code": "1","reason": "x.dim[0] is 8"})"; result = ge::AscendString(resultJsonStr.c_str()); return ge::GRAPH_SUCCESS; } resultJsonStr = R"({"ret_code": "0","reason": "xxx"})"; result = ge::AscendString(resultJsonStr.c_str()); return ge::GRAPH_FAILED; } - An example of registering the parameter verification function is as follows:
class AddCustom : public OpDef { public: AddCustom(const char* name) : OpDef(name) { this->Input("x") .ParamType(REQUIRED); this->Input("y") .ParamType(REQUIRED); this->Output("z") .ParamType(REQUIRED); this->SetInferShape(ge::InferShape); this->AICore() .SetTiling(optiling::TilingFunc) .SetTilingParse(optiling::TilingPrepare) .SetOpSelectFormat(optiling::OpSelectFormat) .SetCheckSupport(optiling::CheckSupported); OpAICoreConfig aicConfig; aicConfig.DynamicCompileStaticFlag(true) .DynamicFormatFlag(true) .DynamicRankSupportFlag(true) .DynamicShapeSupportFlag(true) .NeedCheckSupportFlag(true) .PrecisionReduceFlag(true); // Note: Replace soc_version with the actual AI processor version. this->AICore().AddConfig("soc_version", aicConfig); } };