Overview

Fusion policies should consider the backend capabilities, performance benefits, and peak memory usage impacts to make decisions, perform fusion processing, and obtain a relatively optimal fusion result. The fusion policies can be used to implement the following functions:

  • Unified fusion rule judgment
  • Dynamic and static shapes (depending on Symbolization)
  • Fusion scale control
  • Fusion priority processing

The fusion policy module consists of the CanFuse framework and Backend.

  • CanFuse framework: supports fusion judgment (for loop detection and peak memory) and fusion policy solving.
  • Backend: supports fusion rules and fusion processing (loop fusion, AscGraph fusion, and AscBackend fusion).

The following figure shows the main interaction process.

Figure 1 Interaction between CanFuse and Backend

The fusion performed by the Lowering module is called primary fusion, and the fusion performed by the CanFuse framework is called secondary fusion. The secondary fusion process is as follows:

  1. Perform a round of fusion. By default, 10 rounds of fusion are performed.
  2. Obtain all node pairs that can be fused.
  3. Obtain the fusion priorities of the node pairs (determined in 2) that can be fused.
  4. Sort the fusion policies by priority and score.
  5. Call the CanFuse framework to determine the fusion pattern.
    1. Determine whether vertical fusion can be performed.

      Vertical fusion: There is an input/output relationship between two fusion nodes. The output of one node is the input of the other node.

    2. Analyze the impact of peak memory usage.
    3. Determine whether horizontal fusion can be performed.

      Horizontal fusion: There is no input/output relationship between two nodes, but there is an input from the same root node.

  6. Fuse the two nodes.