Prototype Definition (REG_OP)
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Header File
#include <graph/operator_reg.h>
Function Usage
Defines the operator prototype, including inputs, outputs, attributes, and the corresponding data types.
After an operator prototype is defined, the prototype is registered with the GE, including the inputs, outputs, and attributes of the operators. In addition, class op::xxx is defined. You can include the prototype header file and instantiate the class to build the IR model as follows:
1 2 3 |
conv = op::Conv2D() conv.set_input_x(feature_map_data) conv.set_input_filter(weight_data) |
For details about how to build a model, see Graph Development.
Prototype
An example of defining the function prototype is as follows:
1 2 3 4 5 6 7 8 9 10 11 |
REG_OP(xxx) .INPUT(x1, type) .OPTIONAL_INPUT(x2, type) .DYNAMIC_INPUT(x3, type) .OUTPUT(y1, type) .DYNAMIC_OUTPUT(y3, type) .REQUIRED_ATTR(a, type) .ATTR(b, type, default_value) .GRAPH(z1) .DYNAMIC_GRAPH(z2) .OP_END_FACTORY_REG(xxx) |
API Description
The OpReg &N() API in class OpReg is used to make OpReg calls, such as .INPUT(x, type) and .OUTPUT(x, type), in .** mode during operator registration.
Returns
None
Restrictions
- The operator type passed to the REG_OP call must be globally unique.
- The inputs of an operator must have unique names.
- The outputs of an operator must have unique names.
- The attributes of an operator must have unique names.
Call Examples and Related APIs
The following is an example of defining a dynamic-input operator prototype.
1 2 3 4 5 |
REG_OP(AddN) .DYNAMIC_INPUT(x, TensorType({NumberType(), DT_VARIANT})) .OUTPUT(y, TensorType({NumberType(), DT_VARIANT})) .REQUIRED_ATTR(N, Int) .OP_END_FACTORY_REG(AddN) |
The following is an example of defining a multi-input operator prototype.
1 2 3 4 5 |
REG_OP(GreaterEqual) .INPUT(x1, TensorType::RealNumberType()) .INPUT(x2, TensorType::RealNumberType()) .OUTPUT(y, TensorType({DT_BOOL})) .OP_END_FACTORY_REG(GreaterEqual) |
The following is an example of defining the operator prototype for subgraph registration.
1 2 3 4 5 6 7 |
REG_OP(If) .INPUT(cond, TensorType::ALL()) .DYNAMIC_INPUT(input, TensorType::ALL()) .DYNAMIC_OUTPUT(output, TensorType::ALL()) .GRAPH(then_branch) .GRAPH(else_branch) .OP_END_FACTORY_REG(If) |