f5bd3d01ab096ef770fb074dcf9e6af423111ac9
[alexxy/gromacs.git] / src / gromacs / mdlib / nbnxn_consts.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014 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 #ifndef _nbnxn_consts_h
37 #define _nbnxn_consts_h
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43
44 /* The number of pair-search sub-cells per super-cell, used for GPU */
45 #define GPU_NSUBCELL_Z 2
46 #define GPU_NSUBCELL_Y 2
47 #define GPU_NSUBCELL_X 2
48 #define GPU_NSUBCELL   (GPU_NSUBCELL_Z*GPU_NSUBCELL_Y*GPU_NSUBCELL_X)
49 /* In the non-bonded GPU kernel we operate on cluster-pairs, not cells.
50  * The number of cluster in a super-cluster matches the number of sub-cells
51  * in a pair-search cell, so we introduce a new name for the same value.
52  */
53 #define NBNXN_GPU_NCLUSTER_PER_SUPERCLUSTER  GPU_NSUBCELL
54
55 /* With CPU kernels the i-cluster size is always 4 atoms.
56  * With x86 SIMD the j-cluster size can be 2, 4 or 8, otherwise 4.
57  */
58 #define NBNXN_CPU_CLUSTER_I_SIZE       4
59
60 #define NBNXN_CPU_CLUSTER_I_SIZE_2LOG  2
61
62 /* With GPU kernels the cluster size is 8 atoms */
63 #define NBNXN_GPU_CLUSTER_SIZE         8
64
65 /* With GPU kernels we group cluster pairs in 4 to optimize memory usage.
66  * To change this, also change nbnxn_cj4_t in include/types/nbnxn_pairlist.h.
67  */
68 #define NBNXN_GPU_JGROUP_SIZE       4
69 #define NBNXN_GPU_JGROUP_SIZE_2LOG  2
70
71 /* To avoid NaN when excluded atoms are at zero distance, we add a small
72  * number to r^2. NBNXN_AVOID_SING_R2_INC^-3 should fit in real.
73  */
74 #ifndef GMX_DOUBLE
75 #define NBNXN_AVOID_SING_R2_INC  1.0e-12f
76 #else
77 /* The double prec. x86 SIMD kernels use a single prec. invsqrt, so > 1e-38 */
78 #define NBNXN_AVOID_SING_R2_INC  1.0e-36
79 #endif
80
81 /* Coulomb force table size chosen such that it fits along the non-bonded
82    parameters in the texture cache. */
83 #define GPU_EWALD_COULOMB_FORCE_TABLE_SIZE 1536
84
85
86 /* Strides for x/f with xyz and xyzq coordinate (and charge) storage */
87 #define STRIDE_XYZ   3
88 #define STRIDE_XYZQ  4
89 /* Size of packs of x, y or z with SSE/AVX packed coords/forces */
90 #define PACK_X4      4
91 #define PACK_X8      8
92 /* Strides for a pack of 4 and 8 coordinates/forces */
93 #define STRIDE_P4    (DIM*PACK_X4)
94 #define STRIDE_P8    (DIM*PACK_X8)
95
96 /* Index of atom a into the SSE/AVX coordinate/force array */
97 #define X4_IND_A(a)  (STRIDE_P4*((a) >> 2) + ((a) & (PACK_X4 - 1)))
98 #define X8_IND_A(a)  (STRIDE_P8*((a) >> 3) + ((a) & (PACK_X8 - 1)))
99
100
101 /* Cluster-pair Interaction masks for 4xN and 2xNN kernels.
102  * Bit i*CJ_SIZE + j tells if atom i and j interact.
103  */
104 /* All interaction mask is the same for all kernels */
105 static const unsigned int NBNXN_INTERACTION_MASK_ALL       = 0xffffffffU;
106 /* 4x4 kernel diagonal mask */
107 static const unsigned int NBNXN_INTERACTION_MASK_DIAG      = 0x08ceU;
108 /* 4x2 kernel diagonal masks */
109 static const unsigned int NBNXN_INTERACTION_MASK_DIAG_J2_0 = 0x0002U;
110 static const unsigned int NBNXN_INTERACTION_MASK_DIAG_J2_1 = 0x002fU;
111 /* 4x8 kernel diagonal masks */
112 static const unsigned int NBNXN_INTERACTION_MASK_DIAG_J8_0 = 0xf0f8fcfeU;
113 static const unsigned int NBNXN_INTERACTION_MASK_DIAG_J8_1 = 0x0080c0e0U;
114
115
116 #ifdef __cplusplus
117 }
118 #endif
119
120 #endif