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

Bitwuzla: Fix performance issues in FloatingPointFormulaManagerTest #396

Merged

Conversation

daniel-raffler
Copy link
Contributor

@daniel-raffler daniel-raffler commented Sep 19, 2024

Hello,
this MR aims to fix the performance issues described in #371. The problem was not about the conversion operation itself, but about the large number of ProverEnvironments that would be created, one for each test input. We solve this by reusing the same ProverEnvironment for all inputs of the test. This also improves the performance of Z3 for those same tests.

In addition to that the MR includes a number of minor fixes:

  • Bitwuzla does not support float-to-bitvector conversions and we are using a work-around that introduces new side-conditions for the casts. We now make sure that side-conditions are only pushed onto the stack when needed. The old version would simply include everything in the query, even for variables that don't occur in the assertions, which can cause significant overhead
  • We fixed the names that are used for the variables in these side-conditions to make sure that there are no clashes
  • FunctionDeclarationKind gets a new Symbol FP_REM which was missing
  • We also added support for BV_SHR and BV_ROL, BV_ROLI, BV_ROR, BV_RORI to the Bitwuzla FormulaCreator

Copy link
Member

@kfriedberger kfriedberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. I annotated some minor things.

return builder.build();
}

public Iterable<Term> getVariableCasts(Iterable<Term> pTerms) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this code? This needs to be commented and explained.

Copy link
Member

@kfriedberger kfriedberger Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a fixedpoint iteration that collects variables from terms, and from related terms, and from their related terms,...

It is written as possibly complex code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a fixedpoint iteration that collects variables from terms, and from related terms, and from their related terms,..

Yes, that's the idea. Whenever a formula is pushed onto the assertion stack we need to check if it uses any variables that come from fp-to-bv casts and then include side-conditions for those casts. This needs to be done recursively until all casts are covered.

I think there are a few other solvers (like CVC5) that don't allow fp-to-bv casting? It would be possible to include this code in AbstractBitformulaManager so that it than can be used by those solvers as well.

* @param f A function that takes values from the list and returns assertions
* @param args A list of arguments to the function
*/
private <T> void proveForAll(Function<T, BooleanFormula> f, List<T> args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just styling and personal preference: switch parameters. Using the list of args upfront makes it sound like prove for all <numbers> that <function> is satisfiable.

@daniel-raffler
Copy link
Contributor Author

Thanks for the review! I've opened a new issue about the rotations (#397). Once this has been resolved the workaround can be removed here. I've also added some more documentations about getVariableCasts() and merged the calculation into a single function.

@kfriedberger kfriedberger force-pushed the 371-better-performance-in-floatingpointmanagertest branch 2 times, most recently from 5e90916 to 04b0a0a Compare September 21, 2024 23:26
The new approach has several improvements:
- only analyse those constraints that are referenced in terms,
- do not compare Sets for the fixed-point, but wait for an empty waitlist.
@kfriedberger kfriedberger force-pushed the 371-better-performance-in-floatingpointmanagertest branch from 04b0a0a to d00c4c2 Compare September 21, 2024 23:27
@kfriedberger kfriedberger merged commit d808f78 into master Sep 22, 2024
1 of 3 checks passed
@daniel-raffler daniel-raffler deleted the 371-better-performance-in-floatingpointmanagertest branch October 7, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Bitwuzla is unusualy slow for FP query based on IEEE conversion
2 participants