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