378015fb309729f3c1ef5886de03cffdf1b358f5
[alexxy/gromacs.git] / src / gromacs / gpu_utils / gpu_utils.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2010, The GROMACS development team.
6  * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
7  * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 /*! \libinternal \file
39  *  \brief Declare functions for detection and initialization for GPU devices.
40  *
41  *  \author Szilard Pall <pall.szilard@gmail.com>
42  *  \author Mark Abraham <mark.j.abraham@gmail.com>
43  *
44  *  \inlibraryapi
45  */
46 #ifndef GMX_GPU_UTILS_GPU_UTILS_H
47 #define GMX_GPU_UTILS_GPU_UTILS_H
48
49 #include <cstdio>
50
51 #include <string>
52 #include <vector>
53
54 #include "gromacs/gpu_utils/gpu_macros.h"
55 #include "gromacs/utility/basedefinitions.h"
56
57 namespace gmx
58 {
59 class MDLogger;
60 }
61
62 //! Enum which is only used to describe transfer calls at the moment
63 enum class GpuApiCallBehavior : int
64 {
65     //! Synchronous
66     Sync,
67     //! Asynchronous
68     Async,
69     //! Size of the enumeration
70     Count
71 };
72
73 //! String corresponding to GPU API call behavior
74 const char* enumValueToString(GpuApiCallBehavior enumValue);
75
76 //! Types of actions associated to waiting or checking the completion of GPU tasks
77 enum class GpuTaskCompletion
78 {
79     Wait, /*<< Issue a blocking wait for the task */
80     Check /*<< Only check whether the task has completed */
81 };
82
83 /*! \brief Check if GROMACS has been built with GPU support.
84  *
85  * \param[in] error Pointer to error string or nullptr.
86  * \todo Move this to NB module once it exists.
87  */
88 bool buildSupportsNonbondedOnGpu(std::string* error);
89
90 /*! \brief Starts the GPU profiler if mdrun is being profiled.
91  *
92  *  When a profiler run is in progress (based on the presence of the NVPROF_ID
93  *  env. var.), the profiler is started to begin collecting data during the
94  *  rest of the run (or until stopGpuProfiler is called).
95  *
96  *  Note that this is implemented only for the CUDA API.
97  */
98 CUDA_FUNC_QUALIFIER
99 void startGpuProfiler() CUDA_FUNC_TERM;
100
101
102 /*! \brief Resets the GPU profiler if mdrun is being profiled.
103  *
104  * When a profiler run is in progress (based on the presence of the NVPROF_ID
105  * env. var.), the profiler data is restet in order to eliminate the data collected
106  * from the preceding part fo the run.
107  *
108  * This function should typically be called at the mdrun counter reset time.
109  *
110  * Note that this is implemented only for the CUDA API.
111  */
112 CUDA_FUNC_QUALIFIER
113 void resetGpuProfiler() CUDA_FUNC_TERM;
114
115
116 /*! \brief Stops the CUDA profiler if mdrun is being profiled.
117  *
118  *  This function can be called at cleanup when skipping recording
119  *  recording subsequent API calls from being traces/profiled is desired,
120  *  e.g. before uninitialization.
121  *
122  *  Note that this is implemented only for the CUDA API.
123  */
124 CUDA_FUNC_QUALIFIER
125 void stopGpuProfiler() CUDA_FUNC_TERM;
126
127 //! Tells whether the host buffer was pinned for non-blocking transfers. Only implemented for CUDA.
128 CUDA_FUNC_QUALIFIER
129 bool isHostMemoryPinned(const void* CUDA_FUNC_ARGUMENT(h_ptr)) CUDA_FUNC_TERM_WITH_RETURN(false);
130
131 /*! \brief Enable peer access between GPUs where supported
132  * \param[in] gpuIdsToUse   List of GPU IDs in use
133  * \param[in] mdlog         Logger object
134  */
135 CUDA_FUNC_QUALIFIER
136 void setupGpuDevicePeerAccess(const std::vector<int>& CUDA_FUNC_ARGUMENT(gpuIdsToUse),
137                               const gmx::MDLogger&    CUDA_FUNC_ARGUMENT(mdlog)) CUDA_FUNC_TERM;
138
139 #endif