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

[MLIR] Removes use of ValueRange after using sanitizers. #310

Merged
merged 4 commits into from Oct 12, 2023

Conversation

erick-xanadu
Copy link
Contributor

@erick-xanadu erick-xanadu commented Oct 12, 2023

Context: Wheels did not pass because of memory issues. After looking into it with address sanitizers, ValueRange is the culprit.

Description of the Change: Do not use ValueRange.

https://github.com/PennyLaneAI/catalyst/actions/runs/6495027163

@github-actions
Copy link

Hello. You may have forgotten to update the changelog!
Please edit doc/changelog.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@erick-xanadu erick-xanadu force-pushed the eochoa/2023-10-12/v0.3.1-rc-patch-1 branch from a23f726 to 087f8ff Compare October 12, 2023 11:28
@erick-xanadu erick-xanadu marked this pull request as ready for review October 12, 2023 11:55
Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

Thanks Erick! 🎉

@erick-xanadu
Copy link
Contributor Author

I'll leave this to @dime10 to decide how he wants to merge for the release. Merge with release candidate or merge with main and then with release candidate.

@erick-xanadu erick-xanadu force-pushed the eochoa/2023-10-12/v0.3.1-rc-patch-1 branch from 3599242 to 26e2a71 Compare October 12, 2023 15:07
@dime10
Copy link
Collaborator

dime10 commented Oct 12, 2023

Just a note here for future reference. std::vectors should generally not be returned from such utility functions that merely provide access to existing data. ValueRange, TypeRange, and the like are used in MLIR precisely to have a lightweight way of passing around IR objects which are tied to a long-lived object.
In this case, it's the Operation object that owns the data (the operands) and there should be no issue returning a range. The actual problem was the way the range was constructed (my bad)!

On the other hand, a common error I've made in the past is constructing a ValueRange locally to be passed into an MLIR function. This typically doesn't work because there is no underlying storage object when gathering various Value objects into a ValueRange in this manner. Here, constructing a container that can hold the disparate Value objects (such as SmallVector<Value>) is necessary.

Copy link
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

What about CustomOp? Is that safe because it already returns a range for getParams()?

mlir/lib/Quantum/Transforms/AdjointPatterns.cpp Outdated Show resolved Hide resolved
mlir/include/Quantum/IR/QuantumOps.td Outdated Show resolved Hide resolved
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
@erick-xanadu
Copy link
Contributor Author

What about CustomOp? Is that safe because it already returns a range for getParams()?

When I run all the lit tests with sanitizers there are no more errors.

@dime10
Copy link
Collaborator

dime10 commented Oct 12, 2023

What about CustomOp? Is that safe because it already returns a range for getParams()?

When I run all the lit tests with sanitizers there are no more errors.

I guess that must be explanation then 😅 Sounds good 👍

@dime10
Copy link
Collaborator

dime10 commented Oct 12, 2023

It's very curious that we already used the correct form here:

return getODSOperands(0);

I can't mark it in the code, but could you update that line as well with getParamOperandIdx?

Copy link
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

🦝

@dime10
Copy link
Collaborator

dime10 commented Oct 12, 2023

Oh and update the existing changelog entry with this PR link :)

@dime10 dime10 force-pushed the eochoa/2023-10-12/v0.3.1-rc-patch-1 branch from 9130055 to ac34938 Compare October 12, 2023 16:03
@dime10 dime10 merged commit 0057084 into v0.3.1-rc Oct 12, 2023
2 of 3 checks passed
@dime10 dime10 deleted the eochoa/2023-10-12/v0.3.1-rc-patch-1 branch October 12, 2023 16:03
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.

None yet

3 participants