Skip to content

Avoid host-device synchronization in Gram-Schmidt CGS2 - #458

Merged
shakedregev merged 3 commits into
developfrom
kakeru/improve-cgs
Jul 22, 2026
Merged

Avoid host-device synchronization in Gram-Schmidt CGS2#458
shakedregev merged 3 commits into
developfrom
kakeru/improve-cgs

Conversation

@kakeueda

@kakeueda kakeueda commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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

  • Removed an unnecessary device-to-host synchronization from CGS2.
  • Added vec_Hcolumn_aux_ to store the coefficients from the first CGS pass, then accumulated them with the second coefficients in the active memory space using VectorHandler::axpy() (the additional allocation is small, only restart + 1 elements).

Timed solver.solve() in sysGmres using matrix_ACTIVSg200_AC_renumbered_add9_01.mtx.

Average over five runs

  • Before: 0.852530 s
  • After: 0.699054 s

The impact of this is easier to observe on smaller matrices.

Test environment:

  • NVIDIA GeForce RTX 5050 Laptop GPU
  • CUDA 12.9

Checklist

  • All tests pass (make test and make test_install per testing instructions). Code tested on
    • CPU backend
    • CUDA backend
    • HIP backend
  • I have manually run the non-experimental examples and verified that residuals are close to machine precision. (In your build directory run: ./examples/<your_example>.exe -h to get instructions how to run examples). Code tested on:
    • CPU backend
    • CUDA backend
    • HIP backend
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows Re::Solve style guidelines.
  • [N/A] There are unit tests for the new code.
  • The new code is documented.
  • [N/A] The feature branch is rebased with respect to the target branch.
  • I have updated CHANGELOG.md to reflect the changes in this PR. If this is a minor PR that is part of a larger fix already included in the file, state so.

@kakeueda kakeueda self-assigned this Jul 21, 2026
@kakeueda
kakeueda requested review from pelesh and shakedregev July 21, 2026 14:43

@shakedregev shakedregev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Testing this.

@shakedregev shakedregev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tested and ran the Gmres examples on all platforms. Looks good, merging.

@shakedregev
shakedregev merged commit 4c325e6 into develop Jul 22, 2026
6 checks passed
@shakedregev
shakedregev deleted the kakeru/improve-cgs branch July 22, 2026 13:14
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.

2 participants