DataTypeForBinQuery

Function

Sets the data type of the input/output for runtime operator binary lookup. The number of data types must be the same as that of DataType/DataTypeList and the data types must be in one-to-one mapping.

During operator building, multiple .o files are generated based on the data type, and the operator binary is indexed during running based on these 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.

For example, if the input of an operator supports multiple data types (ge::DT_INT16 and ge::DT_INT32), and when ge::DT_INT16 input is used, ge::DT_INT32 binary file 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 case, only one target file (.o) needs to be generated to support multiple data types.

Prototype

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

Parameters

Parameter

Input/Output

Description

types

Input

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

Returns

OpParamDef operator definition. For details, see OpParamDef.

Restrictions

  • The number of DataTypeForBinQuery parameters must be the same as that of DataType or DataTypeList parameters of the current operator.
  • This API cannot be used together with the To (specifying the data type) API.
  • Ensure that the new operator parameter attribute set (replacing the original DataType sequence with DataTypeForBinQuery) generated after DataTypeForBinQuery is used exists in the original supported parameter attribute set.

    The parameter attribute set is defined as the set of attributes of all parameters supported by an operator, which is equivalent to a set of parameters.

    For example, in Example 1: The operator supports four original sets without repetition.

    1. x: DT_FLOAT16, FORMAT_ND; y: DT_INT16, FORMAT_ND

    2. x: DT_FLOAT, FORMAT_ND; y: DT_INT16, FORMAT_ND

    3. x: DT_INT16, FORMAT_ND; y: DT_INT16, FORMAT_ND

    4. x: DT_INT32, FORMAT_ND; y: DT_INT16, FORMAT_NC

    After DataTypeForBinQuery is used to replace the original DataType sequence, the new set is as follows:

    1. x: DT_INT16, FORMAT_ND; y: DT_INT16, FORMAT_ND

    2. x: DT_FLOAT16, FORMAT_ND; y: DT_INT16, FORMAT_ND

    3. x: DT_FLOAT16, FORMAT_ND; y: DT_INT16, FORMAT_ND

    4. x: DT_INT16, FORMAT_ND; y: DT_INT16, FORMAT_NC

    In this case, the new set 1 is the same as the original set 3, and new set 2 and new set 3 are the same as the original set 1. The settings take effect. The new set 4 does not belong to any original set, and the settings are invalid. In this case, the new set 4 is built according to the original set 4.

Example

  • Example 1
    1
    2
    3
    4
    5
    6
    7
    8
    9
            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
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    // Simple case: Two pairs of cases are reused, that is, columns 1 and 2 -> column 1, and columns 3 and 4 -> column 4. Binary files 1 and 4 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_FLOAT16, ge::DT_FLOAT16, ge::DT_INT32, ge::DT_INT32})
                .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
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    // 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});