SYCL: Use acc.bind(cgh) instead of cgh.require(acc)
[alexxy/gromacs.git] / src / gromacs / nbnxm / sycl / nbnxm_sycl.cpp
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 management and kernel launch functions for nbnxm sycl.
39  *
40  *  \ingroup module_nbnxm
41  */
42 #include "gmxpre.h"
43
44 #include "gromacs/nbnxm/gpu_common.h"
45 #include "gromacs/utility/exceptions.h"
46
47 #include "nbnxm_sycl_kernel.h"
48 #include "nbnxm_sycl_kernel_pruneonly.h"
49 #include "nbnxm_sycl_types.h"
50
51 namespace Nbnxm
52 {
53
54 void gpu_launch_kernel_pruneonly(NbnxmGpu* nb, const InteractionLocality iloc, const int numParts)
55 {
56     gpu_plist* plist = nb->plist[iloc];
57
58     if (plist->haveFreshList)
59     {
60         GMX_ASSERT(numParts == 1, "With first pruning we expect 1 part");
61
62         /* Set rollingPruningNumParts to signal that it is not set */
63         plist->rollingPruningNumParts = 0;
64         plist->rollingPruningPart     = 0;
65     }
66     else
67     {
68         if (plist->rollingPruningNumParts == 0)
69         {
70             plist->rollingPruningNumParts = numParts;
71         }
72         else
73         {
74             GMX_ASSERT(numParts == plist->rollingPruningNumParts,
75                        "It is not allowed to change numParts in between list generation steps");
76         }
77     }
78
79     /* Use a local variable for part and update in plist, so we can return here
80      * without duplicating the part increment code.
81      */
82     const int part = plist->rollingPruningPart;
83
84     plist->rollingPruningPart++;
85     if (plist->rollingPruningPart >= plist->rollingPruningNumParts)
86     {
87         plist->rollingPruningPart = 0;
88     }
89
90     /* Compute the number of list entries to prune in this pass */
91     const int numSciInPart = (plist->nsci - part) / numParts;
92
93     /* Don't launch the kernel if there is no work to do */
94     if (numSciInPart <= 0)
95     {
96         plist->haveFreshList = false;
97         return;
98     }
99
100     launchNbnxmKernelPruneOnly(nb, iloc, numParts, part, numSciInPart);
101
102     if (plist->haveFreshList)
103     {
104         plist->haveFreshList = false;
105         nb->didPrune[iloc]   = true; // Mark that pruning has been done
106     }
107     else
108     {
109         nb->didRollingPrune[iloc] = true; // Mark that rolling pruning has been done
110     }
111 }
112
113 void gpu_launch_kernel(NbnxmGpu* nb, const gmx::StepWorkload& stepWork, const Nbnxm::InteractionLocality iloc)
114 {
115     const NBParamGpu* nbp   = nb->nbparam;
116     gpu_plist*        plist = nb->plist[iloc];
117
118     if (canSkipNonbondedWork(*nb, iloc))
119     {
120         plist->haveFreshList = false;
121         return;
122     }
123
124     if (nbp->useDynamicPruning && plist->haveFreshList)
125     {
126         // Prunes for rlistOuter and rlistInner, sets plist->haveFreshList=false
127         gpu_launch_kernel_pruneonly(nb, iloc, 1);
128     }
129
130     if (plist->nsci == 0)
131     {
132         /* Don't launch an empty local kernel */
133         return;
134     }
135
136     launchNbnxmKernel(nb, stepWork, iloc);
137 }
138
139 } // namespace Nbnxm