2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
5 * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
37 * \brief Define common implementation of nbnxm_gpu_data_mgmt.h
39 * \author Anca Hamuraru <anca@streamcomputing.eu>
40 * \author Dimitrios Karkoulis <dimitris.karkoulis@gmail.com>
41 * \author Teemu Virolainen <teemu@streamcomputing.eu>
42 * \author Szilárd Páll <pall.szilard@gmail.com>
43 * \author Artem Zhmurov <zhmurov@gmail.com>
45 * \ingroup module_nbnxm
52 # include "cuda/nbnxm_cuda_types.h"
56 # include "opencl/nbnxm_ocl_types.h"
59 #include "nbnxm_gpu_data_mgmt.h"
61 #include "gromacs/timing/gpu_timing.h"
63 #include "nbnxm_gpu.h"
68 void init_ewald_coulomb_force_table(const EwaldCorrectionTables
& tables
,
70 const DeviceContext
& deviceContext
)
72 if (!nbp
->coulomb_tab
)
74 destroyParamLookupTable(&nbp
->coulomb_tab
, nbp
->coulomb_tab_texobj
);
77 nbp
->coulomb_tab_scale
= tables
.scale
;
78 initParamLookupTable(&nbp
->coulomb_tab
, &nbp
->coulomb_tab_texobj
, tables
.tableF
.data(),
79 tables
.tableF
.size(), deviceContext
);
82 int nbnxn_gpu_pick_ewald_kernel_type(const interaction_const_t
& ic
)
84 bool bTwinCut
= (ic
.rcoulomb
!= ic
.rvdw
);
85 bool bUseAnalyticalEwald
, bForceAnalyticalEwald
, bForceTabulatedEwald
;
88 /* Benchmarking/development environment variables to force the use of
89 analytical or tabulated Ewald kernel. */
90 bForceAnalyticalEwald
= (getenv("GMX_GPU_NB_ANA_EWALD") != nullptr);
91 bForceTabulatedEwald
= (getenv("GMX_GPU_NB_TAB_EWALD") != nullptr);
93 if (bForceAnalyticalEwald
&& bForceTabulatedEwald
)
96 "Both analytical and tabulated Ewald GPU non-bonded kernels "
97 "requested through environment variables.");
100 /* By default, use analytical Ewald
101 * TODO: tabulated does not work in OpenCL, it needs fixing, see init_nbparam() in nbnxn_ocl_data_mgmt.cpp
104 bUseAnalyticalEwald
= true;
105 if (bForceAnalyticalEwald
)
109 fprintf(debug
, "Using analytical Ewald GPU kernels\n");
112 else if (bForceTabulatedEwald
)
114 bUseAnalyticalEwald
= false;
118 fprintf(debug
, "Using tabulated Ewald GPU kernels\n");
122 /* Use twin cut-off kernels if requested by bTwinCut or the env. var.
123 forces it (use it for debugging/benchmarking only). */
124 if (!bTwinCut
&& (getenv("GMX_GPU_NB_EWALD_TWINCUT") == nullptr))
126 kernel_type
= bUseAnalyticalEwald
? eelTypeEWALD_ANA
: eelTypeEWALD_TAB
;
130 kernel_type
= bUseAnalyticalEwald
? eelTypeEWALD_ANA_TWIN
: eelTypeEWALD_TAB_TWIN
;
136 void set_cutoff_parameters(NBParamGpu
* nbp
, const interaction_const_t
* ic
, const PairlistParams
& listParams
)
138 nbp
->ewald_beta
= ic
->ewaldcoeff_q
;
139 nbp
->sh_ewald
= ic
->sh_ewald
;
140 nbp
->epsfac
= ic
->epsfac
;
141 nbp
->two_k_rf
= 2.0 * ic
->k_rf
;
142 nbp
->c_rf
= ic
->c_rf
;
143 nbp
->rvdw_sq
= ic
->rvdw
* ic
->rvdw
;
144 nbp
->rcoulomb_sq
= ic
->rcoulomb
* ic
->rcoulomb
;
145 nbp
->rlistOuter_sq
= listParams
.rlistOuter
* listParams
.rlistOuter
;
146 nbp
->rlistInner_sq
= listParams
.rlistInner
* listParams
.rlistInner
;
147 nbp
->useDynamicPruning
= listParams
.useDynamicPruning
;
149 nbp
->sh_lj_ewald
= ic
->sh_lj_ewald
;
150 nbp
->ewaldcoeff_lj
= ic
->ewaldcoeff_lj
;
152 nbp
->rvdw_switch
= ic
->rvdw_switch
;
153 nbp
->dispersion_shift
= ic
->dispersion_shift
;
154 nbp
->repulsion_shift
= ic
->repulsion_shift
;
155 nbp
->vdw_switch
= ic
->vdw_switch
;
158 void init_plist(gpu_plist
* pl
)
160 /* initialize to nullptr pointers to data that is not allocated here and will
161 need reallocation in nbnxn_gpu_init_pairlist */
167 /* size -1 indicates that the respective array hasn't been initialized yet */
174 pl
->imask_nalloc
= -1;
176 pl
->excl_nalloc
= -1;
177 pl
->haveFreshList
= false;
180 void init_timings(gmx_wallclock_gpu_nbnxn_t
* t
)
189 for (i
= 0; i
< 2; i
++)
191 for (j
= 0; j
< 2; j
++)
193 t
->ktime
[i
][j
].t
= 0.0;
194 t
->ktime
[i
][j
].c
= 0;
198 t
->pruneTime
.t
= 0.0;
199 t
->dynamicPruneTime
.c
= 0;
200 t
->dynamicPruneTime
.t
= 0.0;