2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2012, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012,2013, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
39 #ifndef NBNXN_CUDA_TYPES_H
40 #define NBNXN_CUDA_TYPES_H
42 #include "types/nbnxn_pairlist.h"
43 #include "types/nbnxn_cuda_types_ext.h"
44 #include "../../gmxlib/cuda_tools/cudautils.cuh"
50 /*! Types of electrostatics available in the CUDA nonbonded force kernels. */
51 enum { eelCuEWALD, eelCuEWALD_TWIN, eelCuRF, eelCuCUT, eelCuNR };
53 enum { eNbnxnCuKDefault, eNbnxnCuKLegacy, eNbnxnCuKOld, eNbnxnCuKNR };
55 #define NBNXN_KVER_OLD(k) (k == eNbnxnCuKOld)
56 #define NBNXN_KVER_LEGACY(k) (k == eNbnxnCuKLegacy)
57 #define NBNXN_KVER_DEFAULT(k) (k == eNbnxnCuKDefault)
59 /*! Non-bonded kernel versions. */
61 /* All structs prefixed with "cu_" hold data used in GPU calculations and
62 * are passed to the kernels, except cu_timers_t. */
63 typedef struct cu_plist cu_plist_t;
64 typedef struct cu_atomdata cu_atomdata_t;
65 typedef struct cu_nbparam cu_nbparam_t;
66 typedef struct cu_timers cu_timers_t;
67 typedef struct nb_staging nb_staging_t;
70 /*! Staging area for temporary data. The energies get downloaded here first,
71 * before getting added to the CPU-side aggregate values.
75 float *e_lj; /* LJ energy */
76 float *e_el; /* electrostatic energy */
77 float3 *fshift; /* shift forces */
80 /*! Nonbonded atom data -- both inputs and outputs. */
83 int natoms; /* number of atoms */
84 int natoms_local; /* number of local atoms */
85 int nalloc; /* allocation size for the atom data (xq, f) */
87 float4 *xq; /* atom coordinates + charges, size natoms */
88 float3 *f; /* force output array, size natoms */
89 /* TODO: try float2 for the energies */
90 float *e_lj, /* LJ energy output, size 1 */
91 *e_el; /* Electrostatics energy input, size 1 */
93 float3 *fshift; /* shift forces */
95 int ntypes; /* number of atom types */
96 int *atom_types; /* atom type indices, size natoms */
98 float3 *shift_vec; /* shifts */
99 bool bShiftVecUploaded; /* true if the shift vector has been uploaded */
102 /*! Parameters required for the CUDA nonbonded calculations. */
105 int eeltype; /* type of electrostatics */
107 float epsfac; /* charge multiplication factor */
108 float c_rf, two_k_rf; /* Reaction-Field constants */
109 float ewald_beta; /* Ewald/PME parameter */
110 float sh_ewald; /* Ewald/PME correction term */
111 float rvdw_sq; /* VdW cut-off */
112 float rcoulomb_sq; /* Coulomb cut-off */
113 float rlist_sq; /* pair-list cut-off */
114 float sh_invrc6; /* LJ potential correction term */
116 float *nbfp; /* nonbonded parameter table with C6/C12 pairs */
118 /* Ewald Coulomb force table */
119 int coulomb_tab_size;
120 float coulomb_tab_scale;
124 /*! Pair list data */
127 int na_c; /* number of atoms per cluster */
129 int nsci; /* size of sci, # of i clusters in the list */
130 int sci_nalloc; /* allocation size of sci */
131 nbnxn_sci_t *sci; /* list of i-cluster ("super-clusters") */
133 int ncj4; /* total # of 4*j clusters */
134 int cj4_nalloc; /* allocation size of cj4 */
135 nbnxn_cj4_t *cj4; /* 4*j cluster list, contains j cluster number
136 and index into the i cluster list */
137 nbnxn_excl_t *excl; /* atom interaction bits */
138 int nexcl; /* count for excl */
139 int excl_nalloc;/* allocation size of excl */
141 bool bDoPrune; /* true if pair-list pruning needs to be
142 done during the current step */
145 /* CUDA events used for timing GPU kernels and H2D/D2H transfers.
146 * The two-sized arrays hold the local and non-local values and should always
147 * be indexed with eintLocal/eintNonlocal.
151 cudaEvent_t start_atdat, stop_atdat; /* atom data transfer (every PS step) */
152 cudaEvent_t start_nb_h2d[2], stop_nb_h2d[2]; /* x/q H2D transfer (every step) */
153 cudaEvent_t start_nb_d2h[2], stop_nb_d2h[2]; /* f D2H transfer (every step) */
154 cudaEvent_t start_pl_h2d[2], stop_pl_h2d[2]; /* pair-list H2D transfer (every PS step) */
155 cudaEvent_t start_nb_k[2], stop_nb_k[2]; /* non-bonded kernels (every step) */
158 /* Main data structure for CUDA nonbonded force calculations. */
161 cuda_dev_info_t *dev_info; /* CUDA device information */
162 int kernel_ver; /* The version of the kernel to be executed on the
163 device in use, possible values: eNbnxnCuK* */
164 bool bUseTwoStreams; /* true if doing both local/non-local NB work on GPU */
165 bool bUseStreamSync; /* true if the standard cudaStreamSynchronize is used
166 and not memory polling-based waiting */
167 cu_atomdata_t *atdat; /* atom data */
168 cu_nbparam_t *nbparam; /* parameters required for the non-bonded calc. */
169 cu_plist_t *plist[2]; /* pair-list data structures (local and non-local) */
170 nb_staging_t nbst; /* staging area where fshift/energies get downloaded */
172 cudaStream_t stream[2]; /* local and non-local GPU streams */
174 /* events used for synchronization */
175 cudaEvent_t nonlocal_done, misc_ops_done;
177 /* NOTE: With current CUDA versions (<=5.0) timing doesn't work with multiple
178 * concurrent streams, so we won't time if both l/nl work is done on GPUs.
179 * Timer init/uninit is still done even with timing off so only the condition
180 * setting bDoTime needs to be change if this CUDA "feature" gets fixed. */
181 bool bDoTime; /* True if event-based timing is enabled. */
182 cu_timers_t *timers; /* CUDA event-based timers. */
183 wallclock_gpu_t *timings; /* Timing data. */
190 #endif /* NBNXN_CUDA_TYPES_H */