bff590c0a5104adf7391e30d5316dd985ddfa1aa
[alexxy/gromacs.git] / src / gromacs / nbnxm / sycl / nbnxm_sycl_data_mgmt.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  *  Stubs of functions that must be defined by nbnxm sycl implementation.
39  *
40  *  \ingroup module_nbnxm
41  */
42 #include "gmxpre.h"
43
44 #include "gromacs/gpu_utils/pmalloc.h"
45 #include "gromacs/hardware/device_information.h"
46 #include "gromacs/mdtypes/interaction_const.h"
47 #include "gromacs/nbnxm/atomdata.h"
48 #include "gromacs/nbnxm/gpu_data_mgmt.h"
49 #include "gromacs/nbnxm/nbnxm_gpu.h"
50 #include "gromacs/nbnxm/nbnxm_gpu_data_mgmt.h"
51 #include "gromacs/pbcutil/ishift.h"
52 #include "gromacs/utility/exceptions.h"
53
54 #include "nbnxm_sycl_types.h"
55
56 namespace Nbnxm
57 {
58
59 void gpu_init_platform_specific(NbnxmGpu* /* nb */)
60 {
61     // Nothing specific in SYCL
62 }
63
64 void gpu_free(NbnxmGpu* nb)
65 {
66     if (nb == nullptr)
67     {
68         return;
69     }
70
71     delete nb->timers;
72     sfree(nb->timings);
73
74     NBAtomData* atdat   = nb->atdat;
75     NBParamGpu* nbparam = nb->nbparam;
76
77     if (nbparam->elecType == ElecType::EwaldTab || nbparam->elecType == ElecType::EwaldTabTwin)
78     {
79         destroyParamLookupTable(&nbparam->coulomb_tab, nbparam->coulomb_tab_texobj);
80     }
81
82     if (!useLjCombRule(nb->nbparam->vdwType))
83     {
84         destroyParamLookupTable(&nbparam->nbfp, nbparam->nbfp_texobj);
85     }
86
87     if (nbparam->vdwType == VdwType::EwaldGeom || nbparam->vdwType == VdwType::EwaldLB)
88     {
89         destroyParamLookupTable(&nbparam->nbfp_comb, nbparam->nbfp_comb_texobj);
90     }
91
92     /* Free plist */
93     auto* plist = nb->plist[InteractionLocality::Local];
94     delete plist;
95     if (nb->bUseTwoStreams)
96     {
97         auto* plist_nl = nb->plist[InteractionLocality::NonLocal];
98         delete plist_nl;
99     }
100
101     /* Free nbst */
102     pfree(nb->nbst.eLJ);
103     nb->nbst.eLJ = nullptr;
104
105     pfree(nb->nbst.eElec);
106     nb->nbst.eElec = nullptr;
107
108     pfree(nb->nbst.fShift);
109     nb->nbst.fShift = nullptr;
110
111     delete atdat;
112     delete nbparam;
113     delete nb;
114 }
115
116 int gpu_min_ci_balanced(NbnxmGpu* nb)
117 {
118     // SYCL-TODO: Logic and magic values taken from OpenCL
119     static constexpr unsigned int balancedFactor = 50;
120     if (nb == nullptr)
121     {
122         return 0;
123     }
124     const cl::sycl::device device = nb->deviceContext_->deviceInfo().syclDevice;
125     const int numComputeUnits     = device.get_info<cl::sycl::info::device::max_compute_units>();
126     return balancedFactor * numComputeUnits;
127 }
128
129 } // namespace Nbnxm