2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
38 * Data types used internally in the nbnxm_sycl module.
40 * \ingroup module_nbnxm
43 #ifndef NBNXM_SYCL_TYPES_H
44 #define NBNXM_SYCL_TYPES_H
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"
59 * \brief Staging area for temporary data downloaded from the GPU.
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.
67 float* e_lj = nullptr;
68 //! electrostatic energy
69 float* e_el = nullptr;
71 Float3* fshift = nullptr;
75 * \brief Nonbonded atom data - both inputs and outputs.
77 struct sycl_atomdata_t
81 //! number of local atoms
83 //! allocation size for the atom data (xq, f)
86 //! atom coordinates + charges, size \ref natoms
87 DeviceBuffer<Float4> xq;
88 //! force output array, size \ref natoms
89 DeviceBuffer<Float3> f;
91 //! LJ energy output, size 1
92 DeviceBuffer<float> eLJ;
93 //! Electrostatics energy input, size 1
94 DeviceBuffer<float> eElec;
97 DeviceBuffer<Float3> fShift;
99 //! number of atom types
101 //! atom type indices, size \ref natoms
102 DeviceBuffer<int> atomTypes;
103 //! sqrt(c6),sqrt(c12) size \ref natoms
104 DeviceBuffer<Float2> ljComb;
107 DeviceBuffer<Float3> shiftVec;
108 //! true if the shift vector has been uploaded
109 bool shiftVecUploaded;
112 class GpuEventSynchronizer;
115 * \brief Main data structure for SYCL nonbonded force calculations.
119 /*! \brief GPU device context.
121 * \todo Make it constant reference, once NbnxmGpu is a proper class.
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;
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. */
136 /*! \brief local and non-local GPU streams */
137 gmx::EnumerationArray<Nbnxm::InteractionLocality, const DeviceStream*> deviceStreams;
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;
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 } };
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;
163 /*! \brief True if there is work for the current domain in the
164 * respective locality.
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
171 gmx::EnumerationArray<Nbnxm::InteractionLocality, bool> haveWork = { { false } };
173 /*! \brief Pointer to event synchronizer triggered when the local
174 * GPU buffer ops / reduction is complete. Would be deprecated in SYCL.
176 * \note That the synchronizer is managed outside of this module
177 * in StatePropagatorDataGpu.
179 GpuEventSynchronizer* localFReductionDone = nullptr;
182 #endif /* NBNXM_SYCL_TYPES_H */