5542cbecb9698032760a22911f62fd48ae4067f9
[alexxy/gromacs.git] / src / gromacs / nbnxm / pairlistwork.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 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
36 /*! \internal \file
37  *
38  * \brief Declares working data structures for the CPU and GPU pairlists
39  *
40  * \author Berk Hess <hess@kth.se>
41  *
42  * \ingroup module_nbnxn
43  */
44
45 #ifndef GMX_NBNXM_PAIRLISTWORK_H
46 #define GMX_NBNXM_PAIRLISTWORK_H
47
48 #include <memory>
49 #include <vector>
50
51 #include "gromacs/nbnxm/pairlist.h"
52 #include "gromacs/simd/simd.h"
53
54 #include "grid.h"
55
56 /* Working data for the actual i-supercell during pair search */
57 struct NbnxnPairlistCpuWork
58 {
59     // Struct for storing coordinats and bounding box for an i-entry during search
60     struct IClusterData
61     {
62         IClusterData() :
63             bb(1),
64             x(c_nbnxnCpuIClusterSize*DIM),
65             xSimd(c_nbnxnCpuIClusterSize*DIM*GMX_REAL_MAX_SIMD_WIDTH)
66         {
67         }
68
69         // The bounding boxes, pbc shifted, for each cluster
70         AlignedVector<nbnxn_bb_t> bb;
71         // The coordinates, pbc shifted, for each atom
72         std::vector<real>         x;
73         // Aligned list for storing 4*DIM*GMX_SIMD_REAL_WIDTH reals
74         AlignedVector<real>       xSimd;
75     };
76
77     // Protect data from cache pollution between threads
78     gmx_cache_protect_t       cp0;
79
80     // Work data for generating an IEntry in the pairlist
81     IClusterData              iClusterData;
82     // The current cj_ind index for the current list
83     int                       cj_ind;
84     // Temporary j-cluster list, used for sorting on exclusions
85     std::vector<nbnxn_cj_t>   cj;
86
87     // Nr. of cluster pairs without Coulomb for flop counting
88     int                       ncj_noq;
89     // Nr. of cluster pairs with 1/2 LJ for flop count
90     int                       ncj_hlj;
91
92     // Protect data from cache pollution between threads
93     gmx_cache_protect_t       cp1;
94 };
95
96 /* Working data for the actual i-supercell during pair search */
97 struct NbnxnPairlistGpuWork
98 {
99     struct ISuperClusterData
100     {
101         ISuperClusterData() :
102             bb(c_gpuNumClusterPerCell),
103 #if NBNXN_SEARCH_BB_SIMD4
104             bbPacked(c_gpuNumClusterPerCell/STRIDE_PBB*NNBSBB_XXXX),
105 #endif
106             x(c_gpuNumClusterPerCell*c_nbnxnGpuClusterSize*DIM),
107             xSimd(c_gpuNumClusterPerCell*c_nbnxnGpuClusterSize*DIM)
108         {
109         }
110
111         // The bounding boxes, pbc shifted, for each cluster
112         AlignedVector<nbnxn_bb_t> bb;
113         // As bb, but in packed xxxx format
114         AlignedVector<float>      bbPacked;
115         // The coordinates, pbc shifted, for each atom
116         AlignedVector<real>       x;
117         // Aligned coordinate list used for 4*DIM*GMX_SIMD_REAL_WIDTH floats
118         AlignedVector<real>       xSimd;
119     };
120
121     NbnxnPairlistGpuWork() :
122         distanceBuffer(c_gpuNumClusterPerCell),
123         sci_sort({}, {gmx::PinningPolicy::PinnedIfSupported})
124     {
125     }
126
127     // Protect data from cache pollution between threads
128     gmx_cache_protect_t       cp0;
129
130     // Work data for generating an i-entry in the pairlist
131     ISuperClusterData         iSuperClusterData;
132     // The current j-cluster index for the current list
133     int                       cj_ind;
134     // Bounding box distance work array
135     AlignedVector<float>      distanceBuffer;
136
137     // Buffer for sorting list entries
138     std::vector<int>          sortBuffer;
139
140     // Second sci array, for sorting
141     gmx::HostVector<nbnxn_sci_t> sci_sort;
142
143     // Protect data from cache pollution between threads
144     gmx_cache_protect_t       cp1;
145 };
146
147 #endif