Feb2021 GPU Package Update - GPU Package Files

This commit is contained in:
Michael Brown
2021-02-15 08:20:50 -08:00
parent 16004e8f45
commit e7e2d2323b
345 changed files with 13424 additions and 7708 deletions

View File

@ -15,6 +15,7 @@
#include <cstring>
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "pair.h"
#include "pair_hybrid.h"
@ -38,14 +39,19 @@ using namespace FixConst;
enum{GPU_FORCE, GPU_NEIGH, GPU_HYB_NEIGH};
extern int lmp_init_device(MPI_Comm world, MPI_Comm replica,
const int first_gpu, const int last_gpu,
const int ngpu, const int first_gpu_id,
const int gpu_mode, const double particle_split,
const int nthreads, const int t_per_atom,
const double cell_size, char *opencl_flags,
const double cell_size, char *opencl_args,
const int ocl_platform, char *device_type_flags,
const int block_pair);
extern void lmp_clear_device();
extern double lmp_gpu_forces(double **f, double **tor, double *eatom,
double **vatom, double *virial, double &ecoul);
double **vatom, double *virial, double &ecoul,
int &err_flag);
extern double lmp_gpu_update_bin_size(const double subx, const double suby,
const double subz, const int nlocal,
const double cut);
static const char cite_gpu_package[] =
"GPU package (short-range, long-range and three-body potentials):\n\n"
@ -105,10 +111,13 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
if (narg < 4) error->all(FLERR,"Illegal package gpu command");
// If ngpu is 0, autoset ngpu to the number of devices per node matching
// best device
int ngpu = atoi(arg[3]);
if (ngpu <= 0) error->all(FLERR,"Illegal package gpu command");
int first_gpu = 0;
int last_gpu = ngpu-1;
if (ngpu < 0) error->all(FLERR,"Illegal package gpu command");
// Negative value indicate GPU package should find the best device ID
int first_gpu_id = -1;
// options
@ -118,9 +127,11 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
int newtonflag = 0;
int threads_per_atom = -1;
double binsize = 0.0;
char *opencl_flags = nullptr;
char *opencl_args = nullptr;
int block_pair = -1;
int pair_only_flag = 0;
int ocl_platform = -1;
char *device_type_flags = nullptr;
int iarg = 4;
while (iarg < narg) {
@ -149,10 +160,9 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Illegal package GPU command");
iarg += 2;
} else if (strcmp(arg[iarg],"gpuID") == 0) {
if (iarg+3 > narg) error->all(FLERR,"Illegal package gpu command");
first_gpu = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
last_gpu = utils::inumeric(FLERR,arg[iarg+2],false,lmp);
iarg += 3;
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
first_gpu_id = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
iarg += 2;
} else if (strcmp(arg[iarg],"tpa") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
threads_per_atom = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
@ -162,9 +172,13 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
nthreads = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
if (nthreads < 1) error->all(FLERR,"Illegal fix GPU command");
iarg += 2;
} else if (strcmp(arg[iarg],"device") == 0) {
} else if (strcmp(arg[iarg],"platform") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
opencl_flags = arg[iarg+1];
ocl_platform = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
iarg += 2;
} else if (strcmp(arg[iarg],"device_type") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
device_type_flags = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"blocksize") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
@ -176,10 +190,14 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
else if (strcmp(arg[iarg+1],"on") == 0) pair_only_flag = 1;
else error->all(FLERR,"Illegal package gpu command");
iarg += 2;
} else if (strcmp(arg[iarg],"ocl_args") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal package gpu command");
opencl_args = arg[iarg+1];
iarg += 2;
} else error->all(FLERR,"Illegal package gpu command");
}
#ifndef _OPENMP
#if (LAL_USE_OMP == 0)
if (nthreads > 1)
error->all(FLERR,"No OpenMP support compiled in");
#endif
@ -207,10 +225,11 @@ FixGPU::FixGPU(LAMMPS *lmp, int narg, char **arg) :
// change binsize default (0.0) to -1.0 used by GPU lib
if (binsize == 0.0) binsize = -1.0;
int gpu_flag = lmp_init_device(universe->uworld, world, first_gpu, last_gpu,
_binsize = binsize;
int gpu_flag = lmp_init_device(universe->uworld, world, ngpu, first_gpu_id,
_gpu_mode, _particle_split, nthreads,
threads_per_atom, binsize, opencl_flags,
block_pair);
threads_per_atom, binsize, opencl_args,
ocl_platform, device_type_flags, block_pair);
GPU_EXTRA::check_flag(gpu_flag,error,world);
}
@ -296,9 +315,15 @@ void FixGPU::post_force(int /* vflag */)
timer->stamp();
double lvirial[6];
for (int i = 0; i < 6; i++) lvirial[i] = 0.0;
int err_flag;
double my_eng = lmp_gpu_forces(atom->f, atom->torque, force->pair->eatom,
force->pair->vatom, lvirial,
force->pair->eng_coul);
force->pair->eng_coul, err_flag);
if (err_flag) {
if (err_flag==1)
error->one(FLERR,
"Too many neighbors on GPU. Use neigh_modify one to increase limit.");
}
force->pair->eng_vdwl += my_eng;
force->pair->virial[0] += lvirial[0];
@ -335,3 +360,12 @@ double FixGPU::memory_usage()
return bytes;
}
double FixGPU::binsize(const double subx, const double suby,
const double subz, const int nlocal,
const double cut) {
if (_binsize > 0.0) return _binsize;
else if (_gpu_mode == GPU_FORCE || comm->cutghostuser)
return cut * 0.5;
else
return lmp_gpu_update_bin_size(subx, suby, subz, nlocal, cut);
}