c1e23c1a7420f94bf59801e59a12f75f35c26759
[alexxy/gromacs.git] / src / gromacs / nbnxm / sycl / nbnxm_sycl_types.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2020,2021, 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  *  \brief
38  *  Data types used internally in the nbnxm_sycl module.
39  *
40  *  \ingroup module_nbnxm
41  */
42
43 #ifndef NBNXM_SYCL_TYPES_H
44 #define NBNXM_SYCL_TYPES_H
45
46 #include "gromacs/gpu_utils/devicebuffer.h"
47 #include "gromacs/gpu_utils/devicebuffer_sycl.h"
48 #include "gromacs/gpu_utils/gmxsycl.h"
49 #include "gromacs/gpu_utils/gpueventsynchronizer_sycl.h"
50 #include "gromacs/gpu_utils/gputraits.h"
51 #include "gromacs/gpu_utils/syclutils.h"
52 #include "gromacs/nbnxm/gpu_types_common.h"
53 #include "gromacs/nbnxm/nbnxm.h"
54 #include "gromacs/nbnxm/pairlist.h"
55 #include "gromacs/timing/gpu_timing.h"
56 #include "gromacs/utility/enumerationhelpers.h"
57
58 class GpuEventSynchronizer;
59
60 /*! \internal
61  * \brief Main data structure for SYCL nonbonded force calculations.
62  */
63 struct NbnxmGpu
64 {
65     /*! \brief GPU device context.
66      *
67      * \todo Make it constant reference, once NbnxmGpu is a proper class.
68      */
69     const DeviceContext* deviceContext_;
70     /*! \brief true if doing both local/non-local NB work on GPU */
71     bool bUseTwoStreams = false;
72     /*! \brief true indicates that the nonlocal_done event was marked */
73     bool bNonLocalStreamDoneMarked = false;
74     /*! \brief atom data */
75     NBAtomData* atdat = nullptr;
76
77     NBParamGpu* nbparam = nullptr;
78     /*! \brief pair-list data structures (local and non-local) */
79     gmx::EnumerationArray<Nbnxm::InteractionLocality, Nbnxm::gpu_plist*> plist = { { nullptr } };
80     /*! \brief staging area where fshift/energies get downloaded. Will be removed in SYCL. */
81     NBStagingData nbst;
82     /*! \brief local and non-local GPU streams */
83     gmx::EnumerationArray<Nbnxm::InteractionLocality, const DeviceStream*> deviceStreams;
84
85     /*! \brief True if event-based timing is enabled. Always false for SYCL. */
86     bool bDoTime = false;
87     /*! \brief Dummy timers. */
88     Nbnxm::gpu_timers_t* timers = nullptr;
89     /*! \brief Dummy timing data. */
90     gmx_wallclock_gpu_nbnxn_t* timings = nullptr;
91
92     //! true when a pair-list transfer has been done at this step
93     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> didPairlistH2D = { { false } };
94     //! true when we we did pruning on this step
95     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> didPrune = { { false } };
96     //! true when we did rolling pruning (at the previous step)
97     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> didRollingPrune = { { false } };
98
99     /*! \brief Event triggered when the non-local non-bonded
100      * kernel is done (and the local transfer can proceed) */
101     GpuEventSynchronizer nonlocal_done;
102     /*! \brief Event triggered when the tasks issued in the local
103      * stream that need to precede the non-local force or buffer
104      * operation calculations are done (e.g. f buffer 0-ing, local
105      * x/q H2D, buffer op initialization in local stream that is
106      * required also by nonlocal stream ) */
107     GpuEventSynchronizer misc_ops_and_local_H2D_done;
108
109     /*! \brief True if there is work for the current domain in the
110      * respective locality.
111      *
112      * This includes local/nonlocal GPU work, either bonded or
113      * nonbonded, scheduled to be executed in the current
114      * domain. As long as bonded work is not split up into
115      * local/nonlocal, if there is bonded GPU work, both flags
116      * will be true. */
117     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> haveWork = { { false } };
118
119     /*! \brief Pointer to event synchronizer triggered when the local
120      * GPU buffer ops / reduction is complete. Would be deprecated in SYCL.
121      *
122      * \note That the synchronizer is managed outside of this module
123      * in StatePropagatorDataGpu.
124      */
125     GpuEventSynchronizer* localFReductionDone = nullptr;
126 };
127
128 #endif /* NBNXM_SYCL_TYPES_H */