Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new simplification rule for invariant loop parameters. #1990

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

athas
Copy link
Member

@athas athas commented Jul 20, 2023

This was suggested by Cosmin to address some of the code produced by AD.

The idea is that for a loop of the form

loop p = x ...
  ...stms...
  in res

we construct and simplify the body

  let p = x
  ...stms...
  in res

and if that simplifies to 'x', then we conclude that the loop parameter 'p' must be invariant to the loop and simply bind it (and the loop result) to 'x'.

Complication: for multi-parameter loops, we must also check that the original computation of 'res' does only depends on other invariant loop parameters.

Currently we do this only for loops that have a constant as one of their initial loop parameter values.

The main downside of this rule is that doing recursive simplification is quite expensive. Especially after sequentialisation, pretty much every 'reduce' will have been turned into a loop that triggers this rule (although the rule itself will fail in most cases, after doing the simplification). Therefore I'm a bit hesitant to enable it as is. Sure, the Futhark compiler is slow and it was never meant to be fast, but it is still quite easy for the compiler to become uselessly slow if we are not careful. E.g. on OptionPricing, this rule itself makes compilation 10% slower (and does not actually optimise anything - this is purely the cost of failing checks).

@athas
Copy link
Member Author

athas commented Jul 20, 2023

@coancea You're very welcome to suggest ways to speed this up.

@athas athas added the run-benchmarks Makes GA run the benchmark suite. label Jul 20, 2023
@athas athas force-pushed the invariant-loop-simplify branch 3 times, most recently from bbe184f to ff4969e Compare July 21, 2023 08:09
This was suggested by Cosmin to address some of the code produced by
AD.

The idea is that for a loop of the form

loop p = x ...
  ...stms...
  in res

we construct and simplify the body

  let p = x
  ...stms...
  in res

and if that simplifies to 'x', then we conclude that the loop
parameter 'p' must be invariant to the loop and simply bind it (and
the loop result) to 'x'.

Complication: for multi-parameter loops, we must also check that
the *original* computation of 'res' does *only* depends on other
invariant loop parameters.

Currently we do this only for loops that have a constant as one of
their initial loop parameter values.

The main downside of this rule is that doing recursive simplification
is quite expensive.  Especially after sequentialisation, pretty much
every 'reduce' will have been turned into a loop that triggers this
rule (although the rule itself will fail in most cases, after doing
the simplification).  Therefore I'm a bit hesitant to enable it as is.
Sure, the Futhark compiler is slow and it was never meant to be fast,
but it is still quite easy for the compiler to become *uselessly slow*
if we are not careful.  E.g. on OptionPricing, this rule itself makes
compilation 10% slower (and does not actually optimise anything - this
is purely the cost of failing checks).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-benchmarks Makes GA run the benchmark suite.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant