DataTypeList
Function
Defines the operator parameter data type. If the data type supported by an input/output can be used together with the data types and data formats supported by all other inputs/outputs, this API can be used to define the data type.
When DataType is used to configure the data type, the data type and format of the operator parameter must be explicitly combined for configuration. Each combination contains the complete mapping between the input/output data type and the data format. In the following example, when the data types of the inputs x and y are DT_FLOAT16, the data type of the output z is also DT_FLOAT16, and the supported data format is FORMAT_ND.
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_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.
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 DataTypeList 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}) .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
1
|
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.
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) .DataTypeList({ge::DT_FLOAT}) .Format({ge::FORMAT_ND, ge::FORMAT_NCHW}); this->Input("x1") ...... } }; |