1 /***************************************************************************
2 gayberne_ext.cpp
3 -------------------
4 W. Michael Brown
5
6 LAMMPS Wrappers for Gay-Berne Acceleration
7
8 __________________________________________________________________________
9 This file is part of the LAMMPS Accelerator Library (LAMMPS_AL)
10 __________________________________________________________________________
11
12 begin :
13 email : brownw@ornl.gov
14 ***************************************************************************/
15
16 #include <iostream>
17 #include <cassert>
18 #include <cmath>
19
20 #include "lal_gayberne.h"
21
22 using namespace std;
23 using namespace LAMMPS_AL;
24
25 static GayBerne<PRECISION,ACC_PRECISION> GBMF;
26
27 // ---------------------------------------------------------------------------
28 // Allocate memory on host and device and copy constants to device
29 // ---------------------------------------------------------------------------
gb_gpu_init(const int ntypes,const double gamma,const double upsilon,const double mu,double ** shape,double ** well,double ** cutsq,double ** sigma,double ** epsilon,double * host_lshape,int ** form,double ** host_lj1,double ** host_lj2,double ** host_lj3,double ** host_lj4,double ** offset,double * special_lj,const int inum,const int nall,const int max_nbors,const int maxspecial,const double cell_size,int & gpu_mode,FILE * screen)30 int gb_gpu_init(const int ntypes, const double gamma,
31 const double upsilon, const double mu, double **shape,
32 double **well, double **cutsq, double **sigma,
33 double **epsilon, double *host_lshape, int **form,
34 double **host_lj1, double **host_lj2, double **host_lj3,
35 double **host_lj4, double **offset, double *special_lj,
36 const int inum, const int nall, const int max_nbors,
37 const int maxspecial, const double cell_size, int &gpu_mode,
38 FILE *screen) {
39 GBMF.clear();
40 gpu_mode=GBMF.device->gpu_mode();
41 double gpu_split=GBMF.device->particle_split();
42 int first_gpu=GBMF.device->first_device();
43 int last_gpu=GBMF.device->last_device();
44 int world_me=GBMF.device->world_me();
45 int gpu_rank=GBMF.device->gpu_rank();
46 int procs_per_gpu=GBMF.device->procs_per_gpu();
47
48 GBMF.device->init_message(screen,"gayberne",first_gpu,last_gpu);
49
50 bool message=false;
51 if (GBMF.device->replica_me()==0 && screen)
52 message=true;
53
54 if (message) {
55 fprintf(screen,"Initializing Device and compiling on process 0...");
56 fflush(screen);
57 }
58
59 int init_ok=0;
60 if (world_me==0)
61 init_ok=GBMF.init(ntypes, gamma, upsilon, mu, shape, well, cutsq,
62 sigma, epsilon, host_lshape, form, host_lj1,
63 host_lj2, host_lj3, host_lj4, offset, special_lj,
64 inum, nall, max_nbors, maxspecial, cell_size, gpu_split,
65 screen);
66
67 GBMF.device->world_barrier();
68 if (message)
69 fprintf(screen,"Done.\n");
70
71 for (int i=0; i<procs_per_gpu; i++) {
72 if (message) {
73 if (last_gpu-first_gpu==0)
74 fprintf(screen,"Initializing Device %d on core %d...",first_gpu,i);
75 else
76 fprintf(screen,"Initializing Devices %d-%d on core %d...",first_gpu,
77 last_gpu,i);
78 fflush(screen);
79 }
80 if (gpu_rank==i && world_me!=0)
81 init_ok=GBMF.init(ntypes, gamma, upsilon, mu, shape, well, cutsq, sigma,
82 epsilon, host_lshape, form, host_lj1, host_lj2,
83 host_lj3, host_lj4, offset, special_lj, inum, nall,
84 max_nbors, maxspecial, cell_size, gpu_split, screen);
85
86 GBMF.device->gpu_barrier();
87 if (message)
88 fprintf(screen,"Done.\n");
89 }
90 if (message)
91 fprintf(screen,"\n");
92
93 if (init_ok==0)
94 GBMF.estimate_gpu_overhead();
95 return init_ok;
96 }
97
98 // ---------------------------------------------------------------------------
99 // Clear memory on host and device
100 // ---------------------------------------------------------------------------
gb_gpu_clear()101 void gb_gpu_clear() {
102 GBMF.clear();
103 }
104
105 int** compute(const int ago, const int inum_full, const int nall,
106 double **host_x, int *host_type, double *sublo,
107 double *subhi, tagint *tag, int **nspecial,
108 tagint **special, const bool eflag, const bool vflag,
109 const bool eatom, const bool vatom, int &host_start,
110 int **ilist, int **numj, const double cpu_time, bool &success,
111 double **host_quat);
112
gb_gpu_compute_n(const int ago,const int inum_full,const int nall,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,double ** host_quat)113 int** gb_gpu_compute_n(const int ago, const int inum_full, const int nall,
114 double **host_x, int *host_type, double *sublo,
115 double *subhi, tagint *tag, int **nspecial, tagint **special,
116 const bool eflag, const bool vflag, const bool eatom,
117 const bool vatom, int &host_start, int **ilist,
118 int **jnum, const double cpu_time, bool &success,
119 double **host_quat) {
120 return GBMF.compute(ago, inum_full, nall, host_x, host_type, sublo, subhi,
121 tag, nspecial, special, eflag, vflag, eatom, vatom,
122 host_start, ilist, jnum, cpu_time, success, host_quat);
123 }
124
gb_gpu_compute(const int ago,const int inum_full,const int nall,double ** host_x,int * host_type,int * ilist,int * numj,int ** firstneigh,const bool eflag,const bool vflag,const bool eatom,const bool vatom,int & host_start,const double cpu_time,bool & success,double ** host_quat)125 int * gb_gpu_compute(const int ago, const int inum_full, const int nall,
126 double **host_x, int *host_type, int *ilist, int *numj,
127 int **firstneigh, const bool eflag, const bool vflag,
128 const bool eatom, const bool vatom, int &host_start,
129 const double cpu_time, bool &success, double **host_quat) {
130 return GBMF.compute(ago, inum_full, nall, host_x, host_type, ilist,
131 numj, firstneigh, eflag, vflag, eatom, vatom, host_start,
132 cpu_time, success, host_quat);
133 }
134
135 // ---------------------------------------------------------------------------
136 // Return memory usage
137 // ---------------------------------------------------------------------------
gb_gpu_bytes()138 double gb_gpu_bytes() {
139 return GBMF.host_memory_usage();
140 }
141
142