From 4fa20bbdb5cea342cfc6263e74100b54aab45932 Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:46:57 +0800 Subject: [PATCH 1/5] fix(lammps): register Kokkos pair style in plugin Agent: ChatGPT Model: GPT-5.6 Sol --- source/lmp/plugin/deepmdplugin.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/lmp/plugin/deepmdplugin.cpp b/source/lmp/plugin/deepmdplugin.cpp index b49b034c41..b4474d8499 100644 --- a/source/lmp/plugin/deepmdplugin.cpp +++ b/source/lmp/plugin/deepmdplugin.cpp @@ -8,6 +8,9 @@ #include "fix_dplr.h" #include "lammpsplugin.h" #include "pair_deepmd.h" +#ifdef LMP_KOKKOS +#include "pair_deepmd_kokkos.h" +#endif #include "pair_deepspin.h" #include "version.h" #if LAMMPS_VERSION_NUMBER >= 20220328 @@ -17,6 +20,11 @@ using namespace LAMMPS_NS; static Pair* pairdeepmd(LAMMPS* lmp) { return new PairDeepMD(lmp); } +#ifdef LMP_KOKKOS +static Pair* pairdeepmdkokkos(LAMMPS* lmp) { + return new PairDeepMDKokkos(lmp); +} +#endif static Pair* pairdeepspin(LAMMPS* lmp) { return new PairDeepSpin(lmp); } static Compute* computedeepmdtensoratom(LAMMPS* lmp, int narg, char** arg) { @@ -48,6 +56,26 @@ extern "C" void lammpsplugin_init(void* lmp, void* handle, void* regfunc) { plugin.handle = handle; (*register_plugin)(&plugin, lmp); +#ifdef LMP_KOKKOS + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "deepmd/kk"; + plugin.info = "deepmd Kokkos pair style " STR_GIT_SUMM; + plugin.author = "DeepModeling"; + plugin.creator.v1 = (lammpsplugin_factory1*)&pairdeepmdkokkos; + plugin.handle = handle; + (*register_plugin)(&plugin, lmp); + + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "deepmd/kk/device"; + plugin.info = "deepmd Kokkos device pair style " STR_GIT_SUMM; + plugin.author = "DeepModeling"; + plugin.creator.v1 = (lammpsplugin_factory1*)&pairdeepmdkokkos; + plugin.handle = handle; + (*register_plugin)(&plugin, lmp); +#endif + plugin.version = LAMMPS_VERSION; plugin.style = "pair"; plugin.name = "deepspin"; From 44d9b3c7f6657eb409bac0505fc4bf64c4c95a5a Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:47:23 +0800 Subject: [PATCH 2/5] build: expose Kokkos LAMMPS plugin option Agent: ChatGPT Model: GPT-5.6 Sol --- backend/read_env.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/read_env.py b/backend/read_env.py index 5abb026024..28bba0e785 100644 --- a/backend/read_env.py +++ b/backend/read_env.py @@ -72,6 +72,7 @@ def get_argument_from_env() -> tuple[str, list, list, dict, str, str]: if os.environ.get("DP_ENABLE_NATIVE_OPTIMIZATION", "0") == "1": cmake_args.append("-DENABLE_NATIVE_OPTIMIZATION:BOOL=TRUE") dp_lammps_version = os.environ.get("DP_LAMMPS_VERSION", "") + dp_lammps_kokkos = os.environ.get("DP_ENABLE_LAMMPS_KOKKOS", "0") dp_ipi = os.environ.get("DP_ENABLE_IPI", "0") if dp_lammps_version != "" or dp_ipi == "1": cmake_args.append("-DBUILD_CPP_IF:BOOL=TRUE") @@ -81,6 +82,13 @@ def get_argument_from_env() -> tuple[str, list, list, dict, str, str]: if dp_lammps_version != "": cmake_args.append(f"-DLAMMPS_VERSION={dp_lammps_version}") + if dp_lammps_kokkos == "1": + if dp_lammps_version == "": + raise RuntimeError( + "DP_ENABLE_LAMMPS_KOKKOS=1 requires DP_LAMMPS_VERSION to build " + "the LAMMPS plugin" + ) + cmake_args.append("-DDEEPMD_LAMMPS_KOKKOS:BOOL=TRUE") if dp_ipi == "1": cmake_args.append("-DENABLE_IPI:BOOL=TRUE") extra_scripts["dp_ipi"] = "deepmd.entrypoints.ipi:dp_ipi" From 5dfbff160de9f93e1fc3915bde95eed015585be3 Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:50:50 +0800 Subject: [PATCH 3/5] test(build): cover LAMMPS Kokkos build toggle Agent: ChatGPT Model: GPT-5.6 Sol --- source/tests/common/test_build_backend.py | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 source/tests/common/test_build_backend.py diff --git a/source/tests/common/test_build_backend.py b/source/tests/common/test_build_backend.py new file mode 100644 index 0000000000..97ffdd0f06 --- /dev/null +++ b/source/tests/common/test_build_backend.py @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later + +import pytest + +from backend.read_env import ( + get_argument_from_env, +) + + +def _disable_ml_backends(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("DP_ENABLE_TENSORFLOW", "0") + monkeypatch.setenv("DP_ENABLE_PYTORCH", "0") + + +def test_lammps_kokkos_build_flag(monkeypatch: pytest.MonkeyPatch) -> None: + _disable_ml_backends(monkeypatch) + monkeypatch.setenv("DP_LAMMPS_VERSION", "stable_22Jul2025_update4") + monkeypatch.setenv("DP_ENABLE_LAMMPS_KOKKOS", "1") + get_argument_from_env.cache_clear() + + _, cmake_args, _, _, _, _ = get_argument_from_env() + + assert "-DDEEPMD_LAMMPS_KOKKOS:BOOL=TRUE" in cmake_args + + +def test_lammps_kokkos_requires_plugin(monkeypatch: pytest.MonkeyPatch) -> None: + _disable_ml_backends(monkeypatch) + monkeypatch.delenv("DP_LAMMPS_VERSION", raising=False) + monkeypatch.setenv("DP_ENABLE_LAMMPS_KOKKOS", "1") + get_argument_from_env.cache_clear() + + with pytest.raises(RuntimeError, match="requires DP_LAMMPS_VERSION"): + get_argument_from_env() From 6a6394fae05477d61963822da4ed354e50a09632 Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:51:11 +0800 Subject: [PATCH 4/5] test(build): isolate build backend environment cache Agent: ChatGPT Model: GPT-5.6 Sol --- source/tests/common/test_build_backend.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/tests/common/test_build_backend.py b/source/tests/common/test_build_backend.py index 97ffdd0f06..2f81dc3a98 100644 --- a/source/tests/common/test_build_backend.py +++ b/source/tests/common/test_build_backend.py @@ -7,6 +7,13 @@ ) +@pytest.fixture(autouse=True) +def _clear_read_env_cache(): + get_argument_from_env.cache_clear() + yield + get_argument_from_env.cache_clear() + + def _disable_ml_backends(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("DP_ENABLE_TENSORFLOW", "0") monkeypatch.setenv("DP_ENABLE_PYTORCH", "0") @@ -16,7 +23,6 @@ def test_lammps_kokkos_build_flag(monkeypatch: pytest.MonkeyPatch) -> None: _disable_ml_backends(monkeypatch) monkeypatch.setenv("DP_LAMMPS_VERSION", "stable_22Jul2025_update4") monkeypatch.setenv("DP_ENABLE_LAMMPS_KOKKOS", "1") - get_argument_from_env.cache_clear() _, cmake_args, _, _, _, _ = get_argument_from_env() @@ -27,7 +33,6 @@ def test_lammps_kokkos_requires_plugin(monkeypatch: pytest.MonkeyPatch) -> None: _disable_ml_backends(monkeypatch) monkeypatch.delenv("DP_LAMMPS_VERSION", raising=False) monkeypatch.setenv("DP_ENABLE_LAMMPS_KOKKOS", "1") - get_argument_from_env.cache_clear() with pytest.raises(RuntimeError, match="requires DP_LAMMPS_VERSION"): get_argument_from_env() From 0f8e3bb61ca3bcd254b0074e26a537e4691da9f6 Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:54:37 +0800 Subject: [PATCH 5/5] build(lammps): use Kokkos compiler launcher for plugin Agent: ChatGPT Model: GPT-5.6 Sol --- source/lmp/plugin/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index 8dcbe6dd59..cd21d149e0 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -123,6 +123,7 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) target_compile_definitions(${libname} PRIVATE LMP_KOKKOS) target_include_directories(${libname} PRIVATE ${LAMMPS_HEADER_DIR}/KOKKOS) target_link_libraries(${libname} PUBLIC Kokkos::kokkos) + kokkos_compilation(TARGET ${libname}) endif() # link: libdeepmd