Compadre 1.6.8
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 Kokkos::TeamPolicy<device_execution_space>
127 TeamPolicyThreadsAndVectors(const global_index_type batch_size, const int threads_per_team = -1,
128 const int vector_lanes_per_thread = -1) const {
129
130 // first create object
131 Kokkos::TeamPolicy<device_execution_space> tp;
132 if (threads_per_team>0 && vector_lanes_per_thread>0) {
133 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, threads_per_team, vector_lanes_per_thread);
134 } else if (threads_per_team>0) {
136 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, threads_per_team, _environment_vector_lanes);
137 } else {
138 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, threads_per_team, Kokkos::AUTO);
139 }
140 } else if (vector_lanes_per_thread>0) {
141 if (_environment_threads>0) {
142 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, _environment_threads, vector_lanes_per_thread);
143 } else {
144 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, Kokkos::AUTO, vector_lanes_per_thread);
145 }
146 } else {
148 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, _environment_threads, _environment_vector_lanes);
149 } else if (_environment_vector_lanes>0) {
150 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, Kokkos::AUTO, _environment_vector_lanes);
151 } else if (_environment_threads>0) {
152 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, _environment_threads, Kokkos::AUTO);
153 } else {
154 tp = Kokkos::TeamPolicy<device_execution_space>(batch_size, Kokkos::AUTO, Kokkos::AUTO);
155 }
156 }
157
159 tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a))
160 .set_scratch_size(_scratch_team_level_b, Kokkos::PerTeam(_team_scratch_size_b))
161 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a))
162 .set_scratch_size(_scratch_thread_level_b, Kokkos::PerThread(_thread_scratch_size_b));
164 tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a))
165 .set_scratch_size(_scratch_team_level_b, Kokkos::PerTeam(_team_scratch_size_b))
166 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a + _thread_scratch_size_b));
168 tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a + _team_scratch_size_b))
169 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a))
170 .set_scratch_size(_scratch_thread_level_b, Kokkos::PerThread(_thread_scratch_size_b));
171 } else {
172 tp.set_scratch_size(_scratch_team_level_a, Kokkos::PerTeam(_team_scratch_size_a + _team_scratch_size_b))
173 .set_scratch_size(_scratch_thread_level_a, Kokkos::PerThread(_thread_scratch_size_a + _thread_scratch_size_b));
174 }
175 return tp;
176 }
177
178 KOKKOS_INLINE_FUNCTION
179 int getTeamScratchLevel(const int level) const {
180 if (level == 0) {
182 } else {
184 }
185 }
186
187 KOKKOS_INLINE_FUNCTION
188 int getThreadScratchLevel(const int level) const {
189 if (level == 0) {
191 } else {
193 }
194 }
195
196 KOKKOS_INLINE_FUNCTION
197 int getTeamScratchSize(const int level) const {
198 if (level == 0) {
200 } else {
202 }
203 }
204
205 KOKKOS_INLINE_FUNCTION
206 int getThreadScratchSize(const int level) const {
207 if (level == 0) {
209 } else {
211 }
212 }
213
214///@}
215
216
217/** @name Modifiers
218 * Changed member variables through public member functions
219 */
220///@{
221
222 void setTeamScratchLevel(const int level, const int value) {
223 if (level == 0) {
224 _scratch_team_level_a = value;
225 } else {
226 _scratch_team_level_b = value;
227 }
228 }
229
230 void setThreadScratchLevel(const int level, const int value) {
231 if (level == 0) {
233 } else {
235 }
236 }
237
238 void setTeamScratchSize(const int level, const int value) {
239 if (level == 0) {
240 _team_scratch_size_a = value;
241 } else {
242 _team_scratch_size_b = value;
243 }
244 }
245
246 void setThreadScratchSize(const int level, const int value) {
247 if (level == 0) {
249 } else {
251 }
252 }
253
260
261///@}
262
263
264}; // ParallelManager Class
265} // Compadre
266
267#endif
268
269
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_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::TeamPolicy< device_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 getTeamScratchLevel(const int level) const
std::size_t global_index_type