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

« back to all changes in this revision

Viewing changes to lib/gpu/lal_mie.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2013-11-20 22:41:36 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131120224136-tzx7leh606fqnckm
Tags: 0~20131119.git7162cf0-1
* [e65b919] Imported Upstream version 0~20131119.git7162cf0
* [f7bddd4] Fix some problems, introduced by upstream recently.
* [3616dfc] Use wrap-and-sort script.
* [7e92030] Ignore quilt dir

Show diffs side-by-side

added added

removed removed

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