A - Mobilint Tensor Scheduling (REGULUS) Editorial
by
lycoris1600
In this version, every tensor has size \(1\) MiB. Let \(L\) be the number of leaf nodes. Initially, exactly the input tensors are in memory, so the initial memory usage is \(L\) MiB.
When computing any result tensor, one new tensor of size \(1\) is allocated first, and then all child tensors are removed. If the node has \(d\) children, the memory usage after the computation changes by \(1-d \le 0\). Therefore, after a computation finishes, memory usage never increases. During the computation, the only possible extra peak is the newly allocated tensor, so the peak memory usage is always at most \(L+1\).
The first computation must allocate one result tensor while the current memory usage is still \(L\), so the peak memory usage is also at least \(L+1\). Hence the answer is always \(L+1\). Since \(L+1 \le N \le 5\,000 < 8\,192=M\), OOM never occurs. It is enough to count the leaves, so the total time complexity is \(O(N)\).
posted:
last update:
