fix(api_cc): size remapped atomic parameters by stride#5790
Conversation
Allocate one output scalar for every frame, retained atom, and atomic-parameter component before select_map remaps neighbor-list inputs. The previous allocation omitted daparam and could write past the vector when dim_aparam exceeded one. Add float and double regressions covering two frames, local and ghost virtual atoms, and both local-only and all-atom parameter layouts. Fixes deepmodeling#5618. Coding-Agent: Codex Codex-Version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
📝 WalkthroughWalkthrough
ChangesAtomic parameter remapping
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@source/api_cc/tests/test_select_map.cc`:
- Around line 98-138: Fix both affected tests in
source/api_cc/tests/test_select_map.cc:98-138 and
source/api_cc/tests/test_select_map.cc:140-178 by changing
TYPED_TEST(TestSelectMap, ...) to TEST_F(TestSelectMap, ...), and replace every
TypeParam use with the fixture’s VALUETYPE type. Keep the existing test logic
and assertions unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 567d2c71-1c2e-4d17-a39d-311e6d570543
📒 Files selected for processing (2)
source/api_cc/src/common.ccsource/api_cc/tests/test_select_map.cc
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5790 +/- ##
==========================================
- Coverage 79.85% 79.58% -0.27%
==========================================
Files 1022 1022
Lines 117351 117387 +36
Branches 4313 4310 -3
==========================================
- Hits 93706 93422 -284
- Misses 22101 22408 +307
- Partials 1544 1557 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wanghan-iapcm
left a comment
There was a problem hiding this comment.
Correct fix. select_map writes out[kknall1stride + to_iistride + dd] with stride=daparam and does not resize out, so the destination needs nframesnall1*daparam elements; the old resize omitted the daparam factor, overflowing the buffer for dim_aparam>1. The new resize matches select_map's indexing exactly. The regressions genuinely fail pre-fix on the size assertion (4!=8, 6!=12) before even hitting the out-of-bounds writes, and they cover both the aparam_nall=false (local) and aparam_nall=true (all) branches, plus float/double and local+ghost virtual atoms. Good explanation of why daparam=1 fixtures hid it. LGTM.
Dismissing to re-review through the /code-review skill per process.
wanghan-iapcm
left a comment
There was a problem hiding this comment.
Re-reviewed via the code-review skill. Correct and complete: the new nframesnall1daparam allocation exactly matches select_map's max write index+1 (select_map doesn't resize its output, so the caller's resize is load-bearing), and the sibling dcoord/atype buffers were already correctly stride-sized, so no analogous bug remains. Day-one issue from #2436 where the aparam line never followed the stride-multiply pattern its dcoord neighbor established in the same commit. The two regressions fail pre-fix deterministically (size 4!=8 and 6!=12 via ASSERT_EQ) and cover both aparam_nall branches with local+ghost virtual atoms; pre-sizing aparam_out keeps the failure a clean size-assertion rather than an ASAN crash. The CodeRabbit TYPED_TEST-won't-compile note is a false positive (the fixture is a template). LGTM.
Conflict: source/api_cc/src/common.cc -- both sides fixed the same daparam-stride aparam buffer sizing (deepmodeling#5790 upstream, e95f2ba here); code identical, comment text taken from upstream so the hunk drops out of this PR's diff. deepmd/dpmodel/descriptor/dpa1.py auto-merged with master's deepmodeling#5785 (dense call is unconditionally _call_dense; verified post-merge).
Summary
Impact
The previous allocation omitted the daparam factor. For models with dim_aparam greater than one, select_map wrote more scalar components than the vector contained, causing undefined behavior and potential heap memory corruption in shared neighbor-list API paths.
Why existing tests missed this
Existing multiframe and neighbor-list API tests use models whose daparam is one. The aparam_nall=true fixtures also use one component per atom, so the missing multiplier was numerically hidden.
The new direct helper tests exercise the exact missing combination: daparam=2 with virtual-atom remapping, multiple frames, local parameters, and local-plus-ghost parameters.
Validation
Closes #5618.
Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests