Apply re-formatting to C++ in src/ tree.
[alexxy/gromacs.git] / src / gromacs / nbnxm / clusterdistancekerneltype.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2020, 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
39  * Declares the ClusterDistanceKernelType enum
40  *
41  * \author Berk Hess <hess@kth.se>
42  * \ingroup module_nbnxm
43  */
44
45 #ifndef GMX_NBNXM_CLUSTERDISTANCEKERNELTYPE_H
46 #define GMX_NBNXM_CLUSTERDISTANCEKERNELTYPE_H
47
48 #include "gromacs/nbnxm/atomdata.h"
49 #include "gromacs/simd/simd.h"
50 #include "gromacs/utility/gmxassert.h"
51
52 #include "pairlistparams.h"
53
54 //! The types of kernel for calculating the distance between pairs of atom clusters
55 enum class ClusterDistanceKernelType : int
56 {
57     CpuPlainC,    //!< Plain-C for CPU list
58     CpuSimd_4xM,  //!< SIMD for CPU list for j-cluster size matching the SIMD width
59     CpuSimd_2xMM, //!< SIMD for CPU list for j-cluster size matching half the SIMD width
60     Gpu           //!< For GPU list, can be either plain-C or SIMD
61 };
62
63 //! Return the cluster distance kernel type given the pairlist type and atomdata
64 static inline ClusterDistanceKernelType getClusterDistanceKernelType(const PairlistType pairlistType,
65                                                                      const nbnxn_atomdata_t& atomdata)
66 {
67     if (pairlistType == PairlistType::HierarchicalNxN)
68     {
69         return ClusterDistanceKernelType::Gpu;
70     }
71     else if (atomdata.XFormat == nbatXYZ)
72     {
73         return ClusterDistanceKernelType::CpuPlainC;
74     }
75     else if (pairlistType == PairlistType::Simple4x2)
76     {
77 #if GMX_SIMD && GMX_SIMD_REAL_WIDTH == 2
78         return ClusterDistanceKernelType::CpuSimd_4xM;
79 #else
80         GMX_RELEASE_ASSERT(false, "Expect 2-wide SIMD with 4x2 list and nbat SIMD layout");
81 #endif
82     }
83     else if (pairlistType == PairlistType::Simple4x4)
84     {
85 #if GMX_SIMD && GMX_SIMD_REAL_WIDTH == 4
86         return ClusterDistanceKernelType::CpuSimd_4xM;
87 #elif GMX_SIMD && GMX_SIMD_REAL_WIDTH == 8
88         return ClusterDistanceKernelType::CpuSimd_2xMM;
89 #else
90         GMX_RELEASE_ASSERT(false, "Expect 4-wide or 8-wide SIMD with 4x4 list and nbat SIMD layout");
91 #endif
92     }
93     else
94     {
95         GMX_ASSERT(pairlistType == PairlistType::Simple4x8, "Unhandled pairlist type");
96 #if GMX_SIMD && GMX_SIMD_REAL_WIDTH == 8
97         return ClusterDistanceKernelType::CpuSimd_4xM;
98 #elif GMX_SIMD && GMX_SIMD_REAL_WIDTH == 16
99         return ClusterDistanceKernelType::CpuSimd_2xMM;
100 #else
101         GMX_RELEASE_ASSERT(false,
102                            "Expect 8-wide or 16-wide SIMD with 4x4 list and nbat SIMD layout");
103 #endif
104     }
105
106     GMX_RELEASE_ASSERT(false, "We should have returned before getting here");
107     return ClusterDistanceKernelType::CpuPlainC;
108 }
109
110 #endif