diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 2a83b40bba..49bb6369d1 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -69,6 +69,7 @@ GPU_AWARE_UNKNOWN using namespace LAMMPS_NS; +Kokkos::InitArguments KokkosLMP::args{-1, -1, -1, false}; int KokkosLMP::is_finalized = 0; /* ---------------------------------------------------------------------- */ @@ -157,6 +158,10 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"t") == 0 || strcmp(arg[iarg],"threads") == 0) { nthreads = atoi(arg[iarg+1]); + + if (nthreads <= 0) + error->all(FLERR,"Invalid number of threads requested for Kokkos: must be 1 or greater"); + iarg += 2; } else if (strcmp(arg[iarg],"n") == 0 || @@ -184,7 +189,13 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) "than the OpenMP backend"); #endif - Kokkos::InitArguments args; + // 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; diff --git a/src/KOKKOS/kokkos.h b/src/KOKKOS/kokkos.h index a62666ba2a..fbea17388d 100644 --- a/src/KOKKOS/kokkos.h +++ b/src/KOKKOS/kokkos.h @@ -50,6 +50,7 @@ class KokkosLMP : protected Pointers { double binsize; static int is_finalized; + static Kokkos::InitArguments args; KokkosLMP(class LAMMPS *, int, char **); ~KokkosLMP(); @@ -88,13 +89,21 @@ because MPI library not recognized The local MPI rank was not found in one of four supported environment variables. +E: Invalid number of threads requested for Kokkos: must be 1 or greater + +Self-explanatory. + E: GPUs are requested but Kokkos has not been compiled for CUDA Recompile Kokkos with CUDA support to use GPUs. -E: Kokkos has been compiled for CUDA but no GPUs are requested +E: Kokkos has been compiled for CUDA, HIP, or SYCL but no GPUs are requested -One or more GPUs must be used when Kokkos is compiled for CUDA. +One or more GPUs must be used when Kokkos is compiled for CUDA/HIP/SYCL. + +W: Kokkos package already initalized, cannot reinitialize with different parameters + +Self-explanatory. E: Illegal ... command