Skip to content

feat(hsolver): add CPU and native CUDA PPCG for PW diagonalization - #8264

Open
cheerly-pku wants to merge 272 commits into
deepmodeling:developfrom
cheerly-pku:ppcg-v3-review
Open

cheerly-pku wants to merge 272 commits into
deepmodeling:developfrom
cheerly-pku:ppcg-v3-review

Conversation

@cheerly-pku

@cheerly-pku cheerly-pku commented Nov 2, 2026 •

Copy link
Copy Markdown

Adds projected preconditioned conjugate-gradient (PPCG) diagonalization for CPU and native CUDA plane-wave SCF, supporting NCPP standard eigenproblems and USPP generalized eigenproblems through the shared H/S operator interface. NSCF, stochastic DFT and unsupported GPU backends are rejected during INPUT validation.

Scope

Prerequisite: #8454 independently fixes the Davidson-subspace GPU failure exposed by the common HSolver test selector. Commit db4c405b6 carries its identical two-file solver/test patch so this PR can validate the combined state. Merge #8454 first to keep the final PPCG diff separate; its shared GPU test step matches this branch. No changes to other solvers are hidden in the PPCG implementation.

The numerical algorithm and CPU/CUDA kernels live in source_hsolver. Changes elsewhere connect the solver to the application:

  • INPUT registration and validation expose ks_solver=ppcg and ppcg_rr_step; the output module adds the PP SCF label.
  • PW, DeltaSpin and stochastic-PW callers adapt the shared HSolverPW signature and explicit log stream. SDFT remains rejected for PPCG; its changes preserve shared-interface compatibility.
  • CMake/Makefile lists link the new implementation. Unit tests are registered with CTest; application fixtures use the standard Autotest lists. CUDA unit execution uses a common HSolver GPU selector.

Commit bda7b032d removes the unrelated APT retry/error-handling change. build_test_cmake.yml now matches the PR base exactly. Dependency-download reliability is now addressed separately in #8453; that patch is not part of this PPCG branch. This workflow-only cleanup passed base-file byte comparison, bash -n for both run blocks, whitespace and staged governance checks. Numerical validation below remains attributed to 926e141c9; no numerical files changed in the cleanup. The workflow was restored before the test consolidation described below.

Behavior

  • pw_diag_ndim controls block size; ppcg_rr_step controls the full Rayleigh–Ritz interval (default 1).
  • Convergence uses freshly evaluated generalized residuals. Iteration-limit failures remain visible; non-finite residuals are fatal. Bounded near-convergence refinement retains normalization, energy/order checks and rollback safeguards.
  • CUDA keeps wavefunctions, residuals and search directions on the GPU. Small projected eigensystems and MPI scalars use the host; no full-wavefunction CPU callback bridge is used.
  • Includes analytical matrix tests, eight CUDA unit cases, and seven ordinary application fixtures per backend in the standard Autotest lists. One additional strict Fe fixture per backend is available for manual precision diagnostics. The CUDA workflow uses shared test entry points; it has no PPCG-specific tracing, residual-warning gate or diagnostic uploads.

Accuracy and efficiency

Fresh CPU comparisons on 2026-11-27 use CG as the accuracy baseline. Within each pair, geometry, cutoffs, k meshes, smearing, mixing and seed are identical; both solvers use scf_thr_type=1, scf_thr=1e-10, initial pw_diag_thr=1e-10, and SCF/diagonalization limits of 200. All twelve runs converged. Differences are finite-SCF comparisons, not exact error bounds or proof of equivalent stopping criteria.

System Energy difference (eV) Max force difference (eV/Å) Max stress difference (kbar)
GaAs (NCPP) 1.319e-10 5.300e-04 4.074e-03
Si (NCPP) 9.456e-10 0.000e+00 5.141e-03
Al (NCPP) 1.894e-10 0.000e+00 4.786e-02
Fe (USPP) 1.218e-09 0.000e+00 2.870e-02
NaCl (USPP) 1.473e-08 1.260e-04 3.397e-02
HCl (mixed NCPP/USPP) 1.920e-10 2.868e-06 4.551e-02

Repeating the three USPP-containing pairs at scf_thr=1e-12 also converged, with maximum energy/force/stress differences of 4.88e-10 eV, 2.87e-6 eV/Å, and 9.33e-3 kbar. BPCG is not used to substantiate accuracy. The existing BPCG-generated strict-USPP reference files are explicitly identified as historical regression snapshots; their values and tolerances remain unchanged.

The controlled historical CPU timing study found PPCG wall times 1.07–2.71 times CG on these small systems. Those timings have not been remeasured after the numerical fixes; no speedup is claimed. Fresh tables, settings, failed-probe exclusions and historical four-solver timings are in the validation report.

Fe acceptance update

Ordinary Fe checks use scf_thr=1e-12 and the existing diago_smooth_ethr=1 option, retaining tight occupied-band thresholds and occupation-dependent thresholds for nearly empty states. The 23-band basis, physical settings, iteration limits, references and observable tolerances are unchanged. The report includes the convergence study, including its nonmonotonic stress result at 1e-14.

At these settings, fresh matched two-rank PPCG/CG comparisons give energy differences of 4.55e-13 eV (CPU) and 1.82e-12 eV (CUDA), zero force differences by symmetry, and maximum stress differences of 4.74e-4 kbar. A per-band refinement eligibility fix removes the ordinary four-rank CPU warning without changing convergence criteria.

The original scf_thr=1e-16, uniform-threshold Fe inputs remain in CPU/CUDA CASES_PPCG_STRESS.txt for manual precision diagnostics. They are outside the ordinary CI lists. Their individual residuals must be inspected alongside observable comparisons; the historical strict-precision limitations remain documented.

20-band Fe fix

The previously failing 20-band Fe input now converges on CPU and CUDA. The fix detects cancellation when combining search directions and refreshes the affected H/S images before their errors can be amplified by normalization. It preserves the original scf_thr=1e-12, uniform residual thresholds, seed, physical settings and 200-iteration limit.

A new standard/generalized matrix regression fails with the old combination update and passes with the fix. The CPU/CUDA 20-band fixtures are now included in the normal mandatory Autotest lists, with no expected-failure handling. Independent CG comparisons give energy differences of 6.82e-12 eV (CPU) and 5.91e-12 eV (CUDA), zero force differences by symmetry, and maximum stress-component differences of 7.85e-4 kbar. New reference files are explicitly CPU PPCG regression snapshots, not CG-derived accuracy benchmarks; the report records their provenance and the distinct aggregate-stress comparison metric.

Unit-test scope

The CPU double-precision suite is one 860-line file. PPCG test/support code totals 1,989 lines, reduced from 4,024 before consolidation. Float (307 lines), CUDA (231) and MPI (414) retain their separate executables. Detailed repetitive probes remain archived locally and recoverable at bda7b032d.

The CPU target has 18 runtime tests, including two kernel checks. The analytical parameter table covers standard/generalized complex matrices, repeated eigenvalues, padding and block sizes. Selected regressions retain low-root recovery, Ritz intervals, false-convergence protection, workspace limits, unequal band thresholds, cancellation, rollback and trace opt-in/append behavior.

Review follow-up be642ec73 restores two small standard/generalized regressions: near-parallel projection with independent HP/SP consistency checks, and four-ULP eigenvalue correction without moving exact vectors. External mutation copies confirm both tests catch disabled protections, including an SP-only stale-cache mutation. Named intermediate values and explicitly sequenced random samples address the style follow-ups. The MPI description now distinguishes zero initial vector support from zero local rows; zero-row decompositions are not covered.

Fresh verification: both MPI-enabled and non-MPI CPU builds pass all 18/18 PPCG tests (these are single-process unit runs). Exact commands and logs are in the validation report. Staged governance, changed-line formatting and whitespace checks pass. The production margin expression is unchanged mathematically; application inputs, references and thresholds are unchanged. The non-blocking single-column refinement optimization is documented as follow-up work, not implemented or claimed as a measured improvement. Each outstanding bot request has a separate reply in its original thread.

CUDA workflow integration (2026-12-01)

The current head is db4c405b6, which includes review follow-up be642ec73 and the independently reviewed Davidson fix from #8454 (6cbad6bd6). New hosted CI is running; results from the previous failing head remain recorded below. The fix first forms Hx and Sx and then subtracts lambda*Sx, using their norms to estimate cancellation roundoff with the user threshold still as an upper cap. The local mixed-state reproduction now passes at overlap scales 4, 5 and 8, with GPU 10/10 cases repeated 30 times, CPU 12/12, non-MPI 12/12 and two-rank MPI 8/8 per rank. An independent clean build and complete application regressions are also running. The separate PR records remaining high-scale rank-breakdown probes and the additional norm reductions; no general rank-recovery or speedup claim is made.

Workflow cleanup was implemented in 562edd352. Hosted CI for this commit has finished. All checks except the CUDA build/test job passed, including both Read the Docs checks. The CUDA job built successfully, then failed in the newly included MODULE_HSOLVER_dav_subspace_gpu: the single-precision MixedConvergedBandsAndOverlap test threw heevd: failed to invert matrix; the six subsequent tests reported timer::start Diago_DavSubspace::diag_once exceptions. In that same run, LOBPCG passed 43/43 tests and PPCG passed 8/8. The later GPU integration steps were skipped after the unit-test failure, so their earlier local success is not being presented as a hosted result for this commit. Dependency installation passed; this failure is separate from the earlier APT download errors. That run predates the #8454 correction; the current head must complete its own CUDA CI. Tests and thresholds have not been bypassed or relaxed.

The CUDA workflow now calls the common HSolver GPU CTest selection, ^MODULE_HSOLVER_.*_gpu$, which covers LOBPCG, Davidson-subspace and PPCG. The existing 11_PW_GPU Autotest invocation is restored unchanged. All 15 cases in CASES_GPU.txt, including seven ordinary PPCG cases, remain selected.

PPCG-specific trace activation, residual-log filtering, the separate strict Fe step, job-summary construction and diagnostic artifact uploads have been removed. Application CI uses the shared Autotest checks; it no longer has an additional PPCG residual-warning failure gate. Strict Fe and detailed residual tracing remain manual diagnostics. Numerical code, fixtures, reference values and tolerances are unchanged.

Fresh local verification on an RTX 3090: the rebuilt common GPU CTest selection passed 3/3 targets (43 LOBPCG, 10 Davidson-subspace and eight PPCG runtime tests). The rebuilt application passed the complete ordinary GPU integration list: 15/15 cases, 317 reference checks, including all seven PPCG fixtures. Each case used two MPI ranks and one OpenMP thread, with four cases running concurrently and residual tracing disabled. No PPCG nonconvergence warning was found in the local case logs. Workflow parsing, Bash syntax, selector/case-list checks, actionlint and whitespace checks passed. Exact commands and log locations are in the updated validation report.

Verification and remaining limitations

CI before the workflow cleanup, checked on 2026-12-01: commit 7b799dd9e3a68889ae2746d94ac3b068f49f712c completed 18/18 successful checks: 16 GitHub Actions checks and both Read the Docs checks. These include the nine-configuration CMake build matrix, CPU unit/integration tests, CUDA tests, ASE tests, and Makefile/Intel build. Both documentation previews passed: abacus-develop and abacus-rtd. These results belong to the preceding workflow configuration. The cleanup commit's CUDA failure is recorded above; numerical and performance limitations remain documented below.

The preceding run on f508f54f1 failed while downloading Ubuntu package indexes or dependencies, before the affected jobs reached ABACUS compilation or testing (build matrix, CPU, CUDA, ASE). The logs show connection failures to Ubuntu archive/security endpoints; they do not identify whether the server, network route, proxy, or runner caused them.

7b799dd9e is an empty commit with no file changes, used to trigger a fresh CI run. That run installed dependencies and passed. This supports an intermittent dependency-download problem. The successful run did not apply #8453, so its recovery is not attributed to that separate CI patch; no PPCG code or test tolerance changed to obtain this rerun result.

The f508f54f1 follow-up only clarifies the pw_diag_thr source comment by naming CG, Davidson, Davidson-subspace, BPCG, PPCG and LOBPCG. Declarations and initializers are identical after removing comments and whitespace; diff checks passed. No new tests or documentation changes are required for this comment-only clarification; the existing INPUT help already lists these solvers. Runtime tests were not repeated for it.

For 926e141c9, CPU/CUDA builds passed. Focused CTest results: 5/5 CPU, 1/1 CUDA PPCG, and 1/1 non-MPI PPCG. That pre-consolidation CPU suite included 66 PPCG cases; current coverage is listed above. Eight CPU fixtures with four ranks and eight RTX 3090 fixtures with two ranks passed 88/88 observable checks, with no residual warnings, including the 20-band and original strict 23-band Fe cases. Separate strict Fe checks with two/four ranks passed on both backends. Compute Sanitizer passed all eight CUDA unit cases with zero errors and leaks. All sixteen fixture READMEs are two lines.

Exact build targets, CTest patterns, Autotest selections, reference provenance and failed-probe exclusions are in the report. Changed C++ formatting, whitespace and staged governance checks passed. The latest CI status is shown in this PR's checks.

Remaining limits: on the preceding fc89a51a3 head, all 19 checks passed, while the strict L20 Fe diagnostic retained one residual of 1.0519e-14 against 1e-14. Local success on the new head does not certify the L20 result. Tighter CG and Davidson-subspace reference probes failed or did not converge and are excluded from accuracy claims. Strict Fe precision diagnostics remain available for manual runs; no general performance or universal robustness claim is made.

Governance warnings cover direct header type dependencies and two existing Deltaspin PARAM reads (net global-dependency increase zero); no exception is requested.

cheerly-pku and others added 30 commits June 6, 2026 19:42
The [w,p] block of the Gram matrix M shrinks as residuals converge,
making M nearly singular and causing sygvd to produce garbage
eigenvectors.  Scaling w and p to unit S-norm keeps M well-conditioned
(diagonal ~1) without changing the subspace — Ritz values are identical
and Ritz vector coefficients cancel in update_one_block.

This enables the full 3-block [psi,w,p] subspace (use_p=true) by
addressing the fundamental ill-conditioning that the p-bad Krylov
fallback alone could not handle.
The Krylov fallback (replace p with Hw when p~w) was flawed:
when w is approximately an eigenvector (Hw ≈ λw), the replacement
does not fix collinearity.  After S-norm scaling, p ≈ w still,
M_wp ≈ [1,1;1,1] is rank-1, and dsygvd fails.

Instead, simply skip p for this iteration (use_p_now=false).
update_one_block still produces a valid p for the next iteration
from the w Ritz-vector contribution.
Add tests for:
- 2x2 matrix (smallest non-trivial case)
- Degenerate eigenvalues (H = I + J, multiplicity-3 degeneracy)
- Larger 20x20 tridiagonal with 5 bands
- Dense 8x8 matrix via Givens rotations (addresses full-matrix coverage)

All use CONJUGATE_GRADIENT strategy which has sygvd fallback.
BLOCK_SUBSPACE tests deferred due to dsygvd instability with some LAPACK builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Covers diagonal, tridiagonal, dense, pentadiagonal, degenerate,
Neumann, S≠I, gamma_g0, single-band, all-band, many-band,
bad preconditioner, tight threshold, scaled, gapped spectrum,
rr_step=1, 1x1, and eigenvector quality checks.

Adds QuickBenchmark (CI-friendly) and DISABLED_FullBenchmark.
@Cstandardlib

Copy link
Copy Markdown
Collaborator

@Cstandardlib, regarding your comment:

Thank you for the suggestion. I have added the requested application comparisons on GaAs/Si/Al NCPP cases and Fe/NaCl/HCl USPP-containing cases. The validation report gives energy, force, stress, and four-solver timing tables with exact settings and explicit exclusions for failed or inconsistent comparison runs. PPCG is slower than CG on these small cases; no general speedup is claimed.

Three new USPP Autotest cases use independently computed BPCG references at tighter SCF settings, without relaxing the existing acceptance tolerances. The six NCPP/USPP native cases passed 36/36 checks with two ranks; the new USPP cases also passed 15/15 checks with four ranks. The report retains the roundoff-level eigensolver warnings observed in the deliberately strict cases and distinguishes them from the warning-free default-threshold comparison.

Thanks for your validation report! I'd like to add a note of caution: the BPCG algorithm has known reported issues on systems such as Fe, so it is not recommended as a benchmark for accuracy comparisons. For that purpose, CG or dav_subspace can be used instead.

@cheerly-pku

Copy link
Copy Markdown
Author

@Cstandardlib, thank you for pointing this out. I agree that BPCG should not be used to substantiate accuracy on Fe.

I have removed the PPCG–BPCG accuracy table and added fresh CG comparisons for all six NCPP/USPP-containing systems. All twelve matched CG/PPCG runs converged at scf_thr=1e-10. Repeating the three USPP-containing pairs at scf_thr=1e-12 also converged; the maximum energy, force-component and stress-component differences were 4.88e-10 eV, 2.87e-6 eV/Å, and 9.33e-3 kbar. The report gives the common settings and per-system results, and the PR description now uses CG as the accuracy baseline.

The existing BPCG-generated strict-USPP files are explicitly labeled as historical regression snapshots, not accuracy benchmarks. CG probes at the fixtures' scf_thr=1e-16 failed with psi_norm <= 0.0; those runs are excluded, and I have not replaced the reference files with unconverged results. The strict L20 Fe residual failure remains open and is reported separately from the observable comparisons. No fixture tolerance or iteration limit was relaxed.

The report changes are in c5e12ebd5, with exact post-merge verification commands in d821c24fa.

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

No new correctness defect was identified in the cancellation and refinement changes at 926e141c9. Two follow-ups concern the work done per refinement band and newly added computed arguments; the latter is addressed in the existing style thread.

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

Comment thread source/source_hsolver/diago_ppcg.cpp 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.

No new production-code defect was identified in the test-consolidation increment at 7b799dd9. Please retain two focused numerical regressions and clarify the MPI coverage wording; new computed-argument cases are noted in the existing style thread.

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

Comment thread docs/advanced/scf/ppcg_validation.md Resolved
Apply the identical two-file solver/test patch from 6cbad6b. The independently reviewable Davidson fix is a prerequisite for the common HSolver GPU CI selection in PR 8264. Keep the common test selection and all acceptance thresholds unchanged.
@cheerly-pku

Copy link
Copy Markdown
Author

@Cstandardlib I synchronized ppcg-v3-review with the latest develop and resolved the conflicts in commit 4354c6ea2aacfbb8dd58ba585a4f9afcbb7bbf29. The CUDA workflow now runs both the existing GPU solver tests and the new direct_dm checks; the PW solver list in the docs reflects the current default while retaining PPCG documentation; the HSolver constructor and DeltaSpin call sites retain the PPCG interval and current solver selection.

All 18 hosted checks on this head have passed, including the CPU and CUDA build/test workflows. Locally, the PPCG unit tests passed on CPU and CUDA, and the strict Fe 20-band application fixture passed its four energy/force/stress checks on both CPU and RTX 3090 CUDA. Could you please review this updated head again? Thank you.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Diago Issues related to diagonalizaiton methods Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants