~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to lib/gpu/lal_coul.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                                 coul.cpp
 
3
                             -------------------
 
4
                               Trung Dac Nguyen
 
5
 
 
6
  Class for acceleration of the coul/cut pair style.
 
7
 
 
8
 __________________________________________________________________________
 
9
    This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
 
10
 __________________________________________________________________________
 
11
 
 
12
    begin                : 
 
13
    email                : ndtrung@umich.edu
 
14
 ***************************************************************************/
 
15
 
 
16
#if defined(USE_OPENCL)
 
17
#include "coul_cl.h"
 
18
#elif defined(USE_CUDART)
 
19
const char *coul=0;
 
20
#else
 
21
#include "coul_cubin.h"
 
22
#endif
 
23
 
 
24
#include "lal_coul.h"
 
25
#include <cassert>
 
26
using namespace LAMMPS_AL;
 
27
#define CoulT Coul<numtyp, acctyp>
 
28
 
 
29
extern Device<PRECISION,ACC_PRECISION> device;
 
30
 
 
31
template <class numtyp, class acctyp>
 
32
CoulT::Coul() : BaseCharge<numtyp,acctyp>(),
 
33
  _allocated(false) {
 
34
}
 
35
 
 
36
template <class numtyp, class acctyp>
 
37
CoulT::~Coul() {
 
38
  clear();
 
39
}
 
40
 
 
41
template <class numtyp, class acctyp>
 
42
int CoulT::bytes_per_atom(const int max_nbors) const {
 
43
  return this->bytes_per_atom_atomic(max_nbors);
 
44
}
 
45
 
 
46
template <class numtyp, class acctyp>
 
47
int CoulT::init(const int ntypes, double **host_scale, double **host_cutsq,
 
48
                double *host_special_coul, const int nlocal,
 
49
                const int nall, const int max_nbors,
 
50
                const int maxspecial, const double cell_size,
 
51
                const double gpu_split, FILE *_screen,
 
52
                const double qqrd2e) {
 
53
  int success;
 
54
  success=this->init_atomic(nlocal,nall,max_nbors,maxspecial,cell_size,gpu_split,
 
55
                            _screen,coul,"k_coul");
 
56
  if (success!=0)
 
57
    return success;
 
58
 
 
59
  // If atom type constants fit in shared memory use fast kernel
 
60
  int lj_types=ntypes;
 
61
  shared_types=false;
 
62
  int max_shared_types=this->device->max_shared_types();
 
63
  if (lj_types<=max_shared_types && this->_block_size>=max_shared_types) {
 
64
    lj_types=max_shared_types;
 
65
    shared_types=true;
 
66
  }
 
67
  _lj_types=lj_types;
 
68
 
 
69
  // Allocate a host write buffer for data initialization
 
70
  UCL_H_Vec<numtyp> host_write(lj_types*lj_types*32,*(this->ucl_device),
 
71
                               UCL_WRITE_ONLY);
 
72
 
 
73
  for (int i=0; i<lj_types*lj_types; i++)
 
74
    host_write[i]=0.0;
 
75
 
 
76
  scale.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
 
77
  this->atom->type_pack1(ntypes,lj_types,scale,host_write,host_scale);
 
78
  
 
79
  cutsq.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY);
 
80
  this->atom->type_pack1(ntypes,lj_types,cutsq,host_write,host_cutsq);
 
81
 
 
82
  sp_cl.alloc(4,*(this->ucl_device),UCL_READ_ONLY);
 
83
  for (int i=0; i<4; i++) {
 
84
    host_write[i]=host_special_coul[i];
 
85
  }
 
86
  ucl_copy(sp_cl,host_write,4,false);
 
87
 
 
88
  _qqrd2e=qqrd2e;
 
89
 
 
90
  _allocated=true;
 
91
  this->_max_bytes=cutsq.row_bytes()+sp_cl.row_bytes();
 
92
  return 0;
 
93
}
 
94
 
 
95
template <class numtyp, class acctyp>
 
96
void CoulT::reinit(const int ntypes, double **host_scale) {
 
97
  // Allocate a host write buffer for data initialization
 
98
  UCL_H_Vec<numtyp> host_write(_lj_types*_lj_types*32,*(this->ucl_device),
 
99
                               UCL_WRITE_ONLY);
 
100
  
 
101
  for (int i=0; i<_lj_types*_lj_types; i++)
 
102
    host_write[i]=0.0;
 
103
  
 
104
  this->atom->type_pack1(ntypes,_lj_types,scale,host_write,host_scale);
 
105
}
 
106
 
 
107
template <class numtyp, class acctyp>
 
108
void CoulT::clear() {
 
109
  if (!_allocated)
 
110
    return;
 
111
  _allocated=false;
 
112
 
 
113
  scale.clear();
 
114
  cutsq.clear();
 
115
  sp_cl.clear();
 
116
  this->clear_atomic();
 
117
}
 
118
 
 
119
template <class numtyp, class acctyp>
 
120
double CoulT::host_memory_usage() const {
 
121
  return this->host_memory_usage_atomic()+sizeof(Coul<numtyp,acctyp>);
 
122
}
 
123
 
 
124
// ---------------------------------------------------------------------------
 
125
// Calculate energies, forces, and torques
 
126
// ---------------------------------------------------------------------------
 
127
template <class numtyp, class acctyp>
 
128
void CoulT::loop(const bool _eflag, const bool _vflag) {
 
129
  // Compute the block size and grid size to keep all cores busy
 
130
  const int BX=this->block_size();
 
131
  int eflag, vflag;
 
132
  if (_eflag)
 
133
    eflag=1;
 
134
  else
 
135
    eflag=0;
 
136
 
 
137
  if (_vflag)
 
138
    vflag=1;
 
139
  else
 
140
    vflag=0;
 
141
  
 
142
  int GX=static_cast<int>(ceil(static_cast<double>(this->ans->inum())/
 
143
                               (BX/this->_threads_per_atom)));
 
144
 
 
145
  int ainum=this->ans->inum();
 
146
  int nbor_pitch=this->nbor->nbor_pitch();
 
147
  this->time_pair.start();
 
148
  if (shared_types) {
 
149
    this->k_pair_fast.set_size(GX,BX);
 
150
    this->k_pair_fast.run(&this->atom->x, &scale, &sp_cl,
 
151
                          &this->nbor->dev_nbor, &this->_nbor_data->begin(),
 
152
                          &this->ans->force, &this->ans->engv, &eflag, 
 
153
                          &vflag, &ainum, &nbor_pitch, &this->atom->q,
 
154
                          &cutsq, &_qqrd2e, &this->_threads_per_atom);
 
155
  } else {
 
156
    this->k_pair.set_size(GX,BX);
 
157
    this->k_pair.run(&this->atom->x, &scale, &_lj_types, &sp_cl,
 
158
                     &this->nbor->dev_nbor, &this->_nbor_data->begin(), 
 
159
                     &this->ans->force, &this->ans->engv, 
 
160
                     &eflag, &vflag, &ainum, &nbor_pitch, &this->atom->q,
 
161
                     &cutsq, &_qqrd2e, &this->_threads_per_atom);
 
162
  }
 
163
  this->time_pair.stop();
 
164
}
 
165
 
 
166
template class Coul<PRECISION,ACC_PRECISION>;