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] Improve concurrency when using async. #424
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rmoyard
approved these changes
Jan 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great solution!
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
maliasadi
reviewed
Jan 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @erick-xanadu! I have a few questions..
Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: The initial implementation of async had a naive algorithm that serialized a lot of potentially concurrent code. This PR improves the algorithm and guarantees maximum concurrency.
Description of the Change:
The
async.execute
instruction returns a token and a promise.We can then wait on the promise or the token
If
async.await
is used for the first time and the value is not available, the thread will waituntil the value becomes available. If the value is available, the function returns practically immediately. For example.
This makes the job of deciding where to place awaits really easy.
We just need to place awaits just before every use of the original value.
For example, take the following piece of code
First we translate the call to an async.execute (which was performed before this
function was called) When this function was called, the transformation is not yet
complete. Because there are still uses of %quantum_results.
This function will perform the following change:
And it will do so for every use of
%quantum_results
. Eg.Benefits: Improved concurrency.
Possible Drawbacks: Not really a drawback, but potential improvement point (which is independent of this commit). We could have a heuristic to decide when async is profitable locally. I believe async is always profitable in remote execution, but not locally.
[sc-52637]