Lowering Process Example
This section uses a simple GE IR graph of Conv+Abs+Exp+Conv as an example (no lowering implementation for Conv) to describe the lowering process. The following figure shows the original GE IR graph.
- Conv lowering is performed first. Because no registered lowering is implemented for the Conv, the default lowering is performed. The KernelBoxes of all output anchors are of the ExternKernel type, indicating that the original GE IR kernel is to be executed.
Figure 2 Lowering of the input Conv
- Then, the input data is loaded during Abs lowering. The pseudocode is as follows:
1 2 3 4 5 6
graphStatus LoweringAbs(const ge::Node &node) { auto x = loop::Load(node.GetInDataAnchor(0)); // Load data from input anchor 0. ... auto result = loop::Abs(x); ... }
When loop::Load(node.GetInDataAnchor(0)) is executed, the Load method of the KernelBox associated with the output anchor of the peer end is called. In this case, the output is a Conv node. Because the KernelBox of the Conv node is of the Extern type, the load operation is equivalent to the load operation on the output anchor of the Conv node. Therefore, after lowering is performed for the Abs node, the output KernelBox associated with the anchor is as follows:
Figure 3 Lowering of Abs
- Then, lowering is performed on the Exp node. The pseudocode is as follows:
1 2 3 4 5 6
graphStatus LoweringExp(const ge::Node &node) { auto x = loop::Load(node.GetInDataAnchor(0)); // Load data from input anchor 0. ... auto result = loop::Exp(x); ... }
When Load is input, the load of the KernelBox associated with the anchor output by the Abs is executed. The Load type is not Realize or Extern (IsRealize is true, indicating that it can be fused; IsExternKernel is true, indicating that the original GE IR process is used) and can be fused. In this case, the internal computation process (load->Abs->Store) is returned. After Exp lowering, the KernelBox associated with the output anchor is as follows:
Figure 4 Exp lowering
- Finally, lowering is performed for the Conv node. The default lowering function is executed to perform the Realize operation for all KernelBoxes at the peer end of the input anchor. (The input is required because the Conv node needs to be rolled back to the original GE IR Kernel for execution.)
Figure 5 Lowering of the output Conv
After graph lowering is complete, it can be seen that the KernelBox requiring Realize is the KernelBox output by the Exp node. In this case, the KernelBox associated with the Anchor output by the Exp node is converted into an AscGraph, and the Exp node is replaced with one of the AscBackend type. Note that the input of the KernelBox associated with the Exp node is Conv:0 instead of the Abs node. Therefore, after the replacement, the Abs node is deleted because its output is no longer used by any node. However, to ensure that the original node can be easily rolled back at any time, the deletion of the useless node is not performed immediately.