small tweak to recover first initialization settings for consistent output

This commit is contained in:
Axel Kohlmeyer
2021-06-30 17:40:42 -04:00
parent d7a24dee91
commit b1d16508fe
3 changed files with 26 additions and 12 deletions

View File

@ -71,6 +71,7 @@ using namespace LAMMPS_NS;
Kokkos::InitArguments KokkosLMP::args{-1, -1, -1, false};
int KokkosLMP::is_finalized = 0;
int KokkosLMP::init_ngpus = 0;
/* ---------------------------------------------------------------------- */
@ -172,7 +173,23 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
} else error->all(FLERR,"Invalid Kokkos command-line args");
}
// initialize Kokkos
// Initialize Kokkos. However, we cannot change any
// Kokkos library parameters after the first initalization
if (args.num_threads != -1) {
if (args.num_threads != nthreads || args.num_numa != numa || args.device_id != device)
if (me == 0)
error->warning(FLERR,"Kokkos package already initalized, cannot reinitialize with different parameters");
nthreads = args.num_threads;
numa = args.num_numa;
device = args.device_id;
ngpus = init_ngpus;
} else {
args.num_threads = nthreads;
args.num_numa = numa;
args.device_id = device;
init_ngpus = ngpus;
}
if (me == 0)
utils::logmesg(lmp, " will use up to {} GPU(s) per node\n",ngpus);
@ -189,17 +206,6 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
"than the OpenMP backend");
#endif
// cannot change Kokkos library parameters after first initalization
if (args.num_threads != -1)
if (args.num_threads != nthreads || args.num_numa != numa || args.device_id != device)
if (me == 0)
error->warning(FLERR,"Kokkos package already initalized, cannot reinitialize with different parameters");
args.num_threads = nthreads;
args.num_numa = numa;
args.device_id = device;
KokkosLMP::initialize(args,error);
// default settings for package kokkos command

View File

@ -51,6 +51,7 @@ class KokkosLMP : protected Pointers {
static int is_finalized;
static Kokkos::InitArguments args;
static int init_ngpus;
KokkosLMP(class LAMMPS *, int, char **);
~KokkosLMP();

View File

@ -165,6 +165,13 @@ class PythonCapabilities(unittest.TestCase):
if self.cmake_cache['GPU_PREC'].lower() == 'single':
self.assertIn('single',settings['GPU']['precision'])
if self.cmake_cache['PKG_KOKKOS']:
if self.cmake_cache['Kokkos_ENABLE_OPENMP']:
self.assertIn('openmp',settings['KOKKOS']['api'])
if self.cmake_cache['Kokkos_ENABLE_SERIAL']:
self.assertIn('serial',settings['KOKKOS']['api'])
self.assertIn('double',settings['KOKKOS']['precision'])
def test_gpu_device(self):
info = self.lmp.get_gpu_device_info()