fix(gpu): avoid host-side FFT crash in LDOS output and wfc-read charge density - #7847
Merged
Merged
Conversation
…e density On GPU builds the host-side recip2real/real2recip (fftw path) returns nullptr aux buffers, causing segfaults in cal_ldos_pw (out_ldos) and read_wf2rho_pw (init_chg=wfc). Route these calls through the recip_to_real<Device> dispatch with device-side buffers and explicit CPU<->device synchronization. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… and explicit host-device synchronization.
# Conflicts: # source/source_io/module_ctrl/ctrl_output_pw.cpp # source/source_io/module_wf/read_wf2rho_pw.cpp
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.
Fix #7770
Two of the three PW-basis GPU calculations reported in this issue (
scf_out_ldosand057_PW_SO_IW) crashed with a null-pointer segmentation fault in post-SCF IO routines, both passing on CPU; the remaining one (100_PW_W90) is a separate host-side FFT crash in the Wannier90 output and will be handled in a follow-up PR.The common root cause of the two fixes here is that these code paths were only ever exercised on CPU builds: in a GPU build, the host-side FFTW entry points recip2real/real2recip are compiled but internally dereference a nullptr auxiliary buffer, so any call that reaches them segfaults. The fix routes every such call through the device-aware recip_to_real/real_to_recip dispatch with explicit H2D/D2H transfers, keeping the host-side call only when the code is instantiated for DEVICE_CPU. In the LDOS output path (
cal_ldos.cppand its caller inctrl_output_pw.cpp), this was done by templating the LDOS routines on the device type and syncing the wave functions to the device (stp.update_psi_d()) before handing their pointers to the GPU FFT; in the wfc-read charge density path (read_wf2rho_pw.cpp), the same dispatch pattern was applied to both the nspin=2 and nspin=4 branches, and the per-band host-to-device copy was narrowed to the actual plane-wave count npwk of each k-point instead of the over-allocated npwk_max * npol.With these changes
057_PW_SO_IWcompletes on GPU (EXIT=0) and its results match the CPU reference, so it is re-enabled in tests/01_PW/CASES_GPU.txt to cover the regression in the GPU CI suite;scf_out_ldos, however, stays commented out even though the crash is fixed, because its LDOS cube output shows an intrinsic ~1e-4 relative deviation from the CPU reference (e.g. 9.478e-03 vs 9.479e-03, cuFFT vs fftw rounding) that exceeds the test's 1e-5 accuracy threshold and would be reported as a fatal error by catch_properties.sh, so re-enabling it requires regenerating the reference or relaxing that threshold first. Numerical verification of the wfc-read path confirms the fix is transparent: the charge density reconstructed from read-in wave functions is bitwise identical between GPU and CPU.