diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 49bb6369d1..2588bf5d49 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -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 diff --git a/src/KOKKOS/kokkos.h b/src/KOKKOS/kokkos.h index fbea17388d..65990544ad 100644 --- a/src/KOKKOS/kokkos.h +++ b/src/KOKKOS/kokkos.h @@ -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(); diff --git a/unittest/python/python-capabilities.py b/unittest/python/python-capabilities.py index 2ace093a7e..8a3fbbd665 100644 --- a/unittest/python/python-capabilities.py +++ b/unittest/python/python-capabilities.py @@ -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()