devito icon indicating copy to clipboard operation
devito copied to clipboard

Temporary variables name in generated code is unordered

Open FabioLuporini opened this issue 5 years ago • 3 comments

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])

FabioLuporini avatar Apr 17 '19 08:04 FabioLuporini

Maybe this is not sufficiently related, but perhaps some kind of automatic line wrapping in the generated code would be good too?

tjb900 avatar Apr 24 '19 08:04 tjb900

Is this still an issue?

mloubout avatar Nov 08 '19 14:11 mloubout

yes, a minor one, but it is. I want the generated code to be as readable as possible. Ordering helps in this regards.

FabioLuporini avatar Nov 09 '19 08:11 FabioLuporini