MFIter: Device sync optimization#4897
Merged
WeiqunZhang merged 1 commit intoAMReX-Codes:developmentfrom Jan 15, 2026
Merged
Conversation
For safety reasons, we have a sync before starting jobs on non-default streams (i.e., streams with index > 0) in MFIter. But the previous approach of delaying the sync until necessary is actually slower than performing a sync on stream 0 (i.e., the default stream in amrex, not to be confused with CUDA's legacy default stream) at the beginning. This is because stream sync is relatively cheap when there are no active jobs in that stream. For example, the sequence of sync, kernel, kernel, and sync is faster than the sequence of kernel, sync, kernel, and sync, where there are no previous active jobs.
atmyers
approved these changes
Jan 15, 2026
WeiqunZhang
added a commit
to WeiqunZhang/amrex
that referenced
this pull request
Jan 15, 2026
The issue was there was an out of bound error in MFIter when local size is zero.
WeiqunZhang
added a commit
that referenced
this pull request
Jan 15, 2026
This file contains hidden or 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
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.
For safety reasons, we have a sync before starting jobs on non-default streams (i.e., streams with index > 0) in MFIter. But the previous approach of delaying the sync until necessary is actually slower than performing a sync on stream 0 (i.e., the default stream in amrex, not to be confused with CUDA's legacy default stream) at the beginning. This is because stream sync is relatively cheap when there are no active jobs in that stream. For example, the sequence of sync, kernel, kernel, and sync is faster than the sequence of kernel, sync, kernel, and sync, where there are no previous active jobs.
I have done some testing on perlmutter and frontier, the new way is about 5-10% faster for the following code.