DataTypeForBinQuery

Function Usage

Sets the data types to be queried by an operator binary file through Input and Output. The number of data types must be the same as that of DataType or DataTypeList in one-to-one mapping.

During operator build, multiple .o files are generated and the operator binary files are indexed during running based on the data types. Some operators support multiple data types and are insensitive to data types. In this case, you can use this API to map multiple data types to the same operator binary file. Multiple data types can reuse one .o file, reducing the number of binary files generated.

Assume that the input of an operator supports multiple data types (ge::DT_INT16 and ge::DT_INT32). If ge::DT_INT16 input is used and the binary file of ge::DT_INT32 can be reused without affecting the final result, the following configuration can be used:

1
2
3
4
5
this->Input("x")
    .ParamType(REQUIRED)
    .DataType({ge::DT_INT16, ge::DT_INT32})
    .DataTypeForBinQuery({ge::DT_INT32, ge::DT_INT32})
    .Format({ge::FORMAT_ND, ge::FORMAT_ND});

In this way, only one target file (.o) needs to be generated to support multiple data types.

Prototype

OpParamDef &DataTypeForBinQuery(std::vector<ge::DataType> types);

Parameters

Parameter

Input/Output

Description

types

Input

Data types of the operator parameter. For details about ge::DataType, see DataType.

Returns

OpParamDef operator definition. For details, see OpParamDef.

Constraints

  • The length of DataTypeForBinQuery must be the same as that of DataType or DataTypeList.
  • This API cannot be used together with the To (specifying the data type) API.
  • After DataTypeForBinQuery is set, its data types are used to replace the current Input and Output data types. You can check whether a new combination exists before the replacement. If a new combination exists, it points to the corresponding binary file. If a new combination does not exist, DataTypeForBinQuery is invalid and the binary file is generated based on the original data types. For details, see Example 1.

Example

  • Example 1
            this->Input("x")
                .ParamType(REQUIRED)
                .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT16, ge::DT_INT32})
                .DataTypeForBinQuery({ge::DT_INT16, ge::DT_FLOAT16, ge::DT_FLOAT16, ge::DT_INT16})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
            this->Output("y")
                .ParamType(REQUIRED)
                .DataType({ge::DT_INT16, ge::DT_INT16, ge::DT_INT16, ge::DT_INT16})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_NC});

    As shown in the following figure, four binary files are generated before DataTypeForBinQuery is set. After DataTypeForBinQuery is set using the preceding code:

    • After the replacement, the first column uses the binary file of the third column, and the second and third columns use the binary file of the first column. The fourth column still uses its own binary file.
    • After the replacement, the second and third columns are the same so that the binary files are reused. The total operator binary files are reduced from four (bin1, bin2, bin3, and bin4) to three (bin1, bin3, and bin4).

  • Example 2
    // Simple case: Two pairs of cases are reused, that is, columns 1 and 4 -> column 3, and columns 2 and 3 -> column 1. Binary files 1 and 3 are generated in total. All supported data types are passed to the two binary files for running.
            this->Input("x")
                .ParamType(REQUIRED)
                .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT16, ge::DT_INT32})
                .DataTypeForBinQuery({ge::DT_INT16, ge::DT_FLOAT16, ge::DT_FLOAT16, ge::DT_INT16})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
            this->Output("y")
                .ParamType(REQUIRED)
                .DataType({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
  • Example 3
    // Complex case: Multiple inputs and outputs can use DataTypeForBinQuery at the same time. In this case, two pairs of inputs and outputs are reused, that is, columns 1 and 2 -> column 2; columns 3 and 4 -> column 1. Binary files 1 and 2 are generated in total. All supported data types are passed to the two binary files for running.
            this->Input("x")
                .ParamType(REQUIRED)
                .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT16, ge::DT_INT32})
                .DataTypeForBinQuery({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_FLOAT16})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
            this->Input("y")
                .ParamType(REQUIRED)
                .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32, ge::DT_INT16})
                .DataTypeForBinQuery({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_FLOAT16})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
            this->Output("z")
                .ParamType(REQUIRED)
                .DataType({ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_INT32, ge::DT_INT16})
                .DataTypeForBinQuery({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_FLOAT16})
                .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});