ad5f25f373cc16324bdefd63a95360641fb6be56
[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, 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
65 getClusterDistanceKernelType(const PairlistType      pairlistType,
66                              const nbnxn_atomdata_t &atomdata)
67 {
68     if (pairlistType == PairlistType::HierarchicalNxN)
69     {
70         return ClusterDistanceKernelType::Gpu;
71     }
72     else if (atomdata.XFormat == nbatXYZ)
73     {
74         return ClusterDistanceKernelType::CpuPlainC;
75     }
76     else if (pairlistType == PairlistType::Simple4x2)
77     {
78 #if GMX_SIMD && GMX_SIMD_REAL_WIDTH == 2
79         return ClusterDistanceKernelType::CpuSimd_4xM;
80 #else
81         GMX_RELEASE_ASSERT(false, "Expect 2-wide SIMD with 4x2 list and nbat SIMD layout");
82 #endif
83     }
84     else if (pairlistType == PairlistType::Simple4x4)
85     {
86 #if GMX_SIMD && GMX_SIMD_REAL_WIDTH == 4
87         return ClusterDistanceKernelType::CpuSimd_4xM;
88 #elif GMX_SIMD && GMX_SIMD_REAL_WIDTH == 8
89         return ClusterDistanceKernelType::CpuSimd_2xMM;
90 #else
91         GMX_RELEASE_ASSERT(false, "Expect 4-wide or 8-wide SIMD with 4x4 list and nbat SIMD layout");
92 #endif
93     }
94     else
95     {
96         GMX_ASSERT(pairlistType == PairlistType::Simple4x8, "Unhandled pairlist type");
97 #if GMX_SIMD && GMX_SIMD_REAL_WIDTH == 8
98         return ClusterDistanceKernelType::CpuSimd_4xM;
99 #elif GMX_SIMD && GMX_SIMD_REAL_WIDTH == 16
100         return ClusterDistanceKernelType::CpuSimd_2xMM;
101 #else
102         GMX_RELEASE_ASSERT(false, "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