Skip to content

Fix(pw): correct atom index in non-collinear non-local stress on GPU - #7819

Open
dyzheng wants to merge 1 commit into
deepmodeling:LTSfrom
dyzheng:fix-nc-stress-gpu-lts
Open

Fix(pw): correct atom index in non-collinear non-local stress on GPU#7819
dyzheng wants to merge 1 commit into
deepmodeling:LTSfrom
dyzheng:fix-nc-stress-gpu-lts

Conversation

@dyzheng

@dyzheng dyzheng commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

In the nspin=4 cal_stress_nl CUDA/ROCm kernels, deeq_nc was indexed with iat + ia while iat was also incremented inside the atom loop, so the atom offset was counted twice. For element types with more than one atom (e.g. Fe2 or HEAs), the second atom onwards read deeq_nc at wrong indices (aliasing another npol block, or out of bounds for the ps3 term), producing a wrong non-local stress with spurious off-diagonal components.

Use iat alone, consistent with the collinear stress kernel and the non-collinear force kernel, in both the CUDA and ROCm kernels.

Add CPU/GPU parity tests for the deeq_nc (nspin=4) overload of cal_stress_nl_op with ntype=1 and atom_na={2}, which fail on the buggy GPU kernel and pass after the fix. Existing tests only covered the real/collinear overload and could not catch this.

(cherry picked from commit 97cb313, adapted to the LTS source tree layout and memory-op API)

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Fix #

Unit Tests and/or Case Tests for my changes

  • Commands run:
  • Result summary:
  • Checks not run, with reason:

What's changed?

  • Example: brief summary of the user-visible or developer-facing change.

Governance Notes

  • INPUT/docs changes:
  • Core module impact:
  • Exceptions requested:

In the nspin=4 cal_stress_nl CUDA/ROCm kernels, deeq_nc was indexed
with `iat + ia` while `iat` was also incremented inside the atom
loop, so the atom offset was counted twice. For element types with
more than one atom (e.g. Fe2 or HEAs), the second atom onwards read
deeq_nc at wrong indices (aliasing another npol block, or out of
bounds for the ps3 term), producing a wrong non-local stress with
spurious off-diagonal components.

Use `iat` alone, consistent with the collinear stress kernel and the
non-collinear force kernel, in both the CUDA and ROCm kernels.

Add CPU/GPU parity tests for the deeq_nc (nspin=4) overload of
cal_stress_nl_op with ntype=1 and atom_na={2}, which fail on the
buggy GPU kernel and pass after the fix. Existing tests only covered
the real/collinear overload and could not catch this.

(cherry picked from commit 97cb313, adapted to the LTS source tree
layout and memory-op API)
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes Long-Time Support (LTS) Issues related to LTS version labels Aug 14, 2026
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 Long-Time Support (LTS) Issues related to LTS version Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants