When KOKKOS has been compiled with GPU support the GPU *must* be used

This commit is contained in:
Axel Kohlmeyer
2024-07-30 10:35:15 -04:00
parent bd2e071ef0
commit a5a0620dca
5 changed files with 93 additions and 14 deletions

View File

@ -2,10 +2,12 @@
#include "lammps.h"
#define LAMMPS_LIB_MPI 1
#include "info.h"
#include "library.h"
#include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@ -78,9 +80,38 @@ TEST(lammps_open, with_args)
TEST(lammps_open, with_kokkos)
{
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none", nullptr};
char **argv = (char **)args;
int argc = (sizeof(args) / sizeof(char *)) - 1;
std::vector<char *> args = {(char *)"lammps", (char *)"-log", (char *)"none", (char *)"-echo",
(char *)"screen", (char *)"-sf", (char *)"kk"};
char *one = (char *)"1";
char *four = (char *)"4";
char *tee = (char *)"t";
char *gee = (char *)"g";
char *kay = (char *)"-k";
char *yes = (char *)"on";
args.push_back(kay);
args.push_back(yes);
// when GPU support is enabled in KOKKOS, it *must* be used
if (lammps_config_accelerator("KOKKOS", "api", "hip") ||
lammps_config_accelerator("KOKKOS", "api", "cuda") ||
lammps_config_accelerator("KOKKOS", "api", "sycl")) {
args.push_back(gee);
args.push_back(one);
}
// use threads or serial
args.push_back(tee);
if (lammps_config_accelerator("KOKKOS", "api", "openmp")) {
args.push_back(four);
} else if (lammps_config_accelerator("KOKKOS", "api", "pthreads")) {
args.push_back(four);
} else {
args.push_back(one);
}
int argc = args.size();
char **argv = args.data();
::testing::internal::CaptureStdout();
void *alt_ptr;