/*************************************************************************** lal_table.cpp ------------------- Trung Dac Nguyen, W. Michael Brown (ORNL) Class for acceleration of the table pair style. __________________________________________________________________________ This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) __________________________________________________________________________ begin : email : brownw@ornl.gov nguyentd@ornl.gov ***************************************************************************/ #ifdef USE_OPENCL #include "table_cl.h" #else #include "table_ptx.h" #endif #include "lal_table.h" #include using namespace LAMMPS_AL; #define TableT Table #define LOOKUP 0 #define LINEAR 1 #define SPLINE 2 #define BITMAP 3 extern Device device; template TableT::Table() : BaseAtomic(), _allocated(false) { } template TableT::~Table() { clear(); } template int TableT::bytes_per_atom(const int max_nbors) const { return this->bytes_per_atom_atomic(max_nbors); } template int TableT::init(const int ntypes, double **host_cutsq, double ***host_table_coeffs, double **host_table_data, double *host_special_lj, const int nlocal, const int nall, const int max_nbors, const int maxspecial, const double cell_size, const double gpu_split, FILE *_screen, int tabstyle, int ntables, int tablength) { int success; success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split, _screen,table); if (success!=0) return success; // If atom type constants fit in shared memory use fast kernel int lj_types=ntypes; shared_types=false; int max_shared_types=this->device->max_shared_types(); if (lj_types<=max_shared_types && this->_block_size>=max_shared_types) { lj_types=max_shared_types; shared_types=true; } _lj_types=lj_types; _tabstyle = tabstyle; _ntables = ntables; _tablength = tablength; // Allocate a host write buffer for data initialization UCL_H_Vec host_write(lj_types*lj_types,*(this->ucl_device), UCL_WRITE_OPTIMIZED); for (int i=0; iucl_device),UCL_READ_ONLY); for (int ix=1; ixucl_device),UCL_READ_ONLY); for (int ix=1; ix host_write2(ntables*tablength,*(this->ucl_device), UCL_WRITE_OPTIMIZED); for (int i=0; iucl_device),UCL_READ_ONLY); for (int n=0; nucl_device),UCL_READ_ONLY); for (int i=0; i host_rsq(lj_types*lj_types,*(this->ucl_device), UCL_WRITE_OPTIMIZED); cutsq.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY); this->atom->type_pack1(ntypes,lj_types,cutsq,host_rsq,host_cutsq); UCL_H_Vec dview; sp_lj.alloc(4,*(this->ucl_device),UCL_READ_ONLY); dview.view(host_special_lj,4,*(this->ucl_device)); ucl_copy(sp_lj,dview,false); _allocated=true; this->_max_bytes=coeff1.row_bytes()+coeff2.row_bytes() +coeff3.row_bytes()+coeff4.row_bytes()+cutsq.row_bytes() +sp_lj.row_bytes(); return 0; } template void TableT::clear() { if (!_allocated) return; _allocated=false; coeff1.clear(); coeff2.clear(); coeff3.clear(); coeff4.clear(); sp_lj.clear(); this->clear_atomic(); } template double TableT::host_memory_usage() const { return this->host_memory_usage_atomic()+sizeof(Table); } // --------------------------------------------------------------------------- // Calculate energies, forces, and torques // --------------------------------------------------------------------------- template void TableT::loop(const bool _eflag, const bool _vflag) { // Compute the block size and grid size to keep all cores busy const int BX=this->block_size(); int eflag, vflag; if (_eflag) eflag=1; else eflag=0; if (_vflag) vflag=1; else vflag=0; int GX=static_cast(ceil(static_cast(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_pair_fast.set_size(GX,BX); this->k_pair_fast.run(&this->atom->dev_x.begin(), &coeff1.begin(), &coeff2.begin(), &coeff3.begin(), &coeff4.begin(), &cutsq.begin(), &sp_lj.begin(), &this->nbor->dev_nbor.begin(), &this->_nbor_data->begin(), &this->ans->dev_ans.begin(), &this->ans->dev_engv.begin(), &eflag, &vflag, &ainum, &nbor_pitch, &this->_threads_per_atom, &_tabstyle, &_tablength); } else { this->k_pair.set_size(GX,BX); this->k_pair.run(&this->atom->dev_x.begin(), &coeff1.begin(), &coeff2.begin(), &coeff3.begin(), &coeff4.begin(), &cutsq.begin(), &_lj_types, &sp_lj.begin(), &this->nbor->dev_nbor.begin(), &this->_nbor_data->begin(), &this->ans->dev_ans.begin(), &this->ans->dev_engv.begin(), &eflag, &vflag, &ainum, &nbor_pitch, &this->_threads_per_atom, &_tabstyle, &_tablength); } this->time_pair.stop(); } template class Table;