Skip to content

Commit 2bb3eed

Browse files
authored
fix(lammps): support 2025 Kokkos API (deepmodeling#5987)
## Summary Backport `0002-support-lammps-2025-kokkos-api.patch` from `conda-forge/deepmd-kit-feedstock@d02138263b0b30629fe28c68c8bcecc2b8644513`. Support both the LAMMPS 22Jul2025 Kokkos API and newer LAMMPS releases by selecting the appropriate reverse-communication buffer and per-atom energy accumulator types from `LAMMPS_VERSION_NUMBER`. ## Validation - Four-file backport matching the feedstock patch. - Split from deepmodeling#5985 so the compatibility change can be reviewed independently. - Full build is left to upstream CI. Agent: ChatGPT Model: GPT-5.6 Sol <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Compatibility** - Improved support across multiple LAMMPS versions for Kokkos-based DeepMD and DPA-4-spin simulations. - Updated reverse communication and per-atom energy handling to use version-compatible data formats. - **Bug Fixes** - Resolved compatibility issues that could affect reverse communication and energy accumulation across LAMMPS releases. - Preserved existing force, magnetic-force, and virial calculation behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 47f2a9c commit 2bb3eed

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

source/lmp/pair_deepmd_kokkos.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void PairDeepMDKokkos<DeviceType>::unpack_reverse_comm(int n,
113113

114114
template <class DeviceType>
115115
int PairDeepMDKokkos<DeviceType>::pack_reverse_comm_kokkos(
116-
int n, int first, DAT::tdual_double_1d& buf) {
116+
int n, int first, DeepMDKokkosCommBuffer& buf) {
117117
auto d_buf = buf.template view<DeviceType>();
118118
if (reverse_virial) {
119119
auto reverse_virial_data = k_reverse_virial.template view<DeviceType>();
@@ -141,7 +141,7 @@ int PairDeepMDKokkos<DeviceType>::pack_reverse_comm_kokkos(
141141

142142
template <class DeviceType>
143143
void PairDeepMDKokkos<DeviceType>::unpack_reverse_comm_kokkos(
144-
int n, DAT::tdual_int_1d list, DAT::tdual_double_1d& buf) {
144+
int n, DAT::tdual_int_1d list, DeepMDKokkosCommBuffer& buf) {
145145
auto d_buf = buf.template view<DeviceType>();
146146
auto d_list = list.template view<DeviceType>();
147147
if (reverse_virial) {

source/lmp/pair_deepmd_kokkos.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ PairStyle(deepmd/kk/host,PairDeepMDKokkos<LMPHostType>);
2828

2929
namespace LAMMPS_NS {
3030

31+
// LAMMPS 22Jul2025 exposes reverse-communication buffers as X_FLOAT; starting
32+
// with 10Sep2025, Kokkos pair styles use a fixed double buffer.
33+
#if LAMMPS_VERSION_NUMBER < 20250910
34+
using DeepMDKokkosCommBuffer = DAT::tdual_xfloat_1d;
35+
#else
36+
using DeepMDKokkosCommBuffer = DAT::tdual_double_1d;
37+
#endif
38+
3139
// GPU-resident inference for exported ``.pt2`` models whose forward consumes
3240
// an explicit edge graph: both the graph-input form (a compact, unpadded
3341
// neighbor graph) and the edge-input form. Both are dispatched through
@@ -64,10 +72,10 @@ class PairDeepMDKokkos : public PairDeepMD, public KokkosBase {
6472
// host-staged path.
6573
int pack_reverse_comm(int, int, double*) override;
6674
void unpack_reverse_comm(int, int*, double*) override;
67-
int pack_reverse_comm_kokkos(int, int, DAT::tdual_double_1d&) override;
75+
int pack_reverse_comm_kokkos(int, int, DeepMDKokkosCommBuffer&) override;
6876
void unpack_reverse_comm_kokkos(int,
6977
DAT::tdual_int_1d,
70-
DAT::tdual_double_1d&) override;
78+
DeepMDKokkosCommBuffer&) override;
7179

7280
// Build the device edge graph of the edge-input schema from the Kokkos full
7381
// neighbor list, returning the edge count. Public because it launches
@@ -101,8 +109,14 @@ class PairDeepMDKokkos : public PairDeepMD, public KokkosBase {
101109

102110
// Per-atom energy accumulator (aliases the base Pair ``eatom`` host array so
103111
// downstream per-atom computes/dumps see it after the device-to-host sync).
112+
// The transformed accumulator view was added in the 10Sep2025 release.
113+
#if LAMMPS_VERSION_NUMBER < 20250910
114+
DAT::tdual_double_1d k_eatom;
115+
typename AT::t_double_1d d_eatom;
116+
#else
104117
DAT::ttransform_kkacc_1d k_eatom;
105118
typename AT::t_kkacc_1d d_eatom;
119+
#endif
106120

107121
int edge_capacity; // allocated edges in d_edge_index / d_edge_vec
108122
bool edge_vec_fp32; // model graph ABI consumes edge vectors in fp32

source/lmp/pair_dpa4spin_kokkos.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void PairDPA4SpinKokkos<DeviceType>::unpack_reverse_comm(int n,
115115

116116
template <class DeviceType>
117117
int PairDPA4SpinKokkos<DeviceType>::pack_reverse_comm_kokkos(
118-
int n, int first, DAT::tdual_double_1d& buf) {
118+
int n, int first, DPA4SpinKokkosCommBuffer& buf) {
119119
auto d_buf = buf.template view<DeviceType>();
120120
if (reverse_virial) {
121121
auto reverse_virial_data = k_reverse_virial.template view<DeviceType>();
@@ -147,7 +147,7 @@ int PairDPA4SpinKokkos<DeviceType>::pack_reverse_comm_kokkos(
147147

148148
template <class DeviceType>
149149
void PairDPA4SpinKokkos<DeviceType>::unpack_reverse_comm_kokkos(
150-
int n, DAT::tdual_int_1d list, DAT::tdual_double_1d& buf) {
150+
int n, DAT::tdual_int_1d list, DPA4SpinKokkosCommBuffer& buf) {
151151
auto d_buf = buf.template view<DeviceType>();
152152
auto d_list = list.template view<DeviceType>();
153153
if (reverse_virial) {

source/lmp/pair_dpa4spin_kokkos.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ PairStyle(dpa4spin/kk/host,PairDPA4SpinKokkos<LMPHostType>);
2828

2929
namespace LAMMPS_NS {
3030

31+
// LAMMPS 22Jul2025 exposes reverse-communication buffers as X_FLOAT; starting
32+
// with 10Sep2025, Kokkos pair styles use a fixed double buffer.
33+
#if LAMMPS_VERSION_NUMBER < 20250910
34+
using DPA4SpinKokkosCommBuffer = DAT::tdual_xfloat_1d;
35+
#else
36+
using DPA4SpinKokkosCommBuffer = DAT::tdual_double_1d;
37+
#endif
38+
3139
// GPU-resident inference for exported native-spin ``.pt2`` models whose forward
3240
// consumes the compact canonical graph: a dual-CSR neighbor topology with
3341
// uint32 indices and float32 edge vectors, plus the per-node magnetic moment.
@@ -64,10 +72,10 @@ class PairDPA4SpinKokkos : public PairDPA4Spin, public KokkosBase {
6472
// overrides serve the host-staged path.
6573
int pack_reverse_comm(int, int, double*) override;
6674
void unpack_reverse_comm(int, int*, double*) override;
67-
int pack_reverse_comm_kokkos(int, int, DAT::tdual_double_1d&) override;
75+
int pack_reverse_comm_kokkos(int, int, DPA4SpinKokkosCommBuffer&) override;
6876
void unpack_reverse_comm_kokkos(int,
6977
DAT::tdual_int_1d,
70-
DAT::tdual_double_1d&) override;
78+
DPA4SpinKokkosCommBuffer&) override;
7179

7280
// Gather the per-node magnetic moment from the Kokkos ``sp`` array. Public
7381
// because it launches an extended device lambda, which CUDA forbids inside
@@ -94,8 +102,14 @@ class PairDPA4SpinKokkos : public PairDPA4Spin, public KokkosBase {
94102

95103
// Per-atom energy accumulator (aliases the base Pair ``eatom`` host array so
96104
// downstream per-atom computes/dumps see it after the device-to-host sync).
105+
// The transformed accumulator view was added in the 10Sep2025 release.
106+
#if LAMMPS_VERSION_NUMBER < 20250910
107+
DAT::tdual_double_1d k_eatom;
108+
typename AT::t_double_1d d_eatom;
109+
#else
97110
DAT::ttransform_kkacc_1d k_eatom;
98111
typename AT::t_kkacc_1d d_eatom;
112+
#endif
99113

100114
bool reverse_virial; // reverse communication operates on centroid virial
101115
bool reverse_used_host; // force reverse communication selected host staging

0 commit comments

Comments
 (0)