AutoMappingFnDynamic

Description

The callback function that implements automatic mapping of the dynamic input/output operator.

Prototype

Status AutoMappingFnDynamic(const google::protobuf::Message *op_src, ge::Operator &op, std::map<std::string, std::pair<std::string, std::string>> dynamic_name_attr_value, int32_t in_pos = -1, int32_t out_pos = -1)

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.

dynamic_name_attr_value

Input

Actual number of dynamic inputs or outputs. key specifies whether they are inputs or outputs. The values of key are as follows:

  • in: operator input.
  • out: operator output.

in_pos

Input

Port ID for the dynamic input.

out_pos

Input

Port ID for the dynamic output.

Restrictions

If the attributes of the original TensorFlow operator are inconsistent with those of operators supported by Ascend AI Processor, the AutoMappingFnDynamic function cannot be used in the callback function ParseParamsByOperatorFn. In this case, use the AutoMappingByOpFnDynamic API in ParseParamsByOperatorFn to automatically parse the attributes that can be mapped. For usage examples, see Example.

Sample Code

A code example of dynamic input is as follows.

// register MapStage op to GE
Status MapStageMapping(const google::protobuf::Message* op_src, ge::Operator& op) {
  map<string, pair<string, string>> value;
  value["in"] = pair<string, string>("values", "fake_dtypes");
  AutoMappingFnDynamic(op_src, op, value);
  return SUCCESS;
}

REGISTER_CUSTOM_OP("MapStage")
    .FrameworkType(TENSORFLOW)
    .OriginOpType("MapStage")
    .ParseParamsFn(MapStageMapping)
    .ImplyType(ImplyType::AI_CPU);

A code example of dynamic output is as follows.

Status AutoMappingFnSplit(const google::protobuf::Message* op_src, ge::Operator& op) {
  map<string, pair<string, string>> value;
  value["out"] = pair<string, string>("y", "num_split");
  AutoMappingFnDynamic(op_src, op, value);
  return SUCCESS;
}

REGISTER_CUSTOM_OP("Split")
    .FrameworkType(TENSORFLOW)
    .OriginOpType("Split")
    .ParseParamsFn(AutoMappingFnSplit)
    .ImplyType(ImplyType::TVM);