run KOKKOS force style unit tests with serial when OpenMP is not available

This commit is contained in:
Axel Kohlmeyer
2025-06-22 18:12:52 -04:00
parent 12dcaa2d03
commit b3c403f464
7 changed files with 59 additions and 15 deletions

View File

@ -550,7 +550,10 @@ TEST(AngleStyle, kokkos_omp)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -559,6 +562,8 @@ TEST(AngleStyle, kokkos_omp)
LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-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(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = nullptr; LAMMPS *lmp = nullptr;

View File

@ -553,7 +553,10 @@ TEST(BondStyle, kokkos_omp)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -562,6 +565,8 @@ TEST(BondStyle, kokkos_omp)
LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-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(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = nullptr; LAMMPS *lmp = nullptr;

View File

@ -569,7 +569,10 @@ TEST(DihedralStyle, kokkos_omp)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -579,6 +582,8 @@ TEST(DihedralStyle, kokkos_omp)
LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen",
"-nocite", "-k", "on", "t", "4", "-nocite", "-k", "on", "t", "4",
"-sf", "kk"}; "-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(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = nullptr; LAMMPS *lmp = nullptr;
@ -773,8 +778,8 @@ TEST(DihedralStyle, extract)
} }
auto *dihedral = lmp->force->dihedral; auto *dihedral = lmp->force->dihedral;
void *ptr = nullptr; void *ptr = nullptr;
int dim = 0; int dim = 0;
for (auto extract : test_config.extract) { for (auto extract : test_config.extract) {
ptr = dihedral->extract(extract.first.c_str(), dim); ptr = dihedral->extract(extract.first.c_str(), dim);
EXPECT_NE(ptr, nullptr); EXPECT_NE(ptr, nullptr);

View File

@ -894,7 +894,10 @@ TEST(FixTimestep, kokkos_omp)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -903,6 +906,8 @@ TEST(FixTimestep, kokkos_omp)
} }
LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-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(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = nullptr; LAMMPS *lmp = nullptr;

View File

@ -547,6 +547,10 @@ TEST(ImproperStyle, kokkos_omp)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -556,6 +560,8 @@ TEST(ImproperStyle, kokkos_omp)
LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen",
"-nocite", "-k", "on", "t", "4", "-nocite", "-k", "on", "t", "4",
"-sf", "kk"}; "-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(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = nullptr; LAMMPS *lmp = nullptr;
@ -747,8 +753,8 @@ TEST(ImproperStyle, extract)
} }
auto *improper = lmp->force->improper; auto *improper = lmp->force->improper;
void *ptr = nullptr; void *ptr = nullptr;
int dim = 0; int dim = 0;
for (auto extract : test_config.extract) { for (auto extract : test_config.extract) {
ptr = improper->extract(extract.first.c_str(), dim); ptr = improper->extract(extract.first.c_str(), dim);
EXPECT_NE(ptr, nullptr); EXPECT_NE(ptr, nullptr);

View File

@ -114,10 +114,14 @@ TEST(MliapUnified, VersusLJMeltGhost)
lammps_close(ljmelt); lammps_close(ljmelt);
lammps_close(mliap); lammps_close(mliap);
} }
TEST(MliapUnified, VersusLJMeltKokkos) TEST(MliapUnified, VersusLJMeltKokkos)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -127,7 +131,9 @@ TEST(MliapUnified, VersusLJMeltKokkos)
const char *lmpargv[] = {"melt", "-log", "none", "-echo", "screen", "-nocite", const char *lmpargv[] = {"melt", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-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 *ljmelt = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr);
void *mliap = 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(ljmelt);
lammps_close(mliap); lammps_close(mliap);
} }
TEST(MliapUnified, VersusLJMeltGhostKokkos) TEST(MliapUnified, VersusLJMeltGhostKokkos)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -172,7 +182,10 @@ TEST(MliapUnified, VersusLJMeltGhostKokkos)
const char *lmpargv[] = {"melt", "-log", "none", "-echo", "screen", "-nocite", const char *lmpargv[] = {"melt", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-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 *ljmelt = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr);
void *mliap = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr); void *mliap = lammps_open_no_mpi(lmpargc, (char **)lmpargv, nullptr);

View File

@ -650,7 +650,10 @@ TEST(PairStyle, kokkos_omp)
{ {
if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) 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 KOKKOS has GPU support enabled, it *must* be used. We cannot test OpenMP only.
if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") || if (Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
Info::has_accelerator_feature("KOKKOS", "api", "hip") || Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
@ -660,6 +663,8 @@ TEST(PairStyle, kokkos_omp)
LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-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 // 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") || if (utils::strmatch(test_config.pair_style, "^dpd") ||
@ -854,8 +859,8 @@ TEST(PairStyle, gpu)
epsilon *= 5.0e8; epsilon *= 5.0e8;
else else
epsilon *= 1.0e10; epsilon *= 1.0e10;
// relax test precision when using pppm and single precision FFTs, but only when also // relax test precision when using pppm and single precision FFTs, but only when also
// running with double precision // running with double precision
#if defined(FFT_SINGLE) #if defined(FFT_SINGLE)
if (lmp->force->kspace && lmp->force->kspace->compute_flag && if (lmp->force->kspace && lmp->force->kspace->compute_flag &&
Info::has_accelerator_feature("GPU", "precision", "double")) Info::has_accelerator_feature("GPU", "precision", "double"))