Skip to content

perf(lammps): skip ghost-node work in fused DPA4C inference - #6160

Open
Miller10101010 wants to merge 1 commit into
deepmodeling:masterfrom
Miller10101010:perf-dpa4c-local-node-count
Open

Miller10101010 wants to merge 1 commit into
deepmodeling:masterfrom
Miller10101010:perf-dpa4c-local-node-count

Conversation

@Miller10101010

@Miller10101010 Miller10101010 commented Nov 24, 2026 •

Copy link
Copy Markdown

Use a bucketed host-side local-node count to bound local readout and backward work for single-block compressed canonical DPA4C models. Keep the ghost contributions required for neighbor forces and allow CUDA graph reuse across changes in local ownership.

Two A800 GPUs, two MPI ranks, 4,096 carbon atoms, NVE. Each measurement used 20 warm-up and 80 timed steps. Values are median ms per MD step across three alternating baseline and patched runs.

Model Neighbor rebuild Baseline Patched
Nano Default 1.049 0.909
Nano Every 4 steps 1.353 1.201
Plus Default 3.178 2.232
Plus Every 4 steps 3.369 2.481

22 C++ tests passed. Direct C API comparisons matched energy, forces and virial while retaining nonzero ghost forces. In a separate three-frame case with 13 atoms crossing a rank boundary and returning, the maximum force differences were zero for Nano and 1.68e-5 eV/Å for Plus. For Plus, the maximum total-energy difference was 0.00171 eV over the 4,096 atoms and the maximum system virial component difference was 0.00901 eV.

Closes #6091.

Summary by CodeRabbit

  • New Features
    • Added graph replay support for eligible short-range calculations involving ghost atoms, including cases where the number of owned atoms changes.
    • Padded graph processing can accommodate changing owned-atom counts while returning energies only for the current set of owned atoms.
  • Bug Fixes
    • Improved consistency of energy, force, virial, and spin-gradient results when atom counts change between evaluations.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes add bucketed row extents for canonical graphs with ghost nodes. Eligible short-range domains can use a separate graph replay runner. The Kokkos pair path passes the padded row count, and tests cover owned-count changes and energy output bounds.

Changes: Canonical domain replay

Layer / File(s) Summary
Local-node extent tracking
source/lib/include/local_node_extent.h, source/lib/src/local_node_extent.cc, source/op/pt/dpa4c/graph_compress.cu
LocalNodeExtent tracks a scoped row bound. The fused operator uses it to select the owned-node extent and to clear output buffers when rows extend beyond that extent.
Padded canonical graph rows
source/lmp/compact_canonical_graph_kokkos.h, source/lmp/pair_deepmd_kokkos.cpp
Canonical graph construction can pad rows and return the row count. The Kokkos pair path uses that count for canonical inference and force and atomic-virial buffers.
Bucketed domain replay
source/api_cc/include/DeepPotPTExpt.h, source/api_cc/src/DeepPotPTExpt.cc, source/api_cc/tests/dpa4c_canonical_test_common.h
DeepPotPTExpt selects a row bucket for eligible domains and uses a separate replay runner and internal energy buffer. It copies the owned energies to the caller. Tests cover owned-count changes and ensure an extra output slot remains unchanged.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant DeepPotPTExpt
  participant GraphReplay
  participant FusedOperator
  Caller->>DeepPotPTExpt: provide domain counts and output
  DeepPotPTExpt->>GraphReplay: replay with domain and bucket key
  GraphReplay->>FusedOperator: evaluate bucket-sized rows
  DeepPotPTExpt->>Caller: copy nloc energies
Loading

Possibly related PRs

Suggested reviewers: outisli, wanghan-iapcm

Merge Risk: Minimal · up to 77a72

This change bounds local readout and backward work for fused DPA4C inference to a bucketed owned-node count and allows CUDA graph replay to be reused when ownership changes. No concrete defect was established in review. Merge-readiness risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the perf(lammps) scope and the goal of skipping ghost-node work in fused DPA4C inference. The changeset adds bucketed local-node counts, a LocalNodeExtent helper, and the graph-replay …
Linked Issues check Passed Issue #6091 is the only active direct link. Its coding requirements are: (1) pass host-known nlocal to the fused DPA4C operator; (2) round nlocal up to a bucket and mask padded rows; (3) include the b…
Out of Scope Changes check Passed All listed changes connect to the objective of bounding local readout and backward work with a bucketed host-side count. DeepPotPTExpt.h/.cc add the state, bucket logic and separate replay runner for …
Full details: Title check

Explanation

The title names the perf(lammps) scope and the goal of skipping ghost-node work in fused DPA4C inference. The changeset adds bucketed local-node counts, a LocalNodeExtent helper, and the graph-replay and build changes that bound readout and backward work to owned nodes. Those edits match the title's main point. The title is specific enough for a reviewer scanning history. Its length (59 characters) is within normal limits.

Full details: Linked Issues check

Explanation

Issue #6091 is the only active direct link. Its coding requirements are: (1) pass host-known nlocal to the fused DPA4C operator; (2) round nlocal up to a bucket and mask padded rows; (3) include the bucket in the CUDA graph replay key; (4) launch readout, fitting and node-backward over the bucketed count; (5) keep graph replay across neighbor-list rebuilds while the bucket is unchanged. The summary shows these changes. DeepPotPTExpt.cc rounds the owned-node count to a 256-row bucket capped at nall_nodes, and includes domain and bucket size in the replay key. It updates the owned-node count outside capture. graph_compress.cu evaluates the node count through LocalNodeExtent::lookup(n_local, halo.owned) for the single-block energy-force path. compact_canonical_graph_kokkos.h pads node capacity with type -1 rows. pair_deepmd_kokkos.cpp sizes force and virial buffers to the bucketed row count. Ghost contributions for neighbor forces are kept, as the issue requires. Two deviations exist. First, nlocal reaches the operator through a thread-local LocalNodeExtent, not a new C API parameter. Second, the PR adds no new entry point or API version bump. The issue requires these only because it assumes a signature change, and the PR declares no public signature change. The reported tests (22 C++ tests, direct C API comparisons, and the 13-atom rank-crossing case) support correctness. The benchmark values differ in scale from the issue estimates. Those values are not coding requirements.

Full details: Out of Scope Changes check

Explanation

All listed changes connect to the objective of bounding local readout and backward work with a bucketed host-side count. DeepPotPTExpt.h/.cc add the state, bucket logic and separate replay runner for short-range canonical domains with halo nodes. Charge-state invalidation of both replay runners supports correct replay with the new key. local_node_extent.h/.cc supply the host count to the operator. compact_canonical_graph_kokkos adds node padding. pair_deepmd_kokkos sizes buffers to the bucketed row count. graph_compress.cu applies the bounded extent and clears buffers when the extent is smaller than the total node count. The dpa4c_canonical_test_common.h changes test the bucket, owned-count change, and replay behavior. Noncanonical edge paths keep the full node count, which keeps the change limited to the target path. No change was found that lacks a connection to #6091. This assessment is based on the change summary and was not confirmed by a full diff read.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c169c4ce-f6d4-45a2-9eb3-5c7b3c2a14d6
Commits

Reviewing files that changed from the base of the PR and between ed85942 and 77a7295.

Files selected for processing: 8

  • source/api_cc/include/DeepPotPTExpt.h
  • source/api_cc/src/DeepPotPTExpt.cc
  • source/api_cc/tests/dpa4c_canonical_test_common.h
  • source/lib/include/local_node_extent.h
  • source/lib/src/local_node_extent.cc
  • source/lmp/compact_canonical_graph_kokkos.h
  • source/lmp/pair_deepmd_kokkos.cpp
  • source/op/pt/dpa4c/graph_compress.cu

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Skip ghost nodes in the fused DPA4C operator on several ranks via a bucketed host-side local-node count

1 participant