Skip to content

fix(gpu): avoid host-side FFT crash in LDOS output and wfc-read charge density - #7847

Merged
mohanchen merged 4 commits into
deepmodeling:developfrom
chengleizheng:fix/3-segfault
Aug 23, 2026
Merged

fix(gpu): avoid host-side FFT crash in LDOS output and wfc-read charge density#7847
mohanchen merged 4 commits into
deepmodeling:developfrom
chengleizheng:fix/3-segfault

Conversation

@chengleizheng

Copy link
Copy Markdown
Collaborator

Fix #7770

Two of the three PW-basis GPU calculations reported in this issue (scf_out_ldos and 057_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.cpp and its caller in ctrl_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_IW completes 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.

chengleizheng and others added 4 commits August 21, 2026 16:26
…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

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

@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes collinear/non-collinear/SOC/delta-spin Issues related to SOC GPU & DCU & HPC GPU and DCU and HPC related any issues labels Aug 23, 2026
@mohanchen
mohanchen merged commit cda0a73 into deepmodeling:develop Aug 23, 2026
17 checks passed
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 collinear/non-collinear/SOC/delta-spin Issues related to SOC GPU & DCU & HPC GPU and DCU and HPC related any issues Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GPU] PW segfaults: 057_PW_SO_IW (SOC init_wfc), 100_PW_W90 (Wannier90), scf_out_ldos (post-SCF)

2 participants