Skip to content

fix(pw): prevent GPU force projector indexing overflow - #8471

Merged
mohanchen merged 7 commits into
deepmodeling:developfrom
Flying-dragon-boxing:split/pr8306-force-projector-bounds
Dec 5, 2026
Merged

mohanchen merged 7 commits into
deepmodeling:developfrom
Flying-dragon-boxing:split/pr8306-force-projector-bounds

Conversation

@Flying-dragon-boxing

Copy link
Copy Markdown
Collaborator

What's changed?

With 8,421,376 selected projector entries, the GPU save and restore kernels used to launch one block per entry. The excess threads pushed the signed 32-bit index past its range. Negative indices could pass the bounds check and lead to out-of-bounds writes.

Launch one thread per entry, rounded up to a whole block. Use size_t for flattened indices and offsets, reject threads beyond the entry count, and skip empty launches. CUDA and ROCm use the same bounds logic. The projector mapping and restore coefficient are unchanged.

Linked Issue

Correctness fix split from #8306 by @dyzheng.

Unit Tests and/or Case Tests for my changes

Recompiled the standalone CUDA reproducer against the upstream and patched force_op.cu on an RTX 4090 with CUDA 12.6. From the scratch directory, with each source version saved as force_old.cu or force_new.cu:

for v in old new; do
    /usr/local/cuda-12.6/bin/nvcc -std=c++14 -O2 -arch=sm_89 -D__CUDA \
        -I../repo/source -I../repo/source/source_base/module_container \
        ../repro/force_index_repro.cu "force_${v}.cu" -o "force_${v}"
done
OMP_NUM_THREADS=1 CUDA_VISIBLE_DEVICES=0 ./force_old
OMP_NUM_THREADS=1 CUDA_VISIBLE_DEVICES=0 ./force_new
  • Upstream c7a18a8ed: cudaMemcpy reported illegal memory access (exit 2).
  • Patched: all 8,421,376 saved projector values matched (exit 0).
  • The draft defers a repository regression test. This reproducer covers save on CUDA. Restore was inspected in code, and ROCm was not built or run.

Governance Notes

  • INPUT/docs: No documentation update required. The change is internal to projector save and restore.
  • Core module impact: PW nonlocal force projector kernels on CUDA and ROCm.
  • Exceptions requested: None.

dyzheng and others added 3 commits November 25, 2026 15:14
Split from deepmodeling#8306. Bound save/restore launches by thread count on CUDA and HIP.
…ce-projector-bounds

# Conflicts:
#	source/source_pw/module_pwdft/kernels/cuda/force_op.cu
#	source/source_pw/module_pwdft/kernels/rocm/force_op.hip.cu
@Flying-dragon-boxing
Flying-dragon-boxing marked this pull request as ready for review December 2, 2026 06:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T06:57:28.701235Z dc6052b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc6052be8e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mohanchen mohanchen added Refactor Refactor ABACUS codes GPU & DCU & HPC GPU and DCU and HPC related any issues labels Dec 2, 2026
@mohanchen
mohanchen merged commit a57bb55 into deepmodeling:develop Dec 5, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants