Documentation
¶
Overview ¶
Package concatwrite registers the (producer-Conv → Concat) tail fusion. Import the package for its side effect to enable the pass.
import _ "github.com/0verkilll/onnx/graph/fusion/concatwrite"
Order: this fusion's eligibility list includes "ConvLeakyRelu" and "ConvPRelu" as producer op types, so when those fusions are also enabled they must be registered before concatwrite. Go init() order matches package import order, so importing fusion/convleakyrelu and fusion/convprelu BEFORE concatwrite is sufficient.
Index ¶
Constants ¶
const FusionName = "concatwrite"
FusionName is the registry key under which Apply is filed.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply rewrites the graph in place, collapsing every (producer-Conv → Concat) tail pair where the producer's output is the LAST input of the Concat AND has exactly one consumer (the Concat itself) into a single fused "ConcatFusedTail" node. The fused node allocates the joint output buffer once, copies all prefix inputs into the head of that buffer with the same block-copy ordering Concat uses, and dispatches the producer Conv kernel to write its output directly into the tail slice — eliminating the producer's standalone output materialisation AND the corresponding memcpy that an unfused Concat would perform on that tail slice.
Why "tail-only" rather than full N-producer fusion? In Real-ESRGAN's RDB dense-connection pattern (276 Concat ops out of 1094 total nodes post other-fusion), each Concat reads K producers of which only the LAST is freshly produced and single-consumer; the K-1 earlier producers are tensors reused across multiple downstream Concats. They cannot be folded into the fused buffer (folding would require a separate dedicated buffer per consumer), but the latest one — the dense-block's just-emitted feature map — is always single-use and is the largest-payload candidate for write fusion. Empirically the pass folds ~276 Concats on Real-ESRGAN x4 (one per Concat in the dense blocks), 0 on realesr-general-x4v3 (no Concats), and 0 on SPAN.
Eligibility constraints (verified for every candidate before fusing):
- The Concat node has axis == 1 (the channel axis in NCHW).
- The Concat node has at least 2 inputs.
- The Concat's LAST input is produced by a node N whose OpType is one of "Conv", "ConvLeakyRelu", "ConvPRelu" — the operators whose Execute methods take their output buffer from the supplied allocator.
- Producer N's output is consumed exactly once in the entire graph.
- Producer N appears immediately before the Concat in topological order.
Apply returns the number of Concat nodes that were rewritten.
Types ¶
This section is empty.