Avoid host-device synchronization in Gram-Schmidt CGS2 - #458
Merged
Conversation
shakedregev
approved these changes
Jul 22, 2026
shakedregev
left a comment
Collaborator
There was a problem hiding this comment.
Tested and ran the Gmres examples on all platforms. Looks good, merging.
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.
Description
While working on #452, I noticed CGS2 was performing an extra device-to-host copy and synchronization in every orthogonalization step on GPU backends.
The coefficients from the first CGS pass were copied to the host and later added to those from the second pass on the host. Instead, we can keep both coefficient vectors in the active memory space and combine them using
VectorHandler::axpy().Proposed changes
vec_Hcolumn_aux_to store the coefficients from the first CGS pass, then accumulated them with the second coefficients in the active memory space usingVectorHandler::axpy()(the additional allocation is small, onlyrestart + 1elements).Timed
solver.solve()insysGmresusingmatrix_ACTIVSg200_AC_renumbered_add9_01.mtx.Average over five runs
The impact of this is easier to observe on smaller matrices.
Test environment:
Checklist
make testandmake test_installper testing instructions). Code tested on./examples/<your_example>.exe -hto get instructions how to run examples). Code tested on:-Wall -Wpedantic -Wconversion -Wextra.