From b3c403f46413a9408753e05a8c4679b77c098217 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 22 Jun 2025 18:12:52 -0400 Subject: [PATCH] run KOKKOS force style unit tests with serial when OpenMP is not available --- unittest/force-styles/test_angle_style.cpp | 7 ++++++- unittest/force-styles/test_bond_style.cpp | 7 ++++++- unittest/force-styles/test_dihedral_style.cpp | 11 +++++++--- unittest/force-styles/test_fix_timestep.cpp | 7 ++++++- unittest/force-styles/test_improper_style.cpp | 10 +++++++-- .../force-styles/test_mliappy_unified.cpp | 21 +++++++++++++++---- unittest/force-styles/test_pair_style.cpp | 11 +++++++--- 7 files changed, 59 insertions(+), 15 deletions(-) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index e24e5401df..b76a542172 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -550,7 +550,10 @@ TEST(AngleStyle, kokkos_omp) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -559,6 +562,8 @@ TEST(AngleStyle, kokkos_omp) LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[9] = "1"; ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 660435cf49..731aac9ef1 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -553,7 +553,10 @@ TEST(BondStyle, kokkos_omp) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -562,6 +565,8 @@ TEST(BondStyle, kokkos_omp) LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[9] = "1"; ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index b2f1a36346..31d89ba9e5 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -569,7 +569,10 @@ TEST(DihedralStyle, kokkos_omp) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -579,6 +582,8 @@ TEST(DihedralStyle, kokkos_omp) LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[9] = "1"; ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; @@ -773,8 +778,8 @@ TEST(DihedralStyle, extract) } auto *dihedral = lmp->force->dihedral; - void *ptr = nullptr; - int dim = 0; + void *ptr = nullptr; + int dim = 0; for (auto extract : test_config.extract) { ptr = dihedral->extract(extract.first.c_str(), dim); EXPECT_NE(ptr, nullptr); diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index d1bdee3535..133397ccdf 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -894,7 +894,10 @@ TEST(FixTimestep, kokkos_omp) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -903,6 +906,8 @@ TEST(FixTimestep, kokkos_omp) } LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[9] = "1"; ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 4a8c3d5106..b9534fabe3 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -547,6 +547,10 @@ TEST(ImproperStyle, kokkos_omp) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -556,6 +560,8 @@ TEST(ImproperStyle, kokkos_omp) LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[9] = "1"; ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; @@ -747,8 +753,8 @@ TEST(ImproperStyle, extract) } auto *improper = lmp->force->improper; - void *ptr = nullptr; - int dim = 0; + void *ptr = nullptr; + int dim = 0; for (auto extract : test_config.extract) { ptr = improper->extract(extract.first.c_str(), dim); EXPECT_NE(ptr, nullptr); diff --git a/unittest/force-styles/test_mliappy_unified.cpp b/unittest/force-styles/test_mliappy_unified.cpp index 412ea3b22a..c9e78b0cd4 100644 --- a/unittest/force-styles/test_mliappy_unified.cpp +++ b/unittest/force-styles/test_mliappy_unified.cpp @@ -114,10 +114,14 @@ TEST(MliapUnified, VersusLJMeltGhost) lammps_close(ljmelt); lammps_close(mliap); } + TEST(MliapUnified, VersusLJMeltKokkos) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -127,7 +131,9 @@ TEST(MliapUnified, VersusLJMeltKokkos) const char *lmpargv[] = {"melt", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; - int lmpargc = sizeof(lmpargv) / sizeof(const char *); + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) lmpargv[9] = "1"; + int lmpargc = sizeof(lmpargv) / sizeof(const char *); void *ljmelt = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr); void *mliap = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr); @@ -159,10 +165,14 @@ TEST(MliapUnified, VersusLJMeltKokkos) lammps_close(ljmelt); lammps_close(mliap); } + TEST(MliapUnified, VersusLJMeltGhostKokkos) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp") && + !Info::has_accelerator_feature("KOKKOS", "api", "serial")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -172,7 +182,10 @@ TEST(MliapUnified, VersusLJMeltGhostKokkos) const char *lmpargv[] = {"melt", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; - int lmpargc = sizeof(lmpargv) / sizeof(const char *); + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) lmpargv[9] = "1"; + + int lmpargc = sizeof(lmpargv) / sizeof(const char *); void *ljmelt = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr); void *mliap = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr); diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 6dabeab7a4..5484a5add6 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -650,7 +650,10 @@ TEST(PairStyle, kokkos_omp) { if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); + // test either OpenMP or Serial + if (!Info::has_accelerator_feature("KOKKOS", "api", "serial") && + !Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + GTEST_SKIP(); // if KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only. if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || Info::has_accelerator_feature("KOKKOS", "api", "hip") || @@ -660,6 +663,8 @@ TEST(PairStyle, kokkos_omp) LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-k", "on", "t", "4", "-sf", "kk"}; + // fall back to serial if openmp is not available + if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[9] = "1"; // cannot run dpd styles in plain or hybrid with more than 1 thread due to using multiple pRNGs if (utils::strmatch(test_config.pair_style, "^dpd") || @@ -854,8 +859,8 @@ TEST(PairStyle, gpu) epsilon *= 5.0e8; else epsilon *= 1.0e10; - // relax test precision when using pppm and single precision FFTs, but only when also - // running with double precision + // relax test precision when using pppm and single precision FFTs, but only when also + // running with double precision #if defined(FFT_SINGLE) if (lmp->force->kspace && lmp->force->kspace->compute_flag && Info::has_accelerator_feature("GPU", "precision", "double"))