Skip to content

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

Merged
mohanchen merged 1 commit into
deepmodeling:developfrom
dyzheng:fix-nc-stress-gpu-develop
Aug 14, 2026
Merged

Fix(pw): correct atom index in non-collinear non-local stress on GPU#7818
mohanchen merged 1 commit into
deepmodeling:developfrom
dyzheng:fix-nc-stress-gpu-develop

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.

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.
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes collinear/non-collinear/SOC Issues related to SOC labels Aug 14, 2026

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

Thanks.

@mohanchen
mohanchen merged commit acf177d into deepmodeling:develop Aug 14, 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 Issues related to SOC Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants