devito
devito copied to clipboard
Temporary variables name in generated code is unordered
This is due to the way the DSE works at the moment -- detecting and hoisting expressions in a greedy fashion as a sequence of steps.
Eg:
a = <expr>
--> first pass
r0 = ...
r1 = ...
a = ... <expr accessing r0,r1> ...
--> second pass: now extracts more temporaries out of r0
and r1
r2 = ...
r3 = ...
r0 = ... <accesses r2/r3> ...
r1 = ... <accesses r2/r3> ...
a = ... <expr accessing r0,r1> ...
To fix (mitigate) this, we need two things:
- lazy evaluation of expression, or decoration of expressions so that we know where derivatives are
- rewrite parts of the DSE so that derivatives are hoisted all at once, and thus assigned incremental temporaries
- generic CSE will still be needed though (hence the "mitigate" above)
Note: introducing a final "cleanup" DSE pass which simply renames the temporaries based on the final ordering is not only horrible, but also challenging due to Arrays with different access functions (a[x, y]
, a[x+1, y]
)
Maybe this is not sufficiently related, but perhaps some kind of automatic line wrapping in the generated code would be good too?
Is this still an issue?
yes, a minor one, but it is. I want the generated code to be as readable as possible. Ordering helps in this regards.