Skip to content

Fix GPU segfaults in PW USPP calculations#7647

Open
chengleizheng wants to merge 2 commits into
deepmodeling:developfrom
chengleizheng:fix/uspp-gpu-bug
Open

Fix GPU segfaults in PW USPP calculations#7647
chengleizheng wants to merge 2 commits into
deepmodeling:developfrom
chengleizheng:fix/uspp-gpu-bug

Conversation

@chengleizheng

@chengleizheng chengleizheng commented Jul 16, 2026

Copy link
Copy Markdown

Summary

Fix GPU segfaults in PW USPP calculations caused by CPU code accessing GPU
memory pointers. Added CPU intermediate buffers and D2H/H2D sync patterns
in three USPP-specific code paths.

Changes

  • hamilt_pw: sPsi reads qq_nt from CPU backup (qq_nt.ptr) instead of
    GPU pointer, fills a CPU buffer, then syncs to GPU for cuBLAS.

  • elecstate_pw (cal_becsum): becp computed on GPU via gemm then synced
    to CPU; auxk1/auxk2 use CPU vectors; aux_gk computed on GPU then synced
    to CPU; becsum allocated on CPU (consumed by CPU-only force/stress code).

  • elecstate_pw (add_usrho): Added D2H/H2D wrappers around real2recip
    and recip2real FFT calls, which read/write via CPU loops.

  • elecstate_pw (addusdens_g): Rewritten to use pure CPU computation
    (CPU BLAS zgemm_, CPU radial_fft_q); ylmk0 computed on GPU with H2D'd
    gcar then D2H'd back.

Test plan

  • Run PW USPP test cases (003, 008, 009) on GPU, verify no segfault
  • Run compute-sanitizer to confirm 0 GPU memory errors

chengleizheng and others added 2 commits July 16, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant