2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
38 /*! \libinternal \file
39 * \brief Declare functions for detection and initialization for GPU devices.
41 * \author Szilard Pall <pall.szilard@gmail.com>
42 * \author Mark Abraham <mark.j.abraham@gmail.com>
46 #ifndef GMX_GPU_UTILS_GPU_UTILS_H
47 #define GMX_GPU_UTILS_GPU_UTILS_H
54 #include "gromacs/gpu_utils/gpu_macros.h"
55 #include "gromacs/utility/basedefinitions.h"
62 //! Enum which is only used to describe transfer calls at the moment
63 enum class GpuApiCallBehavior : int
69 //! Size of the enumeration
73 //! String corresponding to GPU API call behavior
74 const char* enumValueToString(GpuApiCallBehavior enumValue);
76 //! Types of actions associated to waiting or checking the completion of GPU tasks
77 enum class GpuTaskCompletion
79 Wait, /*<< Issue a blocking wait for the task */
80 Check /*<< Only check whether the task has completed */
83 /*! \brief Starts the GPU profiler if mdrun is being profiled.
85 * When a profiler run is in progress (based on the presence of the NVPROF_ID
86 * env. var.), the profiler is started to begin collecting data during the
87 * rest of the run (or until stopGpuProfiler is called).
89 * Note that this is implemented only for the CUDA API.
92 void startGpuProfiler() CUDA_FUNC_TERM;
95 /*! \brief Resets the GPU profiler if mdrun is being profiled.
97 * When a profiler run is in progress (based on the presence of the NVPROF_ID
98 * env. var.), the profiler data is restet in order to eliminate the data collected
99 * from the preceding part fo the run.
101 * This function should typically be called at the mdrun counter reset time.
103 * Note that this is implemented only for the CUDA API.
106 void resetGpuProfiler() CUDA_FUNC_TERM;
109 /*! \brief Stops the CUDA profiler if mdrun is being profiled.
111 * This function can be called at cleanup when skipping recording
112 * recording subsequent API calls from being traces/profiled is desired,
113 * e.g. before uninitialization.
115 * Note that this is implemented only for the CUDA API.
118 void stopGpuProfiler() CUDA_FUNC_TERM;
120 //! Tells whether the host buffer was pinned for non-blocking transfers. Only implemented for CUDA.
122 bool isHostMemoryPinned(const void* CUDA_FUNC_ARGUMENT(h_ptr)) CUDA_FUNC_TERM_WITH_RETURN(false);
124 /*! \brief Enable peer access between GPUs where supported
125 * \param[in] gpuIdsToUse List of GPU IDs in use
126 * \param[in] mdlog Logger object
129 void setupGpuDevicePeerAccess(const std::vector<int>& CUDA_FUNC_ARGUMENT(gpuIdsToUse),
130 const gmx::MDLogger& CUDA_FUNC_ARGUMENT(mdlog)) CUDA_FUNC_TERM;
132 /*! \brief Check the platform-defaults and environment variable to decide whether GPU timings
135 * Currently, timings are enabled for OpenCL, but disabled for CUDA and SYCL. This can be overridden
136 * by \c GMX_ENABLE_GPU_TIMING and \c GMX_DISABLE_GPU_TIMING environment variables.
138 bool decideGpuTimingsUsage();