Compadre 1.7.0
Loading...
Searching...
No Matches
Compadre_ParallelManager.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Compadre: COMpatible PArticle Discretization and REmap Toolkit
4//
5// Copyright 2018 NTESS and the Compadre contributors.
6// SPDX-License-Identifier: BSD-2-Clause
7// *****************************************************************************
8// @HEADER
9#ifndef _COMPADRE_PARALLELMANAGER_HPP_
10#define _COMPADRE_PARALLELMANAGER_HPP_
11
12#include "Compadre_Config.h"
13#include "Compadre_Typedefs.hpp"
14
15namespace Compadre {
16
17
18//! Parallel Manager
19/*!
20* This class sets and manages thread / teams levels, scratch memory sizes, and kernel executions.
21* ex:
22* Compadre::ConvertLayoutLeftToRight clr;
23* Compadre::ParallelManager pm;
24* // no tag specified
25* pm.CallFunctorWithTeamThreads(clr, 100, "MyFunctorName");
26* // some tag specified
27* pm.CallFunctorWithTeamThreads<DefaultTag>(clr, 100);
28*/
30public:
31
32 //! lowest level memory for Kokkos::parallel_for for team access memory
35
36 //! higher (slower) level memory for Kokkos::parallel_for for team access memory
39
40 //! lowest level memory for Kokkos::parallel_for for thread access memory
43
44 //! higher (slower) level memory for Kokkos::parallel_for for thread access memory
47
48 //! number of threads and vector lanes
49 //! if not specified through environment variables THREADS and VECTORLANES,
50 //! then set to Kokkos::AUTO
53
54
55/** @name Private Modifiers
56 * Private function because information lives on the device
57 */
58///@{
59///@}
60
61/** @name Private Accessors
62 * Private function because information lives on the device
63 */
64///@{
65///@}
66
67/** @name Private Utility
68 *
69 */
70///@{
71///@}
72
73public:
74
75/** @name Instantiation / Destruction
76 *
77 */
78///@{
79
82
83#ifdef COMPADRE_USE_CUDA
88
91#else
96
99#endif
100 if (const char* env_threads = std::getenv("THREADS")) {
101 _environment_threads = std::atoi(env_threads);
102 }
103 if (const char* env_vector_lanes = std::getenv("VECTORLANES")) {
104 _environment_vector_lanes = std::atoi(env_vector_lanes);
105 }
106#ifdef COMPADRE_EXTREME_DEBUG
107 printf("ENVIRONMENT:: threads per team: %d, vector lanes per team: %d\n", _environment_threads, _environment_vector_lanes);
108#endif
109 }
110
111///@}
112
113/** @name Public Utility
114 *
115 */
116///@{
117///@}
118
119/** @name Accessors
120 * Retrieve member variables through public member functions
121 */
122///@{
123
124 //! Creates a team policy for a parallel_for
125 //! parallel_for will break out over loops over teams with each vector lane executing code be default
126 template <typename execution_space = device_execution_space>
127 Kokkos::TeamPolicy<execution_space>
128 TeamPolicyThreadsAndVectors(const global_index_type batch_size, const int threads_per_team = -1,
129 const int vector_lanes_per_thread = -1) const {
130
131 // first create object
132 Kokkos::TeamPolicy<execution_space> tp;
133 if (threads_per_team>0 && vector_lanes_per_thread>0) {
134 tp = Kokkos::TeamPolicy<execution_space>(batch_size, threads_per_team, vector_lanes_per_thread);
135 } else if (threads_per_team>0) {
137 tp = Kokkos::TeamPolicy<execution_space>(batch_size, threads_per_team, _environment_vector_lanes);
138 } else {
139 tp = Kokkos::TeamPolicy<execution_space>(batch_size, threads_per_team, Kokkos::AUTO);
140 }
141 } else if (vector_lanes_per_thread>0) {
142 if (_environment_threads>0) {
143 tp = Kokkos::TeamPolicy<execution_space>(batch_size, _environment_threads, vector_lanes_per_thread);
144 } else {
145 tp = Kokkos::TeamPolicy<execution_space>(batch_size, Kokkos::AUTO, vector_lanes_per_thread);
146 }
147 } else {
149 tp = Kokkos::TeamPolicy<execution_space>(batch_size, _environment_threads, _environment_vector_lanes);
150 } else if (_environment_vector_lanes>0) {
151 tp = Kokkos::TeamPolicy<execution_space>(batch_size, Kokkos::AUTO, _environment_vector_lanes);
152 } else if (_environment_threads>0) {
153 tp = Kokkos::TeamPolicy<execution_space>(batch_size, _environment_threads, Kokkos::AUTO);
154 } else {
155 tp = Kokkos::TeamPolicy<execution_space>(batch_size, Kokkos::AUTO, Kokkos::AUTO);
156 }
157 }
158
160 tp = tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a))
161 .set_scratch_size(_scratch_team_level_b, Kokkos::PerTeam(_team_scratch_size_b))
162 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a))
163 .set_scratch_size(_scratch_thread_level_b, Kokkos::PerThread(_thread_scratch_size_b));
165 tp = tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a))
166 .set_scratch_size(_scratch_team_level_b, Kokkos::PerTeam(_team_scratch_size_b))
167 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a + _thread_scratch_size_b));
169 tp = tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a + _team_scratch_size_b))
170 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a))
171 .set_scratch_size(_scratch_thread_level_b, Kokkos::PerThread(_thread_scratch_size_b));
172 } else {
173 tp = tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a + _team_scratch_size_b))
174 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a + _thread_scratch_size_b));
175 }
176 return tp;
177 }
178
179 KOKKOS_INLINE_FUNCTION
180 int getTeamScratchLevel(const int level) const {
181 if (level == 0) {
183 } else {
185 }
186 }
187
188 KOKKOS_INLINE_FUNCTION
189 int getThreadScratchLevel(const int level) const {
190 if (level == 0) {
192 } else {
194 }
195 }
196
197 KOKKOS_INLINE_FUNCTION
198 int getTeamScratchSize(const int level) const {
199 if (level == 0) {
201 } else {
203 }
204 }
205
206 KOKKOS_INLINE_FUNCTION
207 int getThreadScratchSize(const int level) const {
208 if (level == 0) {
210 } else {
212 }
213 }
214
215///@}
216
217
218/** @name Modifiers
219 * Changed member variables through public member functions
220 */
221///@{
222
223 void setTeamScratchLevel(const int level, const int value) {
224 if (level == 0) {
225 _scratch_team_level_a = value;
226 } else {
227 _scratch_team_level_b = value;
228 }
229 }
230
231 void setThreadScratchLevel(const int level, const int value) {
232 if (level == 0) {
234 } else {
236 }
237 }
238
239 void setTeamScratchSize(const int level, const int value) {
240 if (level == 0) {
241 _team_scratch_size_a = value;
242 } else {
243 _team_scratch_size_b = value;
244 }
245 }
246
247 void setThreadScratchSize(const int level, const int value) {
248 if (level == 0) {
250 } else {
252 }
253 }
254
261
262///@}
263
264
265}; // ParallelManager Class
266} // Compadre
267
268#endif
269
270
int _scratch_team_level_a
lowest level memory for Kokkos::parallel_for for team access memory
void setTeamScratchLevel(const int level, const int value)
KOKKOS_INLINE_FUNCTION int getThreadScratchLevel(const int level) const
void setThreadScratchSize(const int level, const int value)
int _scratch_thread_level_a
higher (slower) level memory for Kokkos::parallel_for for team access memory
void setThreadScratchLevel(const int level, const int value)
int _environment_threads
number of threads and vector lanes if not specified through environment variables THREADS and VECTORL...
Kokkos::TeamPolicy< execution_space > TeamPolicyThreadsAndVectors(const global_index_type batch_size, const int threads_per_team=-1, const int vector_lanes_per_thread=-1) const
Creates a team policy for a parallel_for parallel_for will break out over loops over teams with each ...
KOKKOS_INLINE_FUNCTION int getTeamScratchSize(const int level) const
int _scratch_team_level_b
lowest level memory for Kokkos::parallel_for for thread access memory
int _scratch_thread_level_b
higher (slower) level memory for Kokkos::parallel_for for thread access memory
void setTeamScratchSize(const int level, const int value)
KOKKOS_INLINE_FUNCTION int getThreadScratchSize(const int level) const
KOKKOS_INLINE_FUNCTION int getTeamScratchLevel(const int level) const
std::size_t global_index_type