Iterate through each Op, and determine if the input tensor of the Op is
in rec_tbl, if yes, then determine if ref_cnt >= 1, if still yes, ref_cnt
–. This operation means that the number of references to the input
tensor is reduced by one.
If ref_cnt is equal to 0, it means that the life cycle of the tensor is over, and later tensors can reuse its address space.
When allocating the output tensor to each Op, we first check whether
the EOL tensor address can be reused. In other words, the rec_tbl must
meet the following 5 conditions before it can be reused:
The corresponding tensor is not in the hold_edges.
The address of the corresponding tensor is not in_using_addr
The corresponding tensor is already EOL.
The address space of the corresponding tensor >= the space required by the current tensor.
The address of the input tensor of the current Op is different from the address of the corresponding tensor (e.g., the final result of some Op operations is incorrect, except for reshapeOp).
Allocate GMEM to the output tensor of the current Op. Reuse it if step2 shows that it can be reused. Otherwise, open a new GMEM in ddr.
Adjust the lifecycle of the current Op’s input tensor and check if it is in hold_edges. If yes, look in rec_tbl and check if its ref_cnt is 0. If yes, remove it from hold_edges as well as its addr from in_using_addr. This operation means that the input tensor has finished its life cycle and the address space has been released.