Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_HierarchicParallelism.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef PANZER_HIERARCHIC_PARALLELISM_HPP
12 #define PANZER_HIERARCHIC_PARALLELISM_HPP
13 
14 #include "Phalanx_KokkosDeviceTypes.hpp"
15 
16 namespace panzer {
17 
19  class HP {
21  int team_size_;
26 
27  HP();
28 
29  public:
31  static HP& inst();
32 
45  void overrideSizes(const int& team_size,
46  const int& vector_size,
47  const int& fad_vector_size,
48  const bool force_override_safety=false);
49 
52 
65  template<typename Scalar>
66  int vectorSize() const
67  {
68  return Sacado::IsADType<Scalar>::value ? fad_vector_size_ : vector_size_;
69  }
70 
88  void setUseSharedMemory(const bool& use_shared_memory,
89  const bool& fad_use_shared_memory);
90 
91  template<typename Scalar>
92  bool useSharedMemory() const
93  {
94  return Sacado::IsADType<Scalar>::value ? fad_use_shared_memory_ : use_shared_memory_;
95  }
96 
98  template<typename ScalarT, typename ... TeamPolicyProperties>
99  Kokkos::TeamPolicy<TeamPolicyProperties...> teamPolicy(const int& league_size)
100  {
101  const int tmp_vector_size = this->template vectorSize<ScalarT>();
102 
104  return Kokkos::TeamPolicy<TeamPolicyProperties...>(league_size,Kokkos::AUTO(),
105  tmp_vector_size);
106 
107  return Kokkos::TeamPolicy<TeamPolicyProperties...>(league_size,team_size_,tmp_vector_size);
108  }
109 
111  template<typename ScalarT, typename ... TeamPolicyProperties, typename ExecSpace>
112  Kokkos::TeamPolicy<ExecSpace, TeamPolicyProperties...> teamPolicy(ExecSpace exec_space, const int& league_size)
113  {
114  const int tmp_vector_size = this->template vectorSize<ScalarT>();
115 
117  return Kokkos::TeamPolicy<TeamPolicyProperties...>(exec_space,league_size,Kokkos::AUTO(),
118  tmp_vector_size);
119 
120  return Kokkos::TeamPolicy<TeamPolicyProperties...>(exec_space,league_size,team_size_,tmp_vector_size);
121  }
122  };
123 
124 }
125 
126 #endif
void resetSizes()
Reset the sizes to default.
int fad_vector_size_
Default vector size for non-AD types.
bool use_shared_memory_
FAD vector size.
int vector_size_
User specified team size.
Kokkos::TeamPolicy< TeamPolicyProperties...> teamPolicy(const int &league_size)
Returns a TeamPolicy for hierarchic parallelism.
bool fad_use_shared_memory_
Use shared memory kokkos kernels for non-fad types.
int team_size_
If true, the team size is set with Kokkos::AUTO()
void overrideSizes(const int &team_size, const int &vector_size, const int &fad_vector_size, const bool force_override_safety=false)
Kokkos::TeamPolicy< ExecSpace, TeamPolicyProperties...> teamPolicy(ExecSpace exec_space, const int &league_size)
Returns a TeamPolicy for hierarchic parallelism using an exec_space instance (for cuda streams)...
HP()
Use shared memory kokkos kernels for fad types.
int vectorSize() const
Returns the vector size. Specialized for AD scalar types.
Singleton class for accessing kokkos hierarchical parallelism parameters.
static HP & inst()
Private ctor.
void setUseSharedMemory(const bool &use_shared_memory, const bool &fad_use_shared_memory)
Tell kokkos kernels if they should use shared memory. This is very problem dependent.