Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/lmp/pair_deepmd_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void PairDeepMDKokkos<DeviceType>::unpack_reverse_comm(int n,

template <class DeviceType>
int PairDeepMDKokkos<DeviceType>::pack_reverse_comm_kokkos(
int n, int first, DAT::tdual_double_1d& buf) {
int n, int first, DeepMDKokkosCommBuffer& buf) {
auto d_buf = buf.template view<DeviceType>();
if (reverse_virial) {
auto reverse_virial_data = k_reverse_virial.template view<DeviceType>();
Expand Down Expand Up @@ -141,7 +141,7 @@ int PairDeepMDKokkos<DeviceType>::pack_reverse_comm_kokkos(

template <class DeviceType>
void PairDeepMDKokkos<DeviceType>::unpack_reverse_comm_kokkos(
int n, DAT::tdual_int_1d list, DAT::tdual_double_1d& buf) {
int n, DAT::tdual_int_1d list, DeepMDKokkosCommBuffer& buf) {
auto d_buf = buf.template view<DeviceType>();
auto d_list = list.template view<DeviceType>();
if (reverse_virial) {
Expand Down
18 changes: 16 additions & 2 deletions source/lmp/pair_deepmd_kokkos.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ PairStyle(deepmd/kk/host,PairDeepMDKokkos<LMPHostType>);

namespace LAMMPS_NS {

// LAMMPS 22Jul2025 exposes reverse-communication buffers as X_FLOAT; starting
// with 10Sep2025, Kokkos pair styles use a fixed double buffer.
#if LAMMPS_VERSION_NUMBER < 20250910
using DeepMDKokkosCommBuffer = DAT::tdual_xfloat_1d;
#else
using DeepMDKokkosCommBuffer = DAT::tdual_double_1d;
#endif

// GPU-resident inference for exported ``.pt2`` models whose forward consumes
// an explicit edge graph: both the graph-input form (a compact, unpadded
// neighbor graph) and the edge-input form. Both are dispatched through
Expand Down Expand Up @@ -64,10 +72,10 @@ class PairDeepMDKokkos : public PairDeepMD, public KokkosBase {
// host-staged path.
int pack_reverse_comm(int, int, double*) override;
void unpack_reverse_comm(int, int*, double*) override;
int pack_reverse_comm_kokkos(int, int, DAT::tdual_double_1d&) override;
int pack_reverse_comm_kokkos(int, int, DeepMDKokkosCommBuffer&) override;
void unpack_reverse_comm_kokkos(int,
DAT::tdual_int_1d,
DAT::tdual_double_1d&) override;
DeepMDKokkosCommBuffer&) override;

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

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

int edge_capacity; // allocated edges in d_edge_index / d_edge_vec
bool edge_vec_fp32; // model graph ABI consumes edge vectors in fp32
Expand Down
4 changes: 2 additions & 2 deletions source/lmp/pair_dpa4spin_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void PairDPA4SpinKokkos<DeviceType>::unpack_reverse_comm(int n,

template <class DeviceType>
int PairDPA4SpinKokkos<DeviceType>::pack_reverse_comm_kokkos(
int n, int first, DAT::tdual_double_1d& buf) {
int n, int first, DPA4SpinKokkosCommBuffer& buf) {
auto d_buf = buf.template view<DeviceType>();
if (reverse_virial) {
auto reverse_virial_data = k_reverse_virial.template view<DeviceType>();
Expand Down Expand Up @@ -147,7 +147,7 @@ int PairDPA4SpinKokkos<DeviceType>::pack_reverse_comm_kokkos(

template <class DeviceType>
void PairDPA4SpinKokkos<DeviceType>::unpack_reverse_comm_kokkos(
int n, DAT::tdual_int_1d list, DAT::tdual_double_1d& buf) {
int n, DAT::tdual_int_1d list, DPA4SpinKokkosCommBuffer& buf) {
auto d_buf = buf.template view<DeviceType>();
auto d_list = list.template view<DeviceType>();
if (reverse_virial) {
Expand Down
18 changes: 16 additions & 2 deletions source/lmp/pair_dpa4spin_kokkos.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ PairStyle(dpa4spin/kk/host,PairDPA4SpinKokkos<LMPHostType>);

namespace LAMMPS_NS {

// LAMMPS 22Jul2025 exposes reverse-communication buffers as X_FLOAT; starting
// with 10Sep2025, Kokkos pair styles use a fixed double buffer.
#if LAMMPS_VERSION_NUMBER < 20250910
using DPA4SpinKokkosCommBuffer = DAT::tdual_xfloat_1d;
#else
using DPA4SpinKokkosCommBuffer = DAT::tdual_double_1d;
#endif

// GPU-resident inference for exported native-spin ``.pt2`` models whose forward
// consumes the compact canonical graph: a dual-CSR neighbor topology with
// uint32 indices and float32 edge vectors, plus the per-node magnetic moment.
Expand Down Expand Up @@ -64,10 +72,10 @@ class PairDPA4SpinKokkos : public PairDPA4Spin, public KokkosBase {
// overrides serve the host-staged path.
int pack_reverse_comm(int, int, double*) override;
void unpack_reverse_comm(int, int*, double*) override;
int pack_reverse_comm_kokkos(int, int, DAT::tdual_double_1d&) override;
int pack_reverse_comm_kokkos(int, int, DPA4SpinKokkosCommBuffer&) override;
void unpack_reverse_comm_kokkos(int,
DAT::tdual_int_1d,
DAT::tdual_double_1d&) override;
DPA4SpinKokkosCommBuffer&) override;

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

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

bool reverse_virial; // reverse communication operates on centroid virial
bool reverse_used_host; // force reverse communication selected host staging
Expand Down
39 changes: 38 additions & 1 deletion source/lmp/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,44 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION)
find_package(Kokkos CONFIG REQUIRED)
target_compile_definitions(${libname} PRIVATE LMP_KOKKOS)
target_include_directories(${libname} PRIVATE ${LAMMPS_HEADER_DIR}/KOKKOS)
target_link_libraries(${libname} PUBLIC Kokkos::kokkos)

# A runtime LAMMPS plugin must use the Kokkos runtime already linked into
# liblammps. Linking the static Kokkos libraries here creates a second CUDA
# runtime instance and corrupts its shutdown state when the plugin is
# unloaded. Import only the compile/link flags needed for Kokkos device
# code; unresolved Kokkos symbols are resolved by liblammps at load time.
# Kokkos::kokkos is an umbrella target whose usage requirements may live
# only on its component targets, notably in LAMMPS build-tree packages. Copy
# those non-link properties without importing the static runtimes.
set(_kokkos_interface_targets
Kokkos::kokkos Kokkos::kokkoscore Kokkos::kokkoscontainers
Kokkos::kokkosalgorithms Kokkos::kokkossimd)
foreach(_kokkos_target IN LISTS _kokkos_interface_targets)
if(TARGET ${_kokkos_target})
foreach(_kokkos_property IN
ITEMS INCLUDE_DIRECTORIES COMPILE_DEFINITIONS COMPILE_OPTIONS
LINK_OPTIONS COMPILE_FEATURES)
get_target_property(_kokkos_value ${_kokkos_target}
INTERFACE_${_kokkos_property})
if(_kokkos_value)
list(APPEND _kokkos_${_kokkos_property} ${_kokkos_value})
endif()
endforeach()
endif()
endforeach()
target_include_directories(${libname} SYSTEM
PRIVATE ${_kokkos_INCLUDE_DIRECTORIES})
target_compile_definitions(${libname}
PRIVATE ${_kokkos_COMPILE_DEFINITIONS})
target_compile_options(${libname} PRIVATE ${_kokkos_COMPILE_OPTIONS})
target_link_options(${libname} PRIVATE ${_kokkos_LINK_OPTIONS})
target_compile_features(${libname} PRIVATE ${_kokkos_COMPILE_FEATURES})
if(TARGET Kokkos::CUDA)
target_link_libraries(${libname} PRIVATE Kokkos::CUDA)
endif()
if(TARGET Kokkos::LIBDL)
target_link_libraries(${libname} PRIVATE Kokkos::LIBDL)
endif()
endif()

# link: libdeepmd
Expand Down
Loading