FormatList

Function Usage

Defines the operator parameter data formats. 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, this API can be used to define the data formats.

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.

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.

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 formats. For example:

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

OpParamDef &FormatList(std::vector<ge::Format> formats);

Parameters

Parameter

Input/Output

Description

formats

Input

Data formats of the operator parameter. For details about ge::Format, see Format.

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.

Example

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")
        ......
    }
};