Compadre 1.5.5
Loading...
Searching...
No Matches
Compadre_Typedefs.hpp
Go to the documentation of this file.
1#ifndef _COMPADRE_TYPEDEFS_HPP_
2#define _COMPADRE_TYPEDEFS_HPP_
3
4#include "Compadre_Config.h"
5
6#include <Kokkos_Core.hpp>
7#include <Kokkos_Random.hpp>
8#include <type_traits>
9#include <vector>
10#include <sstream>
11#include <cstddef>
12#include <functional>
13#include <string>
14
15/*!
16
17 Data types in Compadre Toolkit:
18
19 - Intention is to do local work, i.e. on a single node, so the default ordinal is local_index_type
20 - When doing pointer arithmetic, it is possible to overflow local_index_type, so use global_index_type
21
22*/
23
24// Indices and data types
25typedef double scalar_type;
26typedef int local_index_type;
27typedef std::size_t global_index_type;
28
29// helper function when doing pointer arithmetic
30#define TO_GLOBAL(variable) ((global_index_type)variable)
31
32// KOKKOS TYPEDEFS
33
34// execution spaces
35typedef Kokkos::DefaultHostExecutionSpace host_execution_space;
36typedef Kokkos::DefaultExecutionSpace device_execution_space;
37
38// memory spaces
39typedef typename host_execution_space::memory_space host_memory_space;
40#ifdef COMPADRE_USE_CUDA
41 typedef typename Kokkos::CudaSpace device_memory_space;
42#else
43 typedef typename device_execution_space::memory_space device_memory_space;
44#endif
45
46// team policies
47typedef typename Kokkos::TeamPolicy<device_execution_space> team_policy;
48typedef typename team_policy::member_type member_type;
49
50typedef typename Kokkos::TeamPolicy<host_execution_space> host_team_policy;
51typedef typename host_team_policy::member_type host_member_type;
52
53// layout types
54typedef Kokkos::LayoutRight layout_right;
55typedef Kokkos::LayoutLeft layout_left;
56
57// unmanaged data wrappers
58typedef Kokkos::View<double**, layout_right, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
60typedef Kokkos::View<double**, layout_left, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
62typedef Kokkos::View<double*, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
64typedef Kokkos::View<int*, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
66
67// host equivalents
68typedef Kokkos::View<double**, layout_right, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
70typedef Kokkos::View<double**, layout_left, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
72typedef Kokkos::View<double*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
74typedef Kokkos::View<int*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
76
77// managed device data views
78typedef Kokkos::View<double**, layout_right, device_memory_space>
80typedef Kokkos::View<double**, layout_left, device_memory_space>
82typedef Kokkos::View<double*, device_memory_space>
84typedef Kokkos::View<int*, device_memory_space>
86
87// managed host data views
88typedef Kokkos::View<double**, layout_right, host_execution_space>
90typedef Kokkos::View<double**, layout_left, host_execution_space>
92typedef Kokkos::View<double*, host_execution_space>
94typedef Kokkos::View<int*, host_execution_space>
96
97// random number generator
98typedef Kokkos::Random_XorShift64_Pool<> pool_type;
99typedef typename pool_type::generator_type generator_type;
100
101// KOKKOS_VERSION % 100 is the patch level
102// KOKKOS_VERSION / 100 % 100 is the minor version
103// KOKKOS_VERSION / 10000 is the major version
104#ifdef KOKKOS_VERSION
105 #define COMPADRE_KOKKOS_VERSION_MAJOR KOKKOS_VERSION / 10000
106 #define COMPADRE_KOKKOS_VERSION_MINOR KOKKOS_VERSION / 100 % 100
107 #if COMPADRE_KOKKOS_VERSION_MAJOR < 4
108 #if COMPADRE_KOKKOS_VERSION_MINOR >= 7
109 using KokkosInitArguments = Kokkos::InitializationSettings;
110 #define COMPADRE_KOKKOS_GREATEREQUAL_3_7
111 constexpr char KOKKOS_THREADS_ARG[] = "--kokkos-num-threads";
112 #elif COMPADRE_KOKKOS_VERSION_MINOR < 7
113 using KokkosInitArguments = Kokkos::InitArguments;
114 constexpr char KOKKOS_THREADS_ARG[] = "--kokkos-threads";
115 #endif
116 #elif COMPADRE_KOKKOS_VERSION_MAJOR >= 4
117 using KokkosInitArguments = Kokkos::InitializationSettings;
118 #define COMPADRE_KOKKOS_GREATEREQUAL_3_7
119 constexpr char KOKKOS_THREADS_ARG[] = "--kokkos-num-threads";
120 #endif
121#else // older version
122 using KokkosInitArguments = Kokkos::InitArguments;
123 constexpr char KOKKOS_THREADS_ARG[] = "--kokkos-threads";
124#endif
125
126template< bool B, class T = void >
127using enable_if_t = typename std::enable_if<B,T>::type;
128
129template<typename T>
130typename std::enable_if<1==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
131{ return T(str, dim_0); }
132
133template<typename T>
134typename std::enable_if<2==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
135{ return T(str, dim_0, dim_1); }
136
137//void compadre_rethrow_exception(std::exception &e, const std::string &extra_message) {
138// std::cout << extra_message + "\n\n" + e.what() << std::endl;
139//}
140
141//! compadre_assert_release is used for assertions that should always be checked, but generally
142//! are not expensive to verify or are not called frequently.
143# define compadre_assert_release(condition) do { \
144 if ( ! (condition)) { \
145 std::stringstream _ss_; \
146 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
147 << "\n"; \
148 throw std::logic_error(_ss_.str()); \
149 } \
150 } while (0)
151
152//! compadre_kernel_assert_release is similar to compadre_assert_release, but is a call on the device,
153//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
154# define compadre_kernel_assert_release(condition) do { \
155 if ( ! (condition)) \
156 Kokkos::abort(#condition); \
157 } while (0)
158
159//! compadre_assert_debug is used for assertions that are checked in loops, as these significantly
160//! impact performance. When NDEBUG is set, these conditions are not checked.
161#ifdef COMPADRE_DEBUG
162# define compadre_assert_debug(condition) do { \
163 if ( ! (condition)) { \
164 std::stringstream _ss_; \
165 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
166 << "\n"; \
167 throw std::logic_error(_ss_.str()); \
168 } \
169 } while (0)
170# define compadre_kernel_assert_debug(condition) do { \
171 if ( ! (condition)) \
172 Kokkos::abort(#condition); \
173 } while (0)
174#else
175# define compadre_assert_debug(condition)
176# define compadre_kernel_assert_debug(condition)
177#endif
178//! compadre_kernel_assert_debug is similar to compadre_assert_debug, but is a call on the device,
179//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
180
181#ifdef COMPADRE_EXTREME_DEBUG
182# define compadre_assert_extreme_debug(condition) do { \
183 if ( ! (condition)) { \
184 std::stringstream _ss_; \
185 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
186 << "\n"; \
187 throw std::logic_error(_ss_.str()); \
188 } \
189 } while (0)
190# define compadre_kernel_assert_extreme_debug(condition) do { \
191 if ( ! (condition)) \
192 Kokkos::abort(#condition); \
193 } while (0)
194#else
195# define compadre_assert_extreme_debug(condition)
196# define compadre_kernel_assert_extreme_debug(condition)
197#endif
198//! compadre_kernel_assert_extreme_debug is similar to compadre_assert_debug, but is a call on the device,
199//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
200
201#endif
Kokkos::DefaultExecutionSpace device_execution_space
double scalar_type
int local_index_type
Kokkos::TeamPolicy< host_execution_space > host_team_policy
Kokkos::View< double **, layout_left, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_left_type
Kokkos::View< double **, layout_left, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_matrix_left_type
Kokkos::View< double **, layout_right, host_execution_space > host_managed_matrix_right_type
Kokkos::View< double *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type
host_execution_space::memory_space host_memory_space
Kokkos::DefaultHostExecutionSpace host_execution_space
std::enable_if< 1==T::rank, T >::type createView(std::string str, int dim_0, int dim_1)
Kokkos::Random_XorShift64_Pool pool_type
std::size_t global_index_type
Kokkos::View< double *, host_execution_space > host_managed_vector_type
Kokkos::View< int *, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_local_index_type
Kokkos::LayoutLeft layout_left
Kokkos::TeamPolicy< device_execution_space > team_policy
constexpr char KOKKOS_THREADS_ARG[]
typename std::enable_if< B, T >::type enable_if_t
Kokkos::View< int *, device_memory_space > device_managed_local_index_type
Kokkos::View< double *, device_memory_space > device_managed_vector_type
Kokkos::View< double **, layout_right, device_memory_space > device_managed_matrix_right_type
Kokkos::View< int *, host_execution_space > host_managed_local_index_type
Kokkos::View< double **, layout_left, device_memory_space > device_managed_matrix_left_type
Kokkos::View< double **, layout_left, host_execution_space > host_managed_matrix_left_type
Kokkos::InitArguments KokkosInitArguments
team_policy::member_type member_type
host_team_policy::member_type host_member_type
Kokkos::LayoutRight layout_right
Kokkos::View< double *, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_vector_type
pool_type::generator_type generator_type
device_execution_space::memory_space device_memory_space
Kokkos::View< int *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_local_index_type
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Kokkos::View< double **, layout_right, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_matrix_right_type