Compadre  1.3.3
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
25 typedef double scalar_type;
26 typedef int local_index_type;
27 typedef 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
35 typedef Kokkos::DefaultHostExecutionSpace host_execution_space;
36 typedef Kokkos::DefaultExecutionSpace device_execution_space;
37 
38 // memory spaces
39 typedef 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
47 typedef typename Kokkos::TeamPolicy<device_execution_space> team_policy;
49 
50 typedef typename Kokkos::TeamPolicy<host_execution_space> host_team_policy;
52 
53 // layout types
54 typedef Kokkos::LayoutRight layout_right;
55 typedef Kokkos::LayoutLeft layout_left;
56 
57 // unmanaged data wrappers
58 typedef Kokkos::View<double**, layout_right, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
60 typedef Kokkos::View<double**, layout_left, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
62 typedef Kokkos::View<double*, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
64 typedef Kokkos::View<int*, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
66 
67 // host equivalents
68 typedef Kokkos::View<double**, layout_right, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
70 typedef Kokkos::View<double**, layout_left, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
72 typedef Kokkos::View<double*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
74 typedef Kokkos::View<int*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
76 
77 // managed device data views
78 typedef Kokkos::View<double**, layout_right, device_memory_space>
80 typedef Kokkos::View<double**, layout_left, device_memory_space>
82 typedef Kokkos::View<double*, device_memory_space>
84 typedef Kokkos::View<int*, device_memory_space>
86 
87 // managed host data views
88 typedef Kokkos::View<double**, layout_right, host_execution_space>
90 typedef Kokkos::View<double**, layout_left, host_execution_space>
92 typedef Kokkos::View<double*, host_execution_space>
94 typedef Kokkos::View<int*, host_execution_space>
96 
97 // random number generator
98 typedef Kokkos::Random_XorShift64_Pool<> pool_type;
100 
101 template< bool B, class T = void >
102 using enable_if_t = typename std::enable_if<B,T>::type;
103 
104 template<typename T>
105 typename std::enable_if<1==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
106 { return T(str, dim_0); }
107 
108 template<typename T>
109 typename std::enable_if<2==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
110 { return T(str, dim_0, dim_1); }
111 
112 //void compadre_rethrow_exception(std::exception &e, const std::string &extra_message) {
113 // std::cout << extra_message + "\n\n" + e.what() << std::endl;
114 //}
115 
116 //! compadre_assert_release is used for assertions that should always be checked, but generally
117 //! are not expensive to verify or are not called frequently.
118 # define compadre_assert_release(condition) do { \
119  if ( ! (condition)) { \
120  std::stringstream _ss_; \
121  _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
122  << "\n"; \
123  throw std::logic_error(_ss_.str()); \
124  } \
125  } while (0)
126 
127 //! compadre_kernel_assert_release is similar to compadre_assert_release, but is a call on the device,
128 //! namely inside of a function marked KOKKOS_INLINE_FUNCTION
129 # define compadre_kernel_assert_release(condition) do { \
130  if ( ! (condition)) \
131  Kokkos::abort(#condition); \
132  } while (0)
133 
134 //! compadre_assert_debug is used for assertions that are checked in loops, as these significantly
135 //! impact performance. When NDEBUG is set, these conditions are not checked.
136 #ifdef COMPADRE_DEBUG
137 # define compadre_assert_debug(condition) do { \
138  if ( ! (condition)) { \
139  std::stringstream _ss_; \
140  _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
141  << "\n"; \
142  throw std::logic_error(_ss_.str()); \
143  } \
144  } while (0)
145 # define compadre_kernel_assert_debug(condition) do { \
146  if ( ! (condition)) \
147  Kokkos::abort(#condition); \
148  } while (0)
149 #else
150 # define compadre_assert_debug(condition)
151 # define compadre_kernel_assert_debug(condition)
152 #endif
153 //! compadre_kernel_assert_debug is similar to compadre_assert_debug, but is a call on the device,
154 //! namely inside of a function marked KOKKOS_INLINE_FUNCTION
155 
156 #ifdef COMPADRE_EXTREME_DEBUG
157 # define compadre_assert_extreme_debug(condition) do { \
158  if ( ! (condition)) { \
159  std::stringstream _ss_; \
160  _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
161  << "\n"; \
162  throw std::logic_error(_ss_.str()); \
163  } \
164  } while (0)
165 # define compadre_kernel_assert_extreme_debug(condition) do { \
166  if ( ! (condition)) \
167  Kokkos::abort(#condition); \
168  } while (0)
169 #else
170 # define compadre_assert_extreme_debug(condition)
171 # define compadre_kernel_assert_extreme_debug(condition)
172 #endif
173 //! compadre_kernel_assert_extreme_debug is similar to compadre_assert_debug, but is a call on the device,
174 //! namely inside of a function marked KOKKOS_INLINE_FUNCTION
175 
176 #endif
Kokkos::View< double **, layout_left, host_execution_space > host_managed_matrix_left_type
std::size_t global_index_type
pool_type::generator_type generator_type
double scalar_type
Kokkos::View< double *, device_memory_space > device_managed_vector_type
team_policy::member_type member_type
Kokkos::View< double **, layout_right, host_execution_space > host_managed_matrix_right_type
Kokkos::View< int *, device_memory_space > device_managed_local_index_type
Kokkos::DefaultHostExecutionSpace host_execution_space
Kokkos::TeamPolicy< host_execution_space > host_team_policy
Kokkos::TeamPolicy< device_execution_space > team_policy
Kokkos::View< int *, host_execution_space > host_managed_local_index_type
Kokkos::DefaultExecutionSpace device_execution_space
Kokkos::View< double **, layout_right, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_matrix_right_type
device_execution_space::memory_space device_memory_space
Kokkos::View< double *, host_execution_space > host_managed_vector_type
typename std::enable_if< B, T >::type enable_if_t
Kokkos::View< double **, layout_right, device_memory_space > device_managed_matrix_right_type
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Kokkos::View< double *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type
Kokkos::View< double **, layout_left, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_left_type
Kokkos::View< double **, layout_left, device_memory_space > device_managed_matrix_left_type
Kokkos::View< double **, layout_left, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_matrix_left_type
Kokkos::LayoutLeft layout_left
Kokkos::View< int *, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_local_index_type
host_execution_space::memory_space host_memory_space
Kokkos::Random_XorShift64_Pool pool_type
host_team_policy::member_type host_member_type
Kokkos::LayoutRight layout_right
std::enable_if< 1==T::rank, T >::type createView(std::string str, int dim_0, int dim_1)
int local_index_type
Kokkos::View< double *, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_vector_type
Kokkos::View< int *, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_local_index_type