git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15248 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2016-07-01 23:27:26 +00:00
parent 8366b35459
commit 9656958169
245 changed files with 4890 additions and 4832 deletions

View File

@ -9,10 +9,10 @@
This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
__________________________________________________________________________
begin :
begin :
email : brownw@ornl.gov nguyentd@ornl.gov
***************************************************************************/
#if defined(USE_OPENCL)
#include "eam_cl.h"
#elif defined(USE_CUDART)
@ -33,7 +33,7 @@ using namespace LAMMPS_AL;
extern Device<PRECISION,ACC_PRECISION> device;
template <class numtyp, class acctyp>
EAMT::EAM() : BaseAtomic<numtyp,acctyp>(),
EAMT::EAM() : BaseAtomic<numtyp,acctyp>(),
_compiled_energy(false), _allocated(false) {
}
@ -41,46 +41,46 @@ template <class numtyp, class acctyp>
EAMT::~EAM() {
clear();
}
template <class numtyp, class acctyp>
int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
int **host_type2z2r, int *host_type2frho,
double ***host_rhor_spline, double ***host_z2r_spline,
double ***host_frho_spline, double rdr, double rdrho,
double ***host_frho_spline, double rdr, double rdrho,
double rhomax, int nrhor, int nrho, int nz2r, int nfrho, int nr,
const int nlocal, const int nall, const int max_nbors,
const int maxspecial, const double cell_size,
const double gpu_split, FILE *_screen)
const int maxspecial, const double cell_size,
const double gpu_split, FILE *_screen)
{
int success;
success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,
gpu_split,_screen,eam,"k_eam");
if (success!=0)
return success;
// allocate fp
int ef_nall=nall;
if (ef_nall==0)
ef_nall=2000;
_max_fp_size=static_cast<int>(static_cast<double>(ef_nall)*1.10);
_fp.alloc(_max_fp_size,*(this->ucl_device),UCL_READ_WRITE,UCL_READ_WRITE);
k_energy.set_function(*(this->pair_program),"k_energy");
k_energy_fast.set_function(*(this->pair_program),"k_energy_fast");
fp_tex.get_texture(*(this->pair_program),"fp_tex");
fp_tex.bind_float(_fp,1);
_compiled_energy = true;
// Initialize timers for selected GPU
time_pair2.init(*(this->ucl_device));
time_pair2.zero();
time_fp1.init(*(this->ucl_device));
time_fp1.zero();
time_fp2.init(*(this->ucl_device));
time_fp2.zero();
@ -93,7 +93,7 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
lj_types=max_shared_types;
shared_types=true;
}
_ntypes=lj_types;
_cutforcesq=host_cutforcesq;
_rdr=rdr;
@ -104,26 +104,26 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
_nz2r=nz2r;
_nfrho=nfrho;
_nr=nr;
UCL_H_Vec<int2> dview_type(lj_types*lj_types,*(this->ucl_device),
UCL_WRITE_ONLY);
for (int i=0; i<lj_types*lj_types; i++) {
dview_type[i].x=0; dview_type[i].y=0;
}
// pack type2rhor and type2z2r
type2rhor_z2r.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
for (int i=0; i<ntypes; i++) {
for (int j=0; j<ntypes; j++) {
dview_type[i*lj_types+j].x=host_type2rhor[i][j];
dview_type[i*lj_types+j].y=host_type2z2r[i][j];
}
}
ucl_copy(type2rhor_z2r,dview_type,false);
// pack type2frho
UCL_H_Vec<int> dview_type2frho(lj_types,*(this->ucl_device),
UCL_WRITE_ONLY);
@ -136,7 +136,7 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
// pack frho_spline
UCL_H_Vec<numtyp4> dview_frho_spline(nfrho*(nrho+1),*(this->ucl_device),
UCL_WRITE_ONLY);
for (int ix=0; ix<nfrho; ix++)
for (int iy=0; iy<nrho+1; iy++) {
dview_frho_spline[ix*(nrho+1)+iy].x=host_frho_spline[ix][iy][0];
@ -166,7 +166,7 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
// pack rhor_spline
UCL_H_Vec<numtyp4> dview_rhor_spline(nrhor*(nr+1),*(this->ucl_device),
UCL_WRITE_ONLY);
for (int ix=0; ix<nrhor; ix++)
for (int iy=0; iy<nr+1; iy++) {
dview_rhor_spline[ix*(nr+1)+iy].x=host_rhor_spline[ix][iy][0];
@ -196,7 +196,7 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
// pack z2r_spline
UCL_H_Vec<numtyp4> dview_z2r_spline(nz2r*(nr+1),*(this->ucl_device),
UCL_WRITE_ONLY);
for (int ix=0; ix<nz2r; ix++)
for (int iy=0; iy<nr+1; iy++) {
dview_z2r_spline[ix*(nr+1)+iy].x=host_z2r_spline[ix][iy][0];
@ -204,12 +204,12 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
dview_z2r_spline[ix*(nr+1)+iy].z=host_z2r_spline[ix][iy][2];
dview_z2r_spline[ix*(nr+1)+iy].w=(numtyp)0;
}
z2r_spline1.alloc(nz2r*(nr+1),*(this->ucl_device),UCL_READ_ONLY);
ucl_copy(z2r_spline1,dview_z2r_spline,false);
z2r_spline1_tex.get_texture(*(this->pair_program),"z2r_sp1_tex");
z2r_spline1_tex.bind_float(z2r_spline1,4);
for (int ix=0; ix<nz2r; ix++)
for (int iy=0; iy<nr+1; iy++) {
dview_z2r_spline[ix*(nr+1)+iy].x=host_z2r_spline[ix][iy][3];
@ -217,7 +217,7 @@ int EAMT::init(const int ntypes, double host_cutforcesq, int **host_type2rhor,
dview_z2r_spline[ix*(nr+1)+iy].z=host_z2r_spline[ix][iy][5];
dview_z2r_spline[ix*(nr+1)+iy].w=host_z2r_spline[ix][iy][6];
}
z2r_spline2.alloc(nz2r*(nr+1),*(this->ucl_device),UCL_READ_ONLY);
ucl_copy(z2r_spline2,dview_z2r_spline,false);
z2r_spline2_tex.get_texture(*(this->pair_program),"z2r_sp2_tex");
@ -241,7 +241,7 @@ void EAMT::clear() {
if (!_allocated)
return;
_allocated=false;
type2rhor_z2r.clear();
type2frho.clear();
rhor_spline1.clear();
@ -250,13 +250,13 @@ void EAMT::clear() {
frho_spline2.clear();
z2r_spline1.clear();
z2r_spline2.clear();
_fp.clear();
time_pair2.clear();
time_fp1.clear();
time_fp2.clear();
if (_compiled_energy) {
k_energy_fast.clear();
k_energy.clear();
@ -283,20 +283,20 @@ void EAMT::compute(const int f_ago, const int inum_full, const int nlocal,
int &host_start, const double cpu_time,
bool &success, void **fp_ptr) {
this->acc_timers();
if (this->device->time_device()) {
// Put time from the second part to the total time_pair
this->time_pair.add_time_to_total(time_pair2.time());
// Add transfer time from device -> host after part 1
this->atom->add_transfer_time(time_fp1.time());
// Add transfer time from host -> device before part 2
this->atom->add_transfer_time(time_fp2.time());
}
// ------------------- Resize FP Array for EAM --------------------
if (nall>_max_fp_size) {
_max_fp_size=static_cast<int>(static_cast<double>(nall)*1.10);
_fp.resize(_max_fp_size);
@ -313,7 +313,7 @@ void EAMT::compute(const int f_ago, const int inum_full, const int nlocal,
this->zero_timers();
return;
}
int ago=this->hd_balancer.ago_first(f_ago);
int inum=this->hd_balancer.balance(ago,inum_full,cpu_time);
this->ans->inum(inum);
@ -326,7 +326,7 @@ void EAMT::compute(const int f_ago, const int inum_full, const int nlocal,
if (!success)
return;
}
this->atom->cast_x_data(host_x,host_type);
this->atom->add_x_data(host_x,host_type);
@ -345,36 +345,36 @@ void EAMT::compute(const int f_ago, const int inum_full, const int nlocal,
// ---------------------------------------------------------------------------
template <class numtyp, class acctyp>
int** EAMT::compute(const int ago, const int inum_full, const int nall,
double **host_x, int *host_type, double *sublo,
double **host_x, int *host_type, double *sublo,
double *subhi, tagint *tag, int **nspecial, tagint **special,
const bool eflag, const bool vflag, const bool eatom,
const bool vatom, int &host_start, int **ilist, int **jnum,
const double cpu_time, bool &success, int &inum,
const double cpu_time, bool &success, int &inum,
void **fp_ptr) {
this->acc_timers();
if (this->device->time_device()) {
// Put time from the second part to the total time_pair
this->time_pair.add_time_to_total(time_pair2.time());
// Add transfer time from device -> host after part 1
this->atom->add_transfer_time(time_fp1.time());
// Add transfer time from host -> device before part 2
this->atom->add_transfer_time(time_fp2.time());
}
// ------------------- Resize FP Array for EAM --------------------
if (nall>_max_fp_size) {
_max_fp_size=static_cast<int>(static_cast<double>(nall)*1.10);
_fp.resize(_max_fp_size);
fp_tex.bind_float(_fp,1);
}
*fp_ptr=_fp.host.begin();
}
*fp_ptr=_fp.host.begin();
// -----------------------------------------------------------------
if (inum_full==0) {
host_start=0;
// Make sure textures are correct if realloc by a different hybrid style
@ -382,14 +382,14 @@ int** EAMT::compute(const int ago, const int inum_full, const int nall,
this->zero_timers();
return NULL;
}
// load balance, returning the atom count on the device (inum)
this->hd_balancer.balance(cpu_time);
inum=this->hd_balancer.get_gpu_count(ago,inum_full);
this->ans->inum(inum);
host_start=inum;
// Build neighbor list on GPU if necessary
// Build neighbor list on GPU if necessary
if (ago==0) {
this->build_nbor_list(inum, inum_full-inum, nall, host_x, host_type,
sublo, subhi, tag, nspecial, special, success);
@ -403,14 +403,14 @@ int** EAMT::compute(const int ago, const int inum_full, const int nall,
*jnum=this->nbor->host_acc.begin();
loop(eflag,vflag);
// copy fp from device to host for comm
_nlocal=inum_full;
time_fp1.start();
_fp.update_host(inum_full,true);
time_fp1.stop();
time_fp1.sync_stop();
return this->nbor->host_jlist.begin()-host_start;
}
@ -420,20 +420,20 @@ int** EAMT::compute(const int ago, const int inum_full, const int nall,
template <class numtyp, class acctyp>
void EAMT::compute2(int *ilist, const bool eflag, const bool vflag,
const bool eatom, const bool vatom) {
if (this->ans->inum()==0)
if (this->ans->inum()==0)
return;
this->hd_balancer.start_timer();
time_fp2.start();
this->add_fp_data();
time_fp2.stop();
loop2(eflag,vflag);
if (ilist == NULL)
this->ans->copy_answers(eflag,vflag,eatom,vatom);
else
this->ans->copy_answers(eflag,vflag,eatom,vatom, ilist);
this->device->add_ans_object(this->ans);
this->hd_balancer.stop_timer();
}
@ -455,27 +455,27 @@ void EAMT::loop(const bool _eflag, const bool _vflag) {
vflag=1;
else
vflag=0;
int GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/
(BX/this->_threads_per_atom)));
int ainum=this->ans->inum();
int nbor_pitch=this->nbor->nbor_pitch();
this->time_pair.start();
if (shared_types) {
this->k_energy_fast.set_size(GX,BX);
this->k_energy_fast.run(&this->atom->x, &type2rhor_z2r, &type2frho,
&rhor_spline2, &frho_spline1,&frho_spline2,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&rhor_spline2, &frho_spline1,&frho_spline2,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&_fp, &this->ans->engv, &eflag, &ainum,
&nbor_pitch, &_ntypes, &_cutforcesq, &_rdr, &_rdrho,
&_rhomax, &_nrho, &_nr, &this->_threads_per_atom);
} else {
this->k_energy.set_size(GX,BX);
this->k_energy.run(&this->atom->x, &type2rhor_z2r, &type2frho,
&rhor_spline2, &frho_spline1, &frho_spline2,
&this->nbor->dev_nbor, &this->_nbor_data->begin(), &_fp,
&rhor_spline2, &frho_spline1, &frho_spline2,
&this->nbor->dev_nbor, &this->_nbor_data->begin(), &_fp,
&this->ans->engv,&eflag, &ainum, &nbor_pitch,
&_ntypes, &_cutforcesq, &_rdr, &_rdrho, &_rhomax, &_nrho,
&_nr, &this->_threads_per_atom);
@ -501,25 +501,25 @@ void EAMT::loop2(const bool _eflag, const bool _vflag) {
vflag=1;
else
vflag=0;
int GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/
(BX/this->_threads_per_atom)));
int ainum=this->ans->inum();
int nbor_pitch=this->nbor->nbor_pitch();
this->time_pair2.start();
if (shared_types) {
this->k_pair_fast.set_size(GX,BX);
this->k_pair_fast.run(&this->atom->x, &_fp, &type2rhor_z2r,
&rhor_spline1, &z2r_spline1, &z2r_spline2,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&rhor_spline1, &z2r_spline1, &z2r_spline2,
&this->nbor->dev_nbor, &this->_nbor_data->begin(),
&this->ans->force, &this->ans->engv, &eflag,
&vflag, &ainum, &nbor_pitch, &_cutforcesq, &_rdr,
&_nr, &this->_threads_per_atom);
} else {
this->k_pair.set_size(GX,BX);
this->k_pair.run(&this->atom->x, &_fp, &type2rhor_z2r, &rhor_spline1,
this->k_pair.run(&this->atom->x, &_fp, &type2rhor_z2r, &rhor_spline1,
&z2r_spline1, &z2r_spline2, &this->nbor->dev_nbor,
&this->_nbor_data->begin(), &this->ans->force,
&this->ans->engv, &eflag, &vflag, &ainum, &nbor_pitch,