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

[DAPHNE-#911] Correct reference counter for arith.select result. #912

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pdamme
Copy link
Collaborator

@pdamme pdamme commented Nov 12, 2024

This PR fixes the double-free bug mentioned in #911, but is still in draft state, because I suspect it can create memory leaks in certain cases. No review required at the moment.


  • The MLIR operation arith.select is frequently created during the canonicalization of scf.if (which, in turn, is created by DaphneDSL if-statements).
  • arith.select takes a boolean argument (condition) plus two additional arguments, one of which it selects/returns based on the value of the condition.
  • arith.select needs to be taken into account in DAPHNE's object reference counter management, because:
    • We decrease the reference counter of SSA values after their last use as operands (the arith.select could be the last user).
    • We have no clue which of the two last operands of arith.select is returned at run-time.
    • However, the return value is the same runtime object as one of the two latter operands.
    • To ensure the correct reference counter for the result after the arith.select, we need to increase the counter of the result before we decrease the counters of the operands.
  • We had already implemented this fix, but applied it only for string operands/results.
  • However, we must apply the fix for all operand/result types that have a reference counter at run-time.
  • Fixed ManageObjRefPass.
  • Added several script-level test cases testing the behavior for matrices, frames, lists, and strings and different settings of the if-then-else in DaphneDSL.

- The MLIR operation arith.select is frequently created during the canonicalization of scf.if (which, in turn, is created by DaphneDSL if-statements).
- arith.select takes a boolean argument (condition) plus two additional arguments, one of which it selects/returns based on the value of the condition.
- arith.select needs to be taken into account in DAPHNE's object reference counter management, because:
  - We decrease the reference counter of SSA values after their last use as operands (the arith.select could be the last user).
  - We have no clue which of the two last operands of arith.select is returned at run-time.
  - However, the return value is the same runtime object as one of the two latter operands.
  - To ensure the correct reference counter for the result after the arith.select, we need to increase the counter of the result before we decrease the counters of the operands.
- We had already implemented this fix, but applied it only for string operands/results.
- However, we must apply the fix for all operand/result types that have a reference counter at run-time.
- Fixed ManageObjRefPass.
- Added several script-level test cases testing the behavior for matrices, frames, lists, and strings and different settings of the if-then-else in DaphneDSL.
@pdamme pdamme mentioned this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant