forked from lijiext/lammps
When KOKKOS has been compiled with GPU support the GPU *must* be used
This commit is contained in:
parent
bd2e071ef0
commit
a5a0620dca
|
@ -3,6 +3,7 @@
|
|||
add_executable(test_library_open test_library_open.cpp test_main.cpp)
|
||||
target_link_libraries(test_library_open PRIVATE lammps GTest::GMock)
|
||||
add_test(NAME LibraryOpen COMMAND test_library_open)
|
||||
set_tests_properties(LibraryOpen PROPERTIES ENVIRONMENT "OMP_NUM_THREADS=4;OMP_PROC_BIND=false")
|
||||
|
||||
add_executable(test_library_commands test_library_commands.cpp test_main.cpp)
|
||||
target_link_libraries(test_library_commands PRIVATE lammps GTest::GMock)
|
||||
|
@ -16,7 +17,7 @@ add_executable(test_library_properties test_library_properties.cpp test_main.cpp
|
|||
target_link_libraries(test_library_properties PRIVATE lammps GTest::GMock)
|
||||
target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_test(NAME LibraryProperties COMMAND test_library_properties)
|
||||
set_tests_properties(LibraryProperties PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(LibraryProperties PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};OMP_NUM_THREADS=4;OMP_PROC_BIND=false")
|
||||
|
||||
add_executable(test_library_objects test_library_objects.cpp test_main.cpp)
|
||||
target_link_libraries(test_library_objects PRIVATE lammps GTest::GMock)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "lmptype.h"
|
||||
#include "platform.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
@ -742,14 +743,45 @@ TEST_F(AtomProperties, position)
|
|||
TEST(SystemSettings, kokkos)
|
||||
{
|
||||
if (!lammps_config_has_package("KOKKOS")) GTEST_SKIP();
|
||||
if (!lammps_config_accelerator("KOKKOS", "api", "openmp")) GTEST_SKIP();
|
||||
std::vector<char *> args = {(char *)"lammps", (char *)"-log", (char *)"none",
|
||||
(char *)"-echo", (char *)"screen", (char *)"-nocite",
|
||||
(char *)"-sf", (char *)"kk"};
|
||||
|
||||
// clang-format off
|
||||
const char *args[] = {"SystemSettings", "-log", "none", "-echo", "screen", "-nocite",
|
||||
"-k", "on", "t", "4", "-sf", "kk", nullptr};
|
||||
// clang-format on
|
||||
char **argv = (char **)args;
|
||||
int argc = (sizeof(args) / sizeof(char *)) - 1;
|
||||
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);
|
||||
|
||||
bool has_gpu = false;
|
||||
bool has_threads = false;
|
||||
|
||||
// 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")) {
|
||||
has_gpu = true;
|
||||
args.push_back(gee);
|
||||
args.push_back(one);
|
||||
}
|
||||
|
||||
// use threads or serial
|
||||
args.push_back(tee);
|
||||
if (lammps_config_accelerator("KOKKOS", "api", "openmp")) {
|
||||
has_threads = true;
|
||||
args.push_back(four);
|
||||
} else if (lammps_config_accelerator("KOKKOS", "api", "pthreads")) {
|
||||
has_threads = true;
|
||||
args.push_back(four);
|
||||
} else {
|
||||
args.push_back(one);
|
||||
}
|
||||
int argc = args.size();
|
||||
char **argv = args.data();
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
void *lmp = lammps_open_no_mpi(argc, argv, nullptr);
|
||||
|
@ -758,7 +790,13 @@ TEST(SystemSettings, kokkos)
|
|||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_active"), 1);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_nthreads"), 4);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_ngpus"), 0);
|
||||
if (has_threads)
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_nthreads"), 4);
|
||||
else
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_nthreads"), 1);
|
||||
if (has_gpu)
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_ngpus"), 1);
|
||||
else
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "kokkos_ngpus"), 0);
|
||||
lammps_close(lmp);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
add_executable(test_lammps_class test_lammps_class.cpp)
|
||||
target_link_libraries(test_lammps_class PRIVATE lammps GTest::GMockMain)
|
||||
add_test(NAME LammpsClass COMMAND test_lammps_class)
|
||||
set_tests_properties(LammpsClass PROPERTIES ENVIRONMENT "OMP_NUM_THREADS=1")
|
||||
set_tests_properties(LammpsClass PROPERTIES ENVIRONMENT "OMP_NUM_THREADS=2;OMP_PROC_BIND=false")
|
||||
|
||||
add_executable(test_input_class test_input_class.cpp)
|
||||
target_link_libraries(test_input_class PRIVATE lammps GTest::GTestMain)
|
||||
|
|
|
@ -253,6 +253,15 @@ protected:
|
|||
{
|
||||
LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none",
|
||||
"-k", "on", "t", "1", "-sf", "kk"};
|
||||
|
||||
// when GPU support is enabled in KOKKOS, it *must* be used
|
||||
if (Info::has_accelerator_feature("KOKKOS", "api", "hip") ||
|
||||
Info::has_accelerator_feature("KOKKOS", "api", "cuda") ||
|
||||
Info::has_accelerator_feature("KOKKOS", "api", "sycl")) {
|
||||
args = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none", "-k",
|
||||
"on", "t", "1", "g", "1", "-sf", "kk"};
|
||||
}
|
||||
|
||||
if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[10] = "2";
|
||||
|
||||
if (LAMMPS::is_installed_pkg("KOKKOS")) {
|
||||
|
|
Loading…
Reference in New Issue