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

« back to all changes in this revision

Viewing changes to lib/gpu/lal_coul_ext.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_ext.cpp
 
3
                             -------------------
 
4
                               Trung Dac Nguyen
 
5
 
 
6
  Functions for LAMMPS access to coul/cut acceleration routines.
 
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
#include <iostream>
 
17
#include <cassert>
 
18
#include <math.h>
 
19
 
 
20
#include "lal_coul.h"
 
21
 
 
22
using namespace std;
 
23
using namespace LAMMPS_AL;
 
24
 
 
25
static Coul<PRECISION,ACC_PRECISION> COULMF;
 
26
 
 
27
// ---------------------------------------------------------------------------
 
28
// Allocate memory on host and device and copy constants to device
 
29
// ---------------------------------------------------------------------------
 
30
int coul_gpu_init(const int ntypes, double **host_scale,
 
31
                  double **cutsq, double *special_coul,
 
32
                  const int inum, const int nall, const int max_nbors,
 
33
                  const int maxspecial, const double cell_size,
 
34
                  int &gpu_mode, FILE *screen, const double qqrd2e) {
 
35
  COULMF.clear();
 
36
  gpu_mode=COULMF.device->gpu_mode();
 
37
  double gpu_split=COULMF.device->particle_split();
 
38
  int first_gpu=COULMF.device->first_device();
 
39
  int last_gpu=COULMF.device->last_device();
 
40
  int world_me=COULMF.device->world_me();
 
41
  int gpu_rank=COULMF.device->gpu_rank();
 
42
  int procs_per_gpu=COULMF.device->procs_per_gpu();
 
43
 
 
44
  COULMF.device->init_message(screen,"coul/cut",first_gpu,last_gpu);
 
45
 
 
46
  bool message=false;
 
47
  if (COULMF.device->replica_me()==0 && screen)
 
48
    message=true;
 
49
 
 
50
  if (message) {
 
51
    fprintf(screen,"Initializing GPU and compiling on process 0...");
 
52
    fflush(screen);
 
53
  }
 
54
 
 
55
  int init_ok=0;
 
56
  if (world_me==0)
 
57
    init_ok=COULMF.init(ntypes, host_scale, cutsq, special_coul, inum, nall, 300,
 
58
                       maxspecial, cell_size, gpu_split, screen, qqrd2e);
 
59
 
 
60
  COULMF.device->world_barrier();
 
61
  if (message)
 
62
    fprintf(screen,"Done.\n");
 
63
 
 
64
  for (int i=0; i<procs_per_gpu; i++) {
 
65
    if (message) {
 
66
      if (last_gpu-first_gpu==0)
 
67
        fprintf(screen,"Initializing GPU %d on core %d...",first_gpu,i);
 
68
      else
 
69
        fprintf(screen,"Initializing GPUs %d-%d on core %d...",first_gpu,
 
70
                last_gpu,i);
 
71
      fflush(screen);
 
72
    }
 
73
    if (gpu_rank==i && world_me!=0)
 
74
      init_ok=COULMF.init(ntypes, host_scale, cutsq, special_coul, inum, nall, 300,
 
75
                          maxspecial, cell_size, gpu_split, screen, qqrd2e);
 
76
 
 
77
    COULMF.device->gpu_barrier();
 
78
    if (message) 
 
79
      fprintf(screen,"Done.\n");
 
80
  }
 
81
  if (message)
 
82
    fprintf(screen,"\n");
 
83
 
 
84
  if (init_ok==0)
 
85
    COULMF.estimate_gpu_overhead();
 
86
  return init_ok;
 
87
}
 
88
 
 
89
// ---------------------------------------------------------------------------
 
90
// Copy updated constants to device
 
91
// ---------------------------------------------------------------------------
 
92
void coul_gpu_reinit(const int ntypes, double **host_scale) {
 
93
  int world_me=COULMF.device->world_me();
 
94
  int gpu_rank=COULMF.device->gpu_rank();
 
95
  int procs_per_gpu=COULMF.device->procs_per_gpu();
 
96
  
 
97
  if (world_me==0)
 
98
    COULMF.reinit(ntypes, host_scale);
 
99
  
 
100
  COULMF.device->world_barrier();
 
101
  
 
102
  for (int i=0; i<procs_per_gpu; i++) {
 
103
    if (gpu_rank==i && world_me!=0)
 
104
      COULMF.reinit(ntypes, host_scale);
 
105
    
 
106
    COULMF.device->gpu_barrier();
 
107
  }
 
108
}
 
109
 
 
110
void coul_gpu_clear() {
 
111
  COULMF.clear();
 
112
}
 
113
 
 
114
int** coul_gpu_compute_n(const int ago, const int inum_full,
 
115
                        const int nall, double **host_x, int *host_type,
 
116
                        double *sublo, double *subhi, tagint *tag, int **nspecial, 
 
117
                        tagint **special, const bool eflag, const bool vflag,
 
118
                        const bool eatom, const bool vatom, int &host_start,
 
119
                        int **ilist, int **jnum, const double cpu_time,
 
120
                        bool &success, double *host_q, double *boxlo,
 
121
                        double *prd) {
 
122
  return COULMF.compute(ago, inum_full, nall, host_x, host_type, sublo,
 
123
                       subhi, tag, nspecial, special, eflag, vflag, eatom,
 
124
                       vatom, host_start, ilist, jnum, cpu_time, success,
 
125
                       host_q, boxlo, prd);
 
126
}  
 
127
                        
 
128
void coul_gpu_compute(const int ago, const int inum_full, const int nall,
 
129
                     double **host_x, int *host_type, int *ilist, int *numj,
 
130
                     int **firstneigh, const bool eflag, const bool vflag,
 
131
                     const bool eatom, const bool vatom, int &host_start,
 
132
                     const double cpu_time, bool &success, double *host_q,
 
133
                     const int nlocal, double *boxlo, double *prd) {
 
134
  COULMF.compute(ago,inum_full,nall,host_x,host_type,ilist,numj,firstneigh,eflag,
 
135
                vflag,eatom,vatom,host_start,cpu_time,success,host_q,
 
136
                nlocal,boxlo,prd);
 
137
}
 
138
 
 
139
double coul_gpu_bytes() {
 
140
  return COULMF.host_memory_usage();
 
141
}
 
142
 
 
143