91464b8010efaa9e88f52c75118998ca109695e2
[alexxy/gromacs.git] / src / gromacs / nbnxm / cuda / nbnxm_cuda_types.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2012, The GROMACS development team.
6  * Copyright (c) 2013-2019,2020,2021, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37
38 /*! \internal \file
39  *  \brief
40  *  Data types used internally in the nbnxn_cuda module.
41  *
42  *  \author Szilárd Páll <pall.szilard@gmail.com>
43  *  \ingroup module_nbnxm
44  */
45
46 #ifndef NBNXM_CUDA_TYPES_H
47 #define NBNXM_CUDA_TYPES_H
48
49 #include "gromacs/gpu_utils/cuda_arch_utils.cuh"
50 #include "gromacs/gpu_utils/cudautils.cuh"
51 #include "gromacs/gpu_utils/devicebuffer.h"
52 #include "gromacs/gpu_utils/devicebuffer_datatype.h"
53 #include "gromacs/gpu_utils/gpueventsynchronizer.cuh"
54 #include "gromacs/gpu_utils/gputraits.cuh"
55 #include "gromacs/mdtypes/interaction_const.h"
56 #include "gromacs/nbnxm/gpu_types_common.h"
57 #include "gromacs/nbnxm/nbnxm.h"
58 #include "gromacs/nbnxm/pairlist.h"
59 #include "gromacs/timing/gpu_timing.h"
60 #include "gromacs/utility/enumerationhelpers.h"
61
62 /* TODO: consider moving this to kernel_utils */
63 /* Convenience defines */
64 /*! \brief cluster size = number of atoms per cluster. */
65 static constexpr int c_clSize = c_nbnxnGpuClusterSize;
66
67 /*! \internal
68  * \brief Main data structure for CUDA nonbonded force calculations.
69  */
70 struct NbnxmGpu
71 {
72     /*! \brief GPU device context.
73      *
74      * \todo Make it constant reference, once NbnxmGpu is a proper class.
75      */
76     const DeviceContext* deviceContext_;
77     /*! \brief true if doing both local/non-local NB work on GPU */
78     bool bUseTwoStreams = false;
79     //! true indicates that the nonlocal_done event was marked
80     bool bNonLocalStreamDoneMarked = false;
81
82     /*! \brief atom data */
83     NBAtomDataGpu* atdat = nullptr;
84     /*! \brief array of atom indices */
85     int* atomIndices = nullptr;
86     /*! \brief size of atom indices */
87     int atomIndicesSize = 0;
88     /*! \brief size of atom indices allocated in device buffer */
89     int atomIndicesSize_alloc = 0;
90     /*! \brief x buf ops num of atoms */
91     int* cxy_na = nullptr;
92     /*! \brief number of elements in cxy_na */
93     int ncxy_na = 0;
94     /*! \brief number of elements allocated allocated in device buffer */
95     int ncxy_na_alloc = 0;
96     /*! \brief x buf ops cell index mapping */
97     int* cxy_ind = nullptr;
98     /*! \brief number of elements in cxy_ind */
99     int ncxy_ind = 0;
100     /*! \brief number of elements allocated allocated in device buffer */
101     int ncxy_ind_alloc = 0;
102     /*! \brief parameters required for the non-bonded calc. */
103     NBParamGpu* nbparam = nullptr;
104     /*! \brief pair-list data structures (local and non-local) */
105     gmx::EnumerationArray<Nbnxm::InteractionLocality, Nbnxm::gpu_plist*> plist = { { nullptr } };
106     /*! \brief staging area where fshift/energies get downloaded */
107     NBStagingData nbst;
108     /*! \brief local and non-local GPU streams */
109     gmx::EnumerationArray<Nbnxm::InteractionLocality, const DeviceStream*> deviceStreams;
110
111     /*! \brief Event triggered when the non-local non-bonded
112      * kernel is done (and the local transfer can proceed) */
113     GpuEventSynchronizer nonlocal_done;
114     /*! \brief Event triggered when the tasks issued in the local
115      * stream that need to precede the non-local force or buffer
116      * operation calculations are done (e.g. f buffer 0-ing, local
117      * x/q H2D, buffer op initialization in local stream that is
118      * required also by nonlocal stream ) */
119     GpuEventSynchronizer misc_ops_and_local_H2D_done;
120
121     /*! \brief True if there is work for the current domain in the
122      * respective locality.
123      *
124      * This includes local/nonlocal GPU work, either bonded or
125      * nonbonded, scheduled to be executed in the current
126      * domain. As long as bonded work is not split up into
127      * local/nonlocal, if there is bonded GPU work, both flags
128      * will be true. */
129     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> haveWork = { { false } };
130
131     /* NOTE: With current CUDA versions (<=5.0) timing doesn't work with multiple
132      * concurrent streams, so we won't time if both l/nl work is done on GPUs.
133      * Timer init/uninit is still done even with timing off so only the condition
134      * setting bDoTime needs to be change if this CUDA "feature" gets fixed. */
135     /*! \brief True if event-based timing is enabled. */
136     bool bDoTime = false;
137     /*! \brief CUDA event-based timers. */
138     Nbnxm::GpuTimers* timers = nullptr;
139     /*! \brief Timing data. TODO: deprecate this and query timers for accumulated data instead */
140     gmx_wallclock_gpu_nbnxn_t* timings = nullptr;
141 };
142
143 #endif /* NBNXN_CUDA_TYPES_H */