1 /***************************************************************************
2 lj96_ext.cpp
3 -------------------
4 W. Michael Brown (ORNL)
5
6 Functions for LAMMPS access to lj96/cut acceleration routines.
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 <math.h>
19
20 #include "lal_lj96.h"
21
22 using namespace std;
23 using namespace LAMMPS_AL;
24
25 static LJ96<PRECISION,ACC_PRECISION> LJ96MF;
26
27 // ---------------------------------------------------------------------------
28 // Allocate memory on host and device and copy constants to device
29 // ---------------------------------------------------------------------------
lj96_gpu_init(const int ntypes,double ** cutsq,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 lj96_gpu_init(const int ntypes, double **cutsq, double **host_lj1,
31 double **host_lj2, double **host_lj3, double **host_lj4,
32 double **offset, double *special_lj, const int inum,
33 const int nall, const int max_nbors, const int maxspecial,
34 const double cell_size, int &gpu_mode, FILE *screen) {
35 LJ96MF.clear();
36 gpu_mode=LJ96MF.device->gpu_mode();
37 double gpu_split=LJ96MF.device->particle_split();
38 int first_gpu=LJ96MF.device->first_device();
39 int last_gpu=LJ96MF.device->last_device();
40 int world_me=LJ96MF.device->world_me();
41 int gpu_rank=LJ96MF.device->gpu_rank();
42 int procs_per_gpu=LJ96MF.device->procs_per_gpu();
43
44 LJ96MF.device->init_message(screen,"lj96/cut",first_gpu,last_gpu);
45
46 bool message=false;
47 if (LJ96MF.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=LJ96MF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3,
58 host_lj4, offset, special_lj, inum, nall, 300,
59 maxspecial, cell_size, gpu_split, screen);
60
61 LJ96MF.device->world_barrier();
62 if (message)
63 fprintf(screen,"Done.\n");
64
65 for (int i=0; i<procs_per_gpu; i++) {
66 if (message) {
67 if (last_gpu-first_gpu==0)
68 fprintf(screen,"Initializing GPU %d on core %d...",first_gpu,i);
69 else
70 fprintf(screen,"Initializing GPUs %d-%d on core %d...",first_gpu,
71 last_gpu,i);
72 fflush(screen);
73 }
74 if (gpu_rank==i && world_me!=0)
75 init_ok=LJ96MF.init(ntypes, cutsq, host_lj1, host_lj2, host_lj3, host_lj4,
76 offset, special_lj, inum, nall, 300, maxspecial,
77 cell_size, gpu_split, screen);
78
79 LJ96MF.device->gpu_barrier();
80 if (message)
81 fprintf(screen,"Done.\n");
82 }
83 if (message)
84 fprintf(screen,"\n");
85
86 if (init_ok==0)
87 LJ96MF.estimate_gpu_overhead();
88 return init_ok;
89 }
90
lj96_gpu_clear()91 void lj96_gpu_clear() {
92 LJ96MF.clear();
93 }
94
lj96_gpu_compute_n(const int ago,const int inum_full,const int nall,double ** host_x,int * host_type,double * sublo,double * subhi,int * tag,int ** nspecial,int ** 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)95 int** lj96_gpu_compute_n(const int ago, const int inum_full,
96 const int nall, double **host_x, int *host_type,
97 double *sublo, double *subhi, int *tag, int **nspecial,
98 int **special, const bool eflag, const bool vflag,
99 const bool eatom, const bool vatom, int &host_start,
100 int **ilist, int **jnum, const double cpu_time,
101 bool &success) {
102 return LJ96MF.compute(ago, inum_full, nall, host_x, host_type, sublo,
103 subhi, tag, nspecial, special, eflag, vflag, eatom,
104 vatom, host_start, ilist, jnum, cpu_time, success);
105 }
106
lj96_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)107 void lj96_gpu_compute(const int ago, const int inum_full, const int nall,
108 double **host_x, int *host_type, int *ilist, int *numj,
109 int **firstneigh, const bool eflag, const bool vflag,
110 const bool eatom, const bool vatom, int &host_start,
111 const double cpu_time, bool &success) {
112 LJ96MF.compute(ago,inum_full,nall,host_x,host_type,ilist,numj,firstneigh,
113 eflag,vflag,eatom,vatom,host_start,cpu_time,success);
114 }
115
lj96_gpu_bytes()116 double lj96_gpu_bytes() {
117 return LJ96MF.host_memory_usage();
118 }
119
120
121