Rename our SYCL aliases floatN to FloatN
[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 /*! \internal
59  * \brief Staging area for temporary data downloaded from the GPU.
60  *
61  * Since SYCL buffers already have host-side storage, this is a bit redundant.
62  * But it allows prefetching of the data from GPU, and brings GPU backends closer together.
63  */
64 struct nb_staging_t
65 {
66     //! LJ energy
67     float* e_lj = nullptr;
68     //! electrostatic energy
69     float* e_el = nullptr;
70     //! shift forces
71     Float3* fshift = nullptr;
72 };
73
74 /** \internal
75  * \brief Nonbonded atom data - both inputs and outputs.
76  */
77 struct sycl_atomdata_t
78 {
79     //! number of atoms
80     int natoms;
81     //! number of local atoms
82     int natoms_local; //
83     //! allocation size for the atom data (xq, f)
84     int numAlloc;
85
86     //! atom coordinates + charges, size \ref natoms
87     DeviceBuffer<Float4> xq;
88     //! force output array, size \ref natoms
89     DeviceBuffer<Float3> f;
90
91     //! LJ energy output, size 1
92     DeviceBuffer<float> eLJ;
93     //! Electrostatics energy input, size 1
94     DeviceBuffer<float> eElec;
95
96     //! shift forces
97     DeviceBuffer<Float3> fShift;
98
99     //! number of atom types
100     int numTypes;
101     //! atom type indices, size \ref natoms
102     DeviceBuffer<int> atomTypes;
103     //! sqrt(c6),sqrt(c12) size \ref natoms
104     DeviceBuffer<Float2> ljComb;
105
106     //! shifts
107     DeviceBuffer<Float3> shiftVec;
108     //! true if the shift vector has been uploaded
109     bool shiftVecUploaded;
110 };
111
112 class GpuEventSynchronizer;
113
114 /*! \internal
115  * \brief Main data structure for SYCL nonbonded force calculations.
116  */
117 struct NbnxmGpu
118 {
119     /*! \brief GPU device context.
120      *
121      * \todo Make it constant reference, once NbnxmGpu is a proper class.
122      */
123     const DeviceContext* deviceContext_;
124     /*! \brief true if doing both local/non-local NB work on GPU */
125     bool bUseTwoStreams = false;
126     /*! \brief true indicates that the nonlocal_done event was marked */
127     bool bNonLocalStreamDoneMarked = false;
128     /*! \brief atom data */
129     sycl_atomdata_t* atdat = nullptr;
130
131     NBParamGpu* nbparam = nullptr;
132     /*! \brief pair-list data structures (local and non-local) */
133     gmx::EnumerationArray<Nbnxm::InteractionLocality, Nbnxm::gpu_plist*> plist = { { nullptr } };
134     /*! \brief staging area where fshift/energies get downloaded. Will be removed in SYCL. */
135     nb_staging_t nbst;
136     /*! \brief local and non-local GPU streams */
137     gmx::EnumerationArray<Nbnxm::InteractionLocality, const DeviceStream*> deviceStreams;
138
139     /*! \brief True if event-based timing is enabled. Always false for SYCL. */
140     bool bDoTime = false;
141     /*! \brief Dummy timers. */
142     Nbnxm::gpu_timers_t* timers = nullptr;
143     /*! \brief Dummy timing data. */
144     gmx_wallclock_gpu_nbnxn_t* timings = nullptr;
145
146     //! true when a pair-list transfer has been done at this step
147     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> didPairlistH2D = { { false } };
148     //! true when we we did pruning on this step
149     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> didPrune = { { false } };
150     //! true when we did rolling pruning (at the previous step)
151     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> didRollingPrune = { { false } };
152
153     /*! \brief Event triggered when the non-local non-bonded
154      * kernel is done (and the local transfer can proceed) */
155     GpuEventSynchronizer nonlocal_done;
156     /*! \brief Event triggered when the tasks issued in the local
157      * stream that need to precede the non-local force or buffer
158      * operation calculations are done (e.g. f buffer 0-ing, local
159      * x/q H2D, buffer op initialization in local stream that is
160      * required also by nonlocal stream ) */
161     GpuEventSynchronizer misc_ops_and_local_H2D_done;
162
163     /*! \brief True if there is work for the current domain in the
164      * respective locality.
165      *
166      * This includes local/nonlocal GPU work, either bonded or
167      * nonbonded, scheduled to be executed in the current
168      * domain. As long as bonded work is not split up into
169      * local/nonlocal, if there is bonded GPU work, both flags
170      * will be true. */
171     gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> haveWork = { { false } };
172
173     /*! \brief Pointer to event synchronizer triggered when the local
174      * GPU buffer ops / reduction is complete. Would be deprecated in SYCL.
175      *
176      * \note That the synchronizer is managed outside of this module
177      * in StatePropagatorDataGpu.
178      */
179     GpuEventSynchronizer* localFReductionDone = nullptr;
180 };
181
182 #endif /* NBNXM_SYCL_TYPES_H */