Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / nbnxm / gpu_types_common.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal \file
36  * \brief Implements common internal types for different NBNXN GPU implementations
37  *
38  * \author Szilárd Páll <pall.szilard@gmail.com>
39  * \ingroup module_nbnxm
40  */
41
42 #ifndef GMX_MDLIB_NBNXN_GPU_COMMON_TYPES_H
43 #define GMX_MDLIB_NBNXN_GPU_COMMON_TYPES_H
44
45 #include "config.h"
46
47 #include "gromacs/mdtypes/locality.h"
48 #include "gromacs/utility/enumerationhelpers.h"
49
50 #include "pairlist.h"
51
52 #if GMX_GPU == GMX_GPU_OPENCL
53 #    include "gromacs/gpu_utils/gpuregiontimer_ocl.h"
54 #endif
55
56 #if GMX_GPU == GMX_GPU_CUDA
57 #    include "gromacs/gpu_utils/gpuregiontimer.cuh"
58 #endif
59
60 namespace Nbnxm
61 {
62
63 using gmx::AtomLocality;
64 using gmx::InteractionLocality;
65
66 /*! \internal
67  * \brief GPU region timers used for timing GPU kernels and H2D/D2H transfers.
68  *
69  * The two-sized arrays hold the local and non-local values and should always
70  * be indexed with eintLocal/eintNonlocal.
71  */
72 struct gpu_timers_t
73 {
74     /*! \internal
75      * \brief Timers for local or non-local coordinate/force transfers
76      */
77     struct XFTransfers
78     {
79         GpuRegionTimer nb_h2d; /**< timer for x/q H2D transfers (l/nl, every step) */
80         GpuRegionTimer nb_d2h; /**< timer for f D2H transfer (l/nl, every step) */
81     };
82
83     /*! \internal
84      * \brief Timers for local or non-local interaction related operations
85      */
86     struct Interaction
87     {
88         GpuRegionTimer pl_h2d;       /**< timer for pair-list H2D transfers (l/nl, every PS step) */
89         bool didPairlistH2D = false; /**< true when a pair-list transfer has been done at this step */
90         GpuRegionTimer nb_k;         /**< timer for non-bonded kernels (l/nl, every step)         */
91         GpuRegionTimer prune_k; /**< timer for the 1st pass list pruning kernel (l/nl, every PS step) */
92         bool didPrune = false; /**< true when we timed pruning and the timings need to be accounted for */
93         GpuRegionTimer rollingPrune_k; /**< timer for rolling pruning kernels (l/nl, frequency depends on chunk size)  */
94         bool           didRollingPrune =
95                 false; /**< true when we timed rolling pruning (at the previous step) and the timings need to be accounted for */
96     };
97
98     //! timer for atom data transfer (every PS step)
99     GpuRegionTimer atdat;
100     //! timers for coordinate/force transfers (every step)
101     gmx::EnumerationArray<AtomLocality, XFTransfers> xf;
102     //! timers for interaction related transfers
103     gmx::EnumerationArray<InteractionLocality, Nbnxm::gpu_timers_t::Interaction> interaction;
104 };
105
106 struct gpu_plist
107 {
108     int na_c; /**< number of atoms per cluster                  */
109
110     int                       nsci;       /**< size of sci, # of i clusters in the list     */
111     int                       sci_nalloc; /**< allocation size of sci                       */
112     DeviceBuffer<nbnxn_sci_t> sci;        /**< list of i-cluster ("super-clusters")         */
113
114     int                       ncj4;          /**< total # of 4*j clusters                      */
115     int                       cj4_nalloc;    /**< allocation size of cj4                       */
116     DeviceBuffer<nbnxn_cj4_t> cj4;           /**< 4*j cluster list, contains j cluster number
117                                                 and index into the i cluster list            */
118     int                        nimask;       /**< # of 4*j clusters * # of warps               */
119     int                        imask_nalloc; /**< allocation size of imask                     */
120     DeviceBuffer<unsigned int> imask;        /**< imask for 2 warps for each 4*j cluster group */
121     DeviceBuffer<nbnxn_excl_t> excl;         /**< atom interaction bits                        */
122     int                        nexcl;        /**< count for excl                               */
123     int                        excl_nalloc;  /**< allocation size of excl                      */
124
125     /* parameter+variables for normal and rolling pruning */
126     bool haveFreshList; /**< true after search, indictes that initial pruning with outer prunning is needed */
127     int  rollingPruningNumParts; /**< the number of parts/steps over which one cyle of roling pruning takes places */
128     int  rollingPruningPart; /**< the next part to which the roling pruning needs to be applied */
129 };
130
131 } // namespace Nbnxm
132
133 #endif