---
title: 融合规则设计
description: "融合规则设计包括明确融合方案、明确融合算子原型和明确融合对应关系。"
url: https://www.hiascend.com/document/detail/zh/TensorFlowCommunity/latest/Convergence/tfscopedevg/atlastfscopedev_11_0011.html
sourcePath: /source/zh/TensorFlowCommunity/910/Convergence/tfscopedevg/atlastfscopedev_11_0011.html
indexId: 6b3d9ba6c986737f9a126ff94f54cd6b3cb32e65a533c6261270ee02ff275ad287
---
# 融合规则设计

融合规则设计包括明确融合方案、明确融合算子原型和明确融合对应关系。


#### 明确融合方案

下面以多对一融合规则DecodeBboxV2ScopeFusionPass为例介绍如何设计和开发Scope融合规则。

该融合规则的目标是把Decode scope下的所有小算子融合为一个大算子DecodeBboxV2，如图1所示。

图1 融合示意图


#### 明确融合算子原型

DecodeBboxV2融合算子原型为：

```
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)
```

算子原型API可以参考《TBE&AI CPU算子开发(https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/910/others/tbeaicpudevg/atlasopdev_10_0001.html)》中的“接口参考>基础数据结构与接口>ge命名空间>原型定义接口（REG_OP）”。


#### 明确融合对应关系

如图1所示，

- transpose的第0个输入（对应上图中的Cast_1）为DecodeBboxV2的第0个输入boxes；
- get_center_coordinates_and_sizes_transpose的第0个输入（对应上图中的Cast0）为DecodeBboxV2的第1个输入anchors；
- transpose_1的输出（对应上图中的Cast_2）作为DecodeBboxV2的输出y。
