Poplar and PopLibs
|
A program to mark a tensor as containing an undefined value. More...
#include <Program.hpp>
A program to mark a tensor as containing an undefined value.
This can be used to improve the liveness analysis of tensors and save memory in some situations.
Poplar does liveness analysis using the standard algorithm, except that Poplar's variables are not scalar values; they are arrays (tensors). In the standard analysis, a variable is "killed" when it is written to with a new value. This means that it is dead immediately before that point because its value there can never be read.
In Poplar, a variable is killed when all of its elements are written in the same compute set. Consider the pseudo-code:
If only some of the elements are written then the entire variable is still live before the write because we may still need the values of the elements that were not written to.
var
is still alive because no compute set writes to every element. If the entire variable is overwritten but in separate compute sets, then it will still be considered to be live because Poplar does not track the liveness of each variable element, only the entire variable.
This means var
is alive more than necessary which may lead to increased memory use. One solution is for Poplar to track the liveness of every variable element separately, but that would be prohibitively expensive.
Instead, this program provides a way to manually mark a tensor as being dead by writing an undefined value to it. Changing the above code to the following results in the correct liveness.
For more information about liveness analysis see https://en.wikipedia.org/wiki/Live_variable_analysis and https://www.cl.cam.ac.uk/teaching/2006/OptComp/slides/lecture03.pdf
t | The tensor to mark as undefined. |
debugContext | Optional DebugId and program name. |