DataTypeList
Function Usage
Defines the operator parameter data types. If the data types supported by an input/output can be used in combination with the data types and formats supported by all other inputs/outputs, this API can be used to define the data types.
When DataType is used to configure data types, these data types are in one-to-one mapping with the data types and formats of other inputs and outputs. As shown in the following example, if the data type of input x and y is DT_FLOAT16, the data type of the corresponding output z is also DT_FLOAT16, and the supported data format must be FORMAT_ND.
class AddCustom : public OpDef {
public:
AddCustom(const char* name) : OpDef(name)
{
this->Input("x")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
this->Input("y")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
this->Output("z")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
...
}
};If the data types supported by an input/output can be used in combination with the data types and formats supported by all other inputs/outputs, the DataType API must be written in the following format, indicating that when input x is of type DT_FLOAT16, all data type and format combinations of input y and input z are supported.
class XxxCustom : public OpDef {
public:
XxxCustom(const char* name) : OpDef(name)
{
this->Input("x")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT16, ge::DT_FLOAT16})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
this->Input("y")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
this->Output("z")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
...
}
};In this case, you can use DataTypeList to specify the data types. For example:
class XxxCustom : public OpDef {
public:
XxxCustom(const char* name) : OpDef(name)
{
this->Input("x")
.ParamType(REQUIRED)
.DataTypeList({ge::DT_FLOAT16})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
this->Input("y")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
this->Output("z")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
...
}
};
Prototype
OpParamDef &DataTypeList(std::vector<ge::DataType> types);
Parameters
Returns
OpParamDef operator definition. For details, see OpParamDef.
Constraints
- DataType and DataTypeList cannot be set for the same input or output at the same time.
- This API cannot be used together with UnknownShapeFormat.
Example
class AddCustom : public OpDef {
public:
AddCustom(const char* name) : OpDef(name)
{
this->Input("x")
.ParamType(REQUIRED)
.DataTypeList({ge::DT_FLOAT})
.Format({ge::FORMAT_ND, ge::FORMAT_NCHW});
this->Input("x1")
......
}
};