AutoMappingByOpFn
Description
The callback function that implements automatic mapping.
Prototype
Status AutoMappingByOpFn(const ge::Operator &op_src, ge::Operator &op);
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
op_src |
Input |
Operator in the original model before conversion, including the attributes of the operator in the original model. |
op |
Input |
Operator that adapts to Ascend AI Processor. |
For details about class Operator, see Operator.
Example
The following describes the scenario where the attributes of the original TensorFlow operator are one-to-one mapped to those of the equivalent supported by Ascend AI Processor.
REGISTER_CUSTOM_OP("SoftplusGrad")
.FrameworkType(TENSORFLOW)
.OriginOpType("SoftplusGrad")
.ParseParamsByOperatorFn(AutoMappingByOpFn)
.ImplyType(ImplyType::TVM);
The following describes the scenario where the attributes of the original TensorFlow operator cannot be mapped to those of the equivalent supported by Ascend AI Processor.
Status ParseResizeArea(const ge::Operator &op_src, ge::Operator& op)
{
AutoMappingByOpFn(op_src, op);
ge::TensorDesc input_tensor = op.GetInputDesc("images");
input_tensor.SetOriginFormat(ge::FORMAT_NHWC);
input_tensor.SetFormat(ge::FORMAT_NHWC);
auto ret = op.UpdateInputDesc("images", input_tensor);
if(ret != ge::GRAPH_SUCCESS){
return FAILED;
}
ge::TensorDesc output_tensor = op.GetOutputDesc("y");
output_tensor.SetOriginFormat(ge::FORMAT_NHWC);
output_tensor.SetFormat(ge::FORMAT_NHWC);
auto ret_output = op.UpdateOutputDesc("y", output_tensor);
if(ret_output != ge::GRAPH_SUCCESS){
return FAILED;
}
return SUCCESS;
}
// register ResizeArea op to GE
REGISTER_CUSTOM_OP("ResizeArea")
.FrameworkType(TENSORFLOW)
.OriginOpType("ResizeArea")
.ParseParamsByOperatorFn(ParseResizeArea)
.ImplyType(ImplyType::AI_CPU);
Parent topic: OpRegistrationData