Separate management of GPU contexts from modules
[gromacs.git] / src / gromacs / taskassignment / taskassignment.h
blob62123e082405d0935ecf228398de2552584a02c2
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2017, 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.
35 /*! \defgroup module_taskassignment Assigning simulation tasks to hardware (taskassignment)
36 * \ingroup group_mdrun
37 * \brief Provides code that manages assignment of simulation tasks to hardware.
39 /*! \libinternal
40 * \file
41 * \brief Declares high-level functionality for managing assigning
42 * tasks on ranks of a node to hardware on that node, and the factory
43 * function to build the correct flavours of gmx::INodeTaskAssigner
44 * required to implement the user's requirements.
46 * \author Mark Abraham <mark.j.abraham@gmail.com>
47 * \ingroup module_taskassignment
48 * \inlibraryapi
50 #ifndef GMX_TASKASSIGNMENT_TASKASSIGNMENT_H
51 #define GMX_TASKASSIGNMENT_TASKASSIGNMENT_H
53 #include <vector>
55 struct gmx_hw_info_t;
56 struct t_commrec;
58 namespace gmx
61 class MDLogger;
63 /*! \brief Types of compute tasks that can be run on a GPU.
65 * These names refer to existing practice in GROMACS, which is not
66 * strictly accurate. */
67 enum class GpuTask : int
69 //! Short-ranged interactions.
70 Nonbonded,
71 //! Long-ranged interactions.
72 Pme
75 /*! \libinternal
76 * \brief Specifies the GPU deviceID_ available for task_ to use. */
77 struct GpuTaskMapping
79 //! The type of this GPU task.
80 GpuTask task_;
81 //! Device ID on this node to which this GPU task is mapped.
82 int deviceId_;
85 //! Container of GPU tasks on a rank, specifying the task type and GPU device ID, e.g. potentially ready for consumption by the modules on that rank.
86 using GpuTaskAssignment = std::vector <GpuTaskMapping>;
87 //! Container of compute tasks suitable to run on a GPU e.g. on each rank of a node.
88 using GpuTasksOnRanks = std::vector< std::vector<GpuTask> >;
89 //! Container of RankGpuTaskAssignments e.g. for all ranks on a node.
90 using GpuTaskAssignments = std::vector<GpuTaskAssignment>;
92 /*! \brief Coordinate the final stages of task assignment and
93 * reporting, and return the assignment for this rank.
95 * Communicates between ranks on a node to coordinate task assignment
96 * between them onto available hardware, e.g. accelerators.
98 * Releases the taskAssigner once its work is complete.
100 * \param[in] gpuIdsToUse The compatible GPUs that the user permitted us to use.
101 * \param[in] userGpuTaskAssignment The user-specified assignment of GPU tasks to device IDs.
102 * \param[in] hardwareInfo The detected hardware
103 * \param[in] mdlog Logging object to write to.
104 * \param[in] cr Communication object.
105 * \param[in] gpuTasksOnThisRank Information about what GPU tasks
106 * exist on this rank.
108 * \returns A GPU task assignment for this rank.
110 * \throws std::bad_alloc If out of memory.
111 * InconsistentInputError If user and/or detected inputs are inconsistent.
113 GpuTaskAssignments::value_type
114 runTaskAssignment(const std::vector<int> &gpuIdsToUse,
115 const std::vector<int> &userGpuTaskAssignment,
116 const gmx_hw_info_t &hardwareInfo,
117 const MDLogger &mdlog,
118 const t_commrec *cr,
119 const std::vector<GpuTask> &gpuTasksOnThisRank);
121 //! Function for whether the task of \c mapping has value \c TaskType.
122 template<GpuTask TaskType>
123 bool hasTaskType(const GpuTaskMapping &mapping)
125 return mapping.task_ == TaskType;
128 } // namespace
130 #endif