Designing Fusion Patterns
The fusion pattern design should specify the fusion solution, fusion operator prototype, and fusion mapping relationship.
Designing the Fusion Solution
The following uses the many-to-one fusion pattern DecodeBboxV2ScopeFusionPass as an example to describe how to design and develop a scope fusion pattern.
This fusion pattern aims to fuse all small operators under Decode scope into a large operator DecodeBboxV2, as shown in Figure 1.
Specifying the Prototype of the Fused Operator
The prototype of the DecodeBboxV2 fused operator is as follows.
1 2 3 4 5 6 7 8 | REG_OP(DecodeBboxV2) .INPUT(boxes, TensorType({DT_FLOAT16,DT_FLOAT})) .INPUT(anchors, TensorType({DT_FLOAT16,DT_FLOAT})) .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT})) .ATTR(scales, ListFloat, {1.0, 1.0, 1.0, 1.0}) .ATTR(decode_clip, Float, 0.0) .ATTR(reversed_box, Bool, false) .OP_END_FACTORY_REG(DecodeBboxV2) |
For details about the operator prototype APIs, see "GE Namespace > Prototype Definition (REG_OP)" in Basic Data Structures and APIs.
Specifying the Fusion Relationship
As shown in Figure 1:
- Input 0 of transpose (corresponding to Cast_1 in the above figure) is input 0 (boxes) of DecodeBboxV2.
- Input 0 of get_center_coordinates_and_sizes_transpose (corresponding to Cast0 in the above figure) is input 1 (anchors) of DecodeBboxV2.
- The output of transpose_1 (corresponding to Cast_2 in the above figure) is used as output y of DecodeBboxV2.
Parent topic: Developing Fusion Patterns
