Skip to content

Fix Davidson-subspace GPU breakdown from rounding residuals - #8454

Merged
mohanchen merged 10 commits into
deepmodeling:developfrom
cheerly-pku:fix/dav-subspace-residual-roundoff
Dec 3, 2026
Merged

mohanchen merged 10 commits into
deepmodeling:developfrom
cheerly-pku:fix/dav-subspace-residual-roundoff

Conversation

@cheerly-pku

@cheerly-pku cheerly-pku commented Dec 1, 2026 •

Copy link
Copy Markdown

A single-precision Davidson-subspace GPU test can turn a small rounding residual into a direction that duplicates the existing basis, causing the reduced generalized eigenproblem to fail. This was exposed when #8264 began running the shared HSolver GPU tests; it is a follow-up to #8142 / #8127, independent of the PPCG implementation.

Reproducer and cause

The CUDA failure on #8264 starts in DavSubspaceTest/1.MixedConvergedBandsAndOverlap, with heevd: failed to invert matrix; the subsequent six timer exceptions follow that first failure. The original scale-4 fixture passes locally on RTX 3090/CUDA 13.5, but scaling H and S together to 5 reproduces the cuSolver failure while preserving eigenvalues, initial vector directions, S condition number (1.9), and both test tolerances.

Local diagnostics show residuals of 4.77e-7 and 2.38e-7: above the old eigenvalue-only roundoff guard but below the configured 1e-6 threshold. Normalization creates a duplicate direction; the projected overlap contains the singular block [[1.25,-2.5],[-2.5,5]]. A diagnostic cuSolver interceptor records info=10 for the six-dimensional generalized solve. Diagnostic instrumentation is not included in this PR.

Change

  • Form Hx and Sx with the unchanged Ritz coefficients, then calculate Hx − λSx. This avoids rounding λ into the coefficient matrix before the S product.
  • Estimate the cancellation scale from epsilon * (||Hx|| + |lambda| ||Sx||), keeping the existing small-residual floor and the cap at the requested band threshold.
  • Reuse the unused H-image workspace. No extra H/S applications or device allocations are added; two vector norm reductions per active band are added.
  • Extend the existing mixed-state regression to scales 4, 5 and 8. Solver and check tolerances remain 1e-6 and 2e-5.
  • Execute the existing HSolver GPU CTest targets through one common CUDA workflow step. This makes the CUDA regression run in this PR's CI; it adds no solver-specific log parsing, test lists or diagnostic infrastructure.

No INPUT parameter, application reference, timer infrastructure or PPCG numerical implementation changes. No performance improvement is claimed. No user documentation update is needed: the INPUT interface and intended convergence behavior are unchanged; this fixes premature expansion of rounding residuals in an existing solver.

Verification

Fresh local verification used the two-file patch in the existing build trees at PPCG branch be642ec73, with OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1:

cmake --build build-ppcg-ci-repro-20261125 --target MODULE_HSOLVER_dav_subspace_gpu -j4
ctest --test-dir build-ppcg-ci-repro-20261125 --output-on-failure -R '^MODULE_HSOLVER_dav_subspace_gpu$'
build-ppcg-ci-repro-20261125/source/source_hsolver/unittests/MODULE_HSOLVER_dav_subspace_gpu --gtest_repeat=30
cmake --build build-review --target MODULE_HSOLVER_dav_subspace -j4
ctest --test-dir build-review -V -R '^MODULE_HSOLVER_dav_subspace(_parallel)?$'
cmake --build build-review-nompi --target MODULE_HSOLVER_dav_subspace -j4
ctest --test-dir build-review-nompi -V -R '^MODULE_HSOLVER_dav_subspace$'

Results: CUDA 10/10 tests, repeated 30/30 suites (300 executions); CPU 12/12, existing two-rank MPI 8/8 per rank, and non-MPI 12/12. The strict-threshold, loose-energy-tolerance and small-preconditioned-direction regressions still pass. A fresh independent build of the original Davidson commit 6cbad6bd6, based on upstream 5064965fa, subsequently passed GPU CTest 2/2 registrations (LOBPCG 43/43 and Davidson 10/10) and CPU/MPI CTest 2/2 registrations (12 serial cases and 8 per MPI rank). A Compute Sanitizer memcheck of the 10 Davidson GPU cases reported zero errors. Changed-line formatting preserves the verified source after whitespace removal. Staged governance has no blockers; its documentation warning is addressed by the no-documentation-change rationale above. Whitespace and actionlint checks pass. Logs and exact source/binary hashes are retained in /mnt/data/Cheerly/ppcg-review-20261201/ and /mnt/data/Cheerly/ppcg-ci-20261201/.

Limits

The hosted CUDA workflow on 7a45cb703 subsequently passed, including the Davidson GPU tests and all six GPU integration steps: run 46595572954. Local tests used RTX 3090/CUDA 13.5. That hosted result belongs to the earlier head containing the downloader prerequisite; it is not a completed check of the current scope-cleanup commit. The new expression estimates cancellation error; it is not a general rank-recovery algorithm. An extra 15-scale diagnostic scan improved from 3 passing cases to 12, but scales 32, 100 and 1000 still fail. In those cases residuals can exceed the configured threshold (for example 1.156e-6 > 1e-6 at scale 100). This patch preserves that threshold and does not discard those directions as converged; broader rank recovery remains follow-up work.

Related: #8264. The shared GPU test entry point is identical to the one currently on that branch so it can be reviewed and merged with this independent Davidson fix.

Review follow-up and merge order (2026-12-02)

Commit 5e02dcaff removes the downloader changes from this PR's final diff, following the review request. The remaining three files are the Davidson implementation, its regression test, and the common HSolver CUDA test entry point. All downloader changes remain independently in #8456. PR #8456 has now merged. This branch has been synchronized with the resulting develop; its toolchain files match the merged versions byte-for-byte. The Davidson implementation and regression test are unchanged. The previous prerequisite merge commits remain in branch history; the toolchain files and precommit workflow are restored byte-for-byte to the pre-dependency state, with no force push.

The same commit documents that residual_thresholds is populated and queried only for bands in the incoming unconv list. In-place compaction retains a subset of that list; entries for other bands are unused. This is a comment-only change to the numerical source; no thresholds or algorithm behavior changed.

Verification of this follow-up: exact source comparison after removing the two added comment lines passed; toolchain/precommit files match the original 6cbad6bd6 state; git diff --cached --check passed; staged governance had no blockers (its documentation warning is covered by the unchanged-user-behavior rationale above). The development merge was rebuilt locally: MODULE_HSOLVER_dav_subspace, MODULE_HSOLVER_dav_subspace_parallel, MODULE_HSOLVER_lobpcg_gpu, and MODULE_HSOLVER_dav_subspace_gpu all passed (CTest 4/4). All three unit-test executables rebuilt successfully. Downloader files matched merged develop; the Davidson implementation and test matched the pre-merge PR head exactly. Full hosted checks for the synchronized head are now running.

@mohanchen mohanchen added Diago Issues related to diagonalizaiton methods GPU & DCU & HPC GPU and DCU and HPC related any issues labels Dec 1, 2026
Comment thread .github/workflows/precommit.yml Resolved

@ABACUS-PR-BOT ABACUS-PR-BOT 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.

Static inspection of 7a45cb7 found no additional actionable defect in the Davidson residual/threshold change, workspace reuse or downloader prerequisite. The threshold remains a cancellation heuristic; arbitrary scaling and backend behavior are not established by this source review. The existing dependency-order and threshold-invariant suggestions remain in their original threads.

Static review only; no builds or runtime tests were run.

@cheerly-pku

Copy link
Copy Markdown
Author

@Cstandardlib Thanks for the review. #8456 has merged, and this branch is now synchronized with develop at head 78a46c35e322b75a774a3bccb67c7bfb3da8a8f6. The PR diff contains only the Davidson implementation, its regression test, and the shared HSolver CUDA test entry point; no toolchain changes remain. I also added the requested comment documenting the residual_thresholds invariant. Both review threads have been addressed.

All 18 checks on the current head have now passed, including CUDA, CPU integration tests, abacuslite, and the complete build matrix. Could you please take another look when you have time? Thank you!

@Cstandardlib Cstandardlib 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.

LGTM. Thank you for your fix!

@mohanchen
mohanchen merged commit 80bf37e into deepmodeling:develop Dec 3, 2026
18 checks passed
@mohanchen mohanchen added the Bugs Bugs that only solvable with sufficient knowledge of DFT label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT Diago Issues related to diagonalizaiton methods GPU & DCU & HPC GPU and DCU and HPC related any issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants