Fix cmake policy warning
[alexxy/gromacs.git] / src / gromacs / ewald / pme-gpu-program-impl.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018, 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
37  * Declares PmeGpuProgramImpl, which stores PME GPU (compiled) kernel handles.
38  *
39  * \author Aleksei Iupinov <a.yupinov@gmail.com>
40  * \ingroup module_ewald
41  */
42 #ifndef GMX_EWALD_PME_PME_GPU_PROGRAM_IMPL_H
43 #define GMX_EWALD_PME_PME_GPU_PROGRAM_IMPL_H
44
45 #include "config.h"
46
47 #include "gromacs/utility/classhelpers.h"
48
49 #if GMX_GPU == GMX_GPU_CUDA
50 #include "gromacs/gpu_utils/gputraits.cuh"
51 #elif GMX_GPU == GMX_GPU_OPENCL
52 #include "gromacs/gpu_utils/gputraits_ocl.h"
53 #elif GMX_GPU == GMX_GPU_NONE
54 // TODO place in gputraits_stub.h
55 using Context = void *;
56 #endif
57
58 struct gmx_device_info_t;
59
60 /*! \internal
61  * \brief
62  * PME GPU persistent host program/kernel data, which should be initialized once for the whole execution.
63  *
64  * Primary purpose of this is to not recompile GPU kernels for each OpenCL unit test,
65  * while the relevant GPU context (e.g. cl_context) instance persists.
66  * In CUDA, this just assigns the kernel function pointers.
67  * This also implicitly relies on the fact that reasonable share of the kernels are always used.
68  * If there were more template parameters, even smaller share of all possible kernels would be used.
69  *
70  * \todo In future if we would need to react to either user input or
71  * auto-tuning to compile different kernels, then we might wish to
72  * revisit the number of kernels we pre-compile, and/or the management
73  * of their lifetime.
74  *
75  * This also doesn't manage cuFFT/clFFT kernels, which depend on the PME grid dimensions.
76  *
77  * TODO: pass cl_context to the constructor and not create it inside.
78  * See also Redmine #2522.
79  */
80 struct PmeGpuProgramImpl
81 {
82     /*! \brief
83      * This is a handle to the GPU context, which is just a dummy in CUDA,
84      * but is created/destroyed by this class in OpenCL.
85      * TODO: Later we want to be able to own the context at a higher level and not here,
86      * but this class would still need the non-owning context handle to build the kernels.
87      */
88     Context context;
89
90     //! Conveniently all the PME kernels use the same single argument type
91 #if GMX_GPU == GMX_GPU_CUDA
92     using PmeKernelHandle = void(*)(const struct PmeGpuCudaKernelParams);
93 #elif GMX_GPU == GMX_GPU_OPENCL
94     using PmeKernelHandle = cl_kernel;
95 #else
96     using PmeKernelHandle = void *;
97 #endif
98
99     /*! \brief
100      * Maximum synchronous GPU thread group execution width.
101      * "Warp" is a CUDA term which we end up reusing in OpenCL kernels as well.
102      * For CUDA, this is a static value that comes from gromacs/gpu_utils/cuda_arch_utils.cuh;
103      * for OpenCL, we have to query it dynamically.
104      */
105     size_t warpSize;
106
107     //@{
108     /**
109      * Spread/spline kernels are compiled only for order of 4.
110      * Spreading kernels also have hardcoded X/Y indices wrapping parameters,
111      * as a placeholder for implementing 1/2D decomposition.
112      */
113     size_t          spreadWorkGroupSize;
114
115     PmeKernelHandle splineKernel;
116     PmeKernelHandle spreadKernel;
117     PmeKernelHandle splineAndSpreadKernel;
118     //@}
119
120     //@{
121     /** Same for gather: hardcoded X/Y unwrap parameters, order of 4, plus
122      * it can either reduce with previous forces in the host buffer, or ignore them.
123      */
124     size_t          gatherWorkGroupSize;
125
126     PmeKernelHandle gatherReduceWithInputKernel;
127     PmeKernelHandle gatherKernel;
128     //@}
129
130     //@{
131     /** Solve kernel doesn't care about the interpolation order, but can optionally
132      * compute energy and virial, and supports XYZ and YZX grid orderings.
133      */
134     size_t          solveMaxWorkGroupSize;
135
136     PmeKernelHandle solveYZXKernel;
137     PmeKernelHandle solveXYZKernel;
138     PmeKernelHandle solveYZXEnergyKernel;
139     PmeKernelHandle solveXYZEnergyKernel;
140     //@}
141
142     PmeGpuProgramImpl() = delete;
143     //! Constructor for the given device
144     explicit PmeGpuProgramImpl(const gmx_device_info_t *deviceInfo);
145     ~PmeGpuProgramImpl();
146     GMX_DISALLOW_COPY_AND_ASSIGN(PmeGpuProgramImpl);
147
148     private:
149         // Compiles kernels, if supported. Called by the constructor.
150         void compileKernels(const gmx_device_info_t *deviceInfo);
151 };
152
153 #endif