-
Notifications
You must be signed in to change notification settings - Fork 611
fix(c++): fix NULL type in custom op #4889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wanghan-iapcm
merged 26 commits into
deepmodeling:master
from
iProzd:D0814_debug_c_nlist
Mar 4, 2026
Merged
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f99ad4d
debug 4749
iProzd ba8f52e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa8b3a8
fix cmake
iProzd 4dab5d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4a2027e
fix bugs
iProzd a4f565f
Update DeepPotPT.cc
iProzd 58e340c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e0626dd
Update DeepPotPT.cc
iProzd 73ad268
wrapped a func
iProzd 7167591
fix const
iProzd 619b158
Merge branch 'devel' into D0814_debug_c_nlist
iProzd e8b889e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2114514
Update test_lammps_dpa_pt.py
iProzd af2411d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 69a9086
Merge branch 'master' into D0814_debug_c_nlist
wanghan-iapcm bb13cdf
revert old fix
iProzd 0411338
use own comm data for remapped sendlist
iProzd b415c67
Update common.cc
iProzd 3068a24
Revert commit
iProzd c8e4be1
Merge branch 'master' into D0814_debug_c_nlist
iProzd 5875158
update fix, ref to #5268
iProzd 78fdc64
Delete test_select_real_atoms_sendlist.cc
iProzd 773c4e6
Create test_select_real_atoms_sendlist.cc
iProzd b061270
Update DeepSpinPT.cc
iProzd 9afc5c0
fix PD
iProzd 280729f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #ifdef BUILD_PYTORCH | ||
| #include <torch/torch.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include "common.h" | ||
| #include "neighbor_list.h" | ||
|
|
||
| namespace deepmd { | ||
|
|
||
| /** | ||
| * @brief Build comm_dict tensors from sendlist/sendnum/recvnum buffers. | ||
| * | ||
| * This is the shared tensor-building logic for all PyTorch backends | ||
| * (DeepPotPT, DeepSpinPT). Backend-specific entries (e.g. has_spin) | ||
| * should be added by the caller after this function returns. | ||
| * | ||
| * @param[out] comm_dict The communication dictionary to populate. | ||
| * @param[in] lmp_list The LAMMPS neighbor list (for sendproc/recvproc/world). | ||
| * @param[in] sendlist Pointer array (int**) for each swap's send list. | ||
| * @param[in] sendnum Number of send atoms per swap. | ||
| * @param[in] recvnum Number of recv atoms per swap. | ||
| */ | ||
| inline void build_comm_dict(torch::Dict<std::string, torch::Tensor>& comm_dict, | ||
| const InputNlist& lmp_list, | ||
| int** sendlist, | ||
| int* sendnum, | ||
| int* recvnum) { | ||
| int nswap = lmp_list.nswap; | ||
| auto int32_option = | ||
| torch::TensorOptions().device(torch::kCPU).dtype(torch::kInt32); | ||
| auto int64_option = | ||
| torch::TensorOptions().device(torch::kCPU).dtype(torch::kInt64); | ||
|
|
||
| torch::Tensor sendlist_tensor = | ||
| torch::from_blob(static_cast<void*>(sendlist), {nswap}, int64_option); | ||
| torch::Tensor sendnum_tensor = | ||
| torch::from_blob(sendnum, {nswap}, int32_option); | ||
| torch::Tensor recvnum_tensor = | ||
| torch::from_blob(recvnum, {nswap}, int32_option); | ||
| torch::Tensor sendproc_tensor = | ||
| torch::from_blob(lmp_list.sendproc, {nswap}, int32_option); | ||
| torch::Tensor recvproc_tensor = | ||
| torch::from_blob(lmp_list.recvproc, {nswap}, int32_option); | ||
|
|
||
| torch::Tensor communicator_tensor; | ||
| static std::int64_t null_communicator = 0; | ||
| if (lmp_list.world == nullptr) { | ||
| communicator_tensor = | ||
| torch::from_blob(&null_communicator, {1}, torch::kInt64); | ||
| } else { | ||
| communicator_tensor = | ||
| torch::from_blob(const_cast<void*>(lmp_list.world), {1}, torch::kInt64); | ||
| } | ||
|
|
||
| comm_dict.insert_or_assign("send_list", sendlist_tensor); | ||
| comm_dict.insert_or_assign("send_proc", sendproc_tensor); | ||
| comm_dict.insert_or_assign("recv_proc", recvproc_tensor); | ||
| comm_dict.insert_or_assign("send_num", sendnum_tensor); | ||
| comm_dict.insert_or_assign("recv_num", recvnum_tensor); | ||
| comm_dict.insert_or_assign("communicator", communicator_tensor); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Build comm_dict with sendlist remapping for virtual (NULL-type) atoms. | ||
| * | ||
| * Calls remap_comm_sendlist() to remap indices through fwd_map, then | ||
| * build_comm_dict() to create tensors. Backend-specific entries (e.g. | ||
| * has_spin) should be added by the caller after this function returns. | ||
| * | ||
| * @param[out] comm_dict The communication dictionary to populate. | ||
| * @param[in] lmp_list The LAMMPS neighbor list containing communication info. | ||
| * @param[in] fwd_map Map from original atom index to real-atom index (-1 for | ||
| * virtual atoms). | ||
| * @param[out] remapped_sendlist Storage for remapped send lists (kept alive for | ||
| * tensor lifetime). | ||
| * @param[out] remapped_sendlist_ptrs Pointer array into remapped_sendlist. | ||
| * @param[out] remapped_sendnum Remapped send counts per swap. | ||
| * @param[out] remapped_recvnum Remapped recv counts per swap. | ||
| */ | ||
| inline void build_comm_dict_with_virtual_atoms( | ||
| torch::Dict<std::string, torch::Tensor>& comm_dict, | ||
| const InputNlist& lmp_list, | ||
| const std::vector<int>& fwd_map, | ||
| std::vector<std::vector<int>>& remapped_sendlist, | ||
| std::vector<int*>& remapped_sendlist_ptrs, | ||
| std::vector<int>& remapped_sendnum, | ||
| std::vector<int>& remapped_recvnum) { | ||
| remap_comm_sendlist(remapped_sendlist, remapped_sendnum, remapped_recvnum, | ||
| lmp_list, fwd_map); | ||
| int nswap = lmp_list.nswap; | ||
| remapped_sendlist_ptrs.resize(nswap); | ||
| for (int s = 0; s < nswap; ++s) { | ||
| remapped_sendlist_ptrs[s] = remapped_sendlist[s].data(); | ||
| } | ||
| build_comm_dict(comm_dict, lmp_list, remapped_sendlist_ptrs.data(), | ||
| remapped_sendnum.data(), remapped_recvnum.data()); | ||
| } | ||
|
|
||
| } // namespace deepmd | ||
|
|
||
| #endif // BUILD_PYTORCH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.