Fix: preserve exact-origin spherical harmonics in GPU Gint (Useful Information to print out exactly the same numbers with both CPU and GPU) - #7901
Open
GenZeal-Lin wants to merge 1 commit into
Conversation
mohanchen
reviewed
Sep 3, 2026
| // Normalize the input direction vector | ||
| double r = sqrt(x_in * x_in + y_in * y_in + z_in * z_in); | ||
| double x, y, z; | ||
| if (r < 1e-10) |
Collaborator
There was a problem hiding this comment.
On what basis is the cutoff set to 1 × 10⁻¹⁰
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.
Reminder
AGENTS.mdanddocs/developers_guide/agent_governance.md.source/changes.Linked Issue
Fixes #7860
Related: #7856
Unit Tests and/or Case Tests for my changes
The temporary wrapper above only runs the validated CUDA binary under a
450-second timeout. GPU mode was forced separately by the temporary
device gpuedits shown above. The INPUT changes and smoke-list file wereremoved after the test and are not part of this PR.
# Final PR patch check. git diff --check upstream/develop..HEAD git diff --name-only upstream/develop..HEADResult summary:
c1790ea39532f9630b8917972131afdf1fb08dfa.CONFIG_RC=0).BUILD_RC=0,FINAL_BUILD_OK=1).TARGET_AUTOTEST_RC=0).scf_out_hsr_spin4:hrs1_nao.csris byte-identical to the reference (CMP_RC=0)nscf_out_hsr_tr_rr:hrs1_nao.csris byte-identical to the reference (CMP_RC=0)12_NAO_Gamma_GPU: PASS (RC=0).13_NAO_multik_GPU: PASS (RC=0).git diff --check: PASS.source/source_base/kernels/cuda/sph_harm_gpu.cuhsource/source_hamilt/module_gint/kernel/phi_operator_kernel.cuhtests/03_NAO_multik/CASES_GPU.txtChecks not run, with reason:
the final submission gate. This change is confined to the CUDA
spherical-harmonic/Gint path, so final validation focused on the two
directly affected integration cases and both existing NAO GPU guard
suites.
cases reproduce the affected H(R) output end-to-end and are re-enabled
here as strict regression coverage.
What's changed?
This PR fixes the GPU-specific H(R) CSR discrepancy reported in #7860 by
aligning GPU Gint with the existing CPU Gint behavior at an exact
atom-grid coincidence.
For an exact displacement
(0, 0, 0), CPU Gint evaluates the existingspherical-harmonic recurrence directly. The general CUDA
sph_harmhelper instead normalizes its input direction and falls back to the +z
direction for a near-zero norm. When GPU Gint passed an exact zero
displacement through that helper, the fallback produced different
spherical-harmonic values at this special point. The resulting H(R)
residuals could remain above the fixed sparse-output threshold, changing
the CSR sparsity pattern.
This fix leaves the general CUDA
sph_harmsemantics unchanged. Itsexisting recurrence is factored into a direct helper that performs
neither normalization nor zero-vector fallback. GPU Gint uses that
direct recurrence only when the original atom-grid displacement is
exactly
(0, 0, 0), matching the CPU Gint recurrence at that specialpoint. All nonzero displacements in this Gint path, and all other callers
of
sph_harm, retain the pre-existing path.With this fix, the two cases intentionally left disabled in #7856
because of #7860 are re-enabled in
tests/03_NAO_multik/CASES_GPU.txt:scf_out_hsr_spin4nscf_out_hsr_tr_rrThis restores strict regression coverage without relaxing the CSR
comparator, changing the sparse-output threshold, or updating reference
data.
Governance Notes
documentation metadata is changed.
device gpuedits used for local validation were restoredafter testing and are not part of the PR.
03_NAO_multikcases in
CASES_GPU.txt.source/source_base/kernels/cuda/sph_harm_gpu.cuhfactors the existingspherical-harmonic recurrence into a direct helper while preserving the
general GPU
sph_harmnormalization and near-zero fallback behavior.source/source_hamilt/module_gint/kernel/phi_operator_kernel.cuhchangesonly the exact-origin GPU Gint path to use the direct recurrence.
Nonzero displacements retain the previous behavior.
threshold, or reference-data behavior is modified.