FormatList
Function
Defines the operator parameter data format. If the data format supported by an input/output can be used together with the data types and data formats supported by all other inputs/outputs, this interface can be used to define the data format.
When Format is used to configure data formats, these data formats 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 format of input x and y is FORMAT_NHWC, the data format of the corresponding output z is also FORMAT_NHWC, and the data type of x, y, and z must be ge::DT_FLOAT.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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_NHWC, ge::FORMAT_ND}); this->Input("y") .ParamType(REQUIRED) .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32}) .Format({ge::FORMAT_ND, ge::FORMAT_NHWC, ge::FORMAT_ND}); this->Output("z") .ParamType(REQUIRED) .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32}) .Format({ge::FORMAT_ND, ge::FORMAT_NHWC, ge::FORMAT_ND}); ... } }; |
If the data formats supported by an input/output can be used in combination with the data types and formats supported by all other inputs/outputs, the Format API must be written in the following format, indicating that when input x is of type FORMAT_ND, all data type and format combinations of input y and input z are supported.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 FormatList to specify the data type. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class XxxCustom : public OpDef { public: XxxCustom(const char* name) : OpDef(name) { this->Input("x") .ParamType(REQUIRED) .DataTypeList({ge::DT_FLOAT16}) .FormatList({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
1
|
OpParamDef &FormatList(std::vector<ge::Format> formats) |
Parameters
Returns
OpParamDef operator definition. For details, see OpParamDef.
Constraints
- Format and FormatList cannot be set for the same input or output at the same time.
- This API cannot be used together with UnknownShapeFormat.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 |
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}) .FormatList({ge::FORMAT_ND}); this->Input("x1") ...... } }; |