Compadre 1.7.2
Loading...
Searching...
No Matches
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
23namespace Compadre {
24/*!
25
26 Data types in Compadre Toolkit:
27
28 - Intention is to do local work, i.e. on a single node, so the default ordinal is local_index_type
29 - When doing pointer arithmetic, it is possible to overflow local_index_type, so use global_index_type
30
31*/
32
33// Indices and data types
34typedef double scalar_type;
35typedef int local_index_type;
36typedef std::size_t global_index_type;
37
38// helper function when doing pointer arithmetic
39#define TO_GLOBAL(variable) ((global_index_type)variable)
40
41// KOKKOS TYPEDEFS
42
43// execution spaces
44typedef Kokkos::DefaultHostExecutionSpace host_execution_space;
45typedef Kokkos::DefaultExecutionSpace device_execution_space;
46typedef host_execution_space::scratch_memory_space host_scratch;
47typedef device_execution_space::scratch_memory_space device_scratch;
48
49// memory spaces
50typedef typename host_execution_space::memory_space host_memory_space;
51#if defined(COMPADRE_USE_CUDA)
52 typedef typename Kokkos::CudaSpace device_memory_space;
53#elif defined(COMPADRE_USE_HIP)
54 typedef typename Kokkos::HIPSpace device_memory_space;
55#else
56 typedef typename device_execution_space::memory_space device_memory_space;
57#endif
58
59// team policies
60typedef typename Kokkos::TeamPolicy<device_execution_space> team_policy;
61typedef typename team_policy::member_type member_type;
62
63typedef typename Kokkos::TeamPolicy<host_execution_space> host_team_policy;
64typedef typename host_team_policy::member_type host_member_type;
65
66// layout types
67typedef Kokkos::LayoutRight layout_right;
68typedef Kokkos::LayoutLeft layout_left;
69
70// scratch data wrappers
71typedef Kokkos::View<double**, layout_right, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
73typedef Kokkos::View<double**, layout_left, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
75typedef Kokkos::View<double*, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
77typedef Kokkos::View<int*, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
79
80// host equivalents
81typedef Kokkos::View<double**, layout_right, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
83typedef Kokkos::View<double**, layout_left, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
85typedef Kokkos::View<double*, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
87typedef Kokkos::View<int*, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
89
90// unmanaged devicedata deviews
91typedef Kokkos::View<double**, layout_right, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
93typedef Kokkos::View<double**, layout_left, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
95typedef Kokkos::View<double*, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
97typedef Kokkos::View<int*, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
99
100// host equivalents
101typedef Kokkos::View<double**, layout_right, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
103typedef Kokkos::View<double**, layout_left, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
105typedef Kokkos::View<double*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
107typedef Kokkos::View<int*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
109
110// managed device data views
111typedef Kokkos::View<double**, layout_right, device_memory_space>
113typedef Kokkos::View<double**, layout_left, device_memory_space>
115typedef Kokkos::View<double*, device_memory_space>
117typedef Kokkos::View<int*, device_memory_space>
119
120// managed host data views
121typedef Kokkos::View<double**, layout_right, host_execution_space>
123typedef Kokkos::View<double**, layout_left, host_execution_space>
125typedef Kokkos::View<double*, host_execution_space>
127typedef Kokkos::View<int*, host_execution_space>
129
130// random number generator
131typedef Kokkos::Random_XorShift64_Pool<> pool_type;
132typedef typename pool_type::generator_type generator_type;
133
134using KokkosInitArguments = Kokkos::InitializationSettings;
135constexpr char KOKKOS_THREADS_ARG[] = "--kokkos-num-threads";
136
137template< bool B, class T = void >
138using enable_if_t = typename std::enable_if<B,T>::type;
139
140template<typename T>
141typename std::enable_if<1==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
142{ return T(str, dim_0); }
143
144template<typename T>
145typename std::enable_if<2==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
146{ return T(str, dim_0, dim_1); }
147
148//void compadre_rethrow_exception(std::exception &e, const std::string &extra_message) {
149// std::cout << extra_message + "\n\n" + e.what() << std::endl;
150//}
151
152//! compadre_assert_release is used for assertions that should always be checked, but generally
153//! are not expensive to verify or are not called frequently.
154#if COMPADRE_BUILD_ABBR == 1 || COMPADRE_BUILD_ABBR == 2
155# define compadre_assert_release(condition) do { \
156 if ( ! (condition)) { \
157 std::stringstream _ss_; \
158 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
159 << "\n"; \
160 throw std::logic_error(_ss_.str()); \
161 } \
162 } while (0)
163#else
164# define compadre_assert_release(condition)
165#endif
166
167//! compadre_kernel_assert_release is similar to compadre_assert_release, but is a call on the device,
168//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
169#if COMPADRE_BUILD_ABBR == 1 || COMPADRE_BUILD_ABBR == 2
170# define compadre_kernel_assert_release(condition) do { \
171 if ( ! (condition)) \
172 Kokkos::abort(#condition); \
173 } while (0)
174# else
175# define compadre_kernel_assert_release(condition)
176#endif
177
178//! compadre_assert_debug is used for assertions that are checked in loops, as these significantly
179//! impact performance. When NDEBUG is set, these conditions are not checked.
180#ifdef COMPADRE_DEBUG
181# define compadre_assert_debug(condition) do { \
182 if ( ! (condition)) { \
183 std::stringstream _ss_; \
184 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
185 << "\n"; \
186 throw std::logic_error(_ss_.str()); \
187 } \
188 } while (0)
189# define compadre_kernel_assert_debug(condition) do { \
190 if ( ! (condition)) \
191 Kokkos::abort(#condition); \
192 } while (0)
193#else
194# define compadre_assert_debug(condition)
195# define compadre_kernel_assert_debug(condition)
196#endif
197//! compadre_kernel_assert_debug is similar to compadre_assert_debug, but is a call on the device,
198//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
199
200#ifdef COMPADRE_EXTREME_DEBUG
201# define compadre_assert_extreme_debug(condition) do { \
202 if ( ! (condition)) { \
203 std::stringstream _ss_; \
204 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
205 << "\n"; \
206 throw std::logic_error(_ss_.str()); \
207 } \
208 } while (0)
209# define compadre_kernel_assert_extreme_debug(condition) do { \
210 if ( ! (condition)) \
211 Kokkos::abort(#condition); \
212 } while (0)
213#else
214# define compadre_assert_extreme_debug(condition)
215# define compadre_kernel_assert_extreme_debug(condition)
216#endif
217//! compadre_kernel_assert_extreme_debug is similar to compadre_assert_debug, but is a call on the device,
218//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
219
220} // Compadre namespace
221
222#endif
Kokkos::Random_XorShift64_Pool pool_type
Kokkos::View< int *, device_memory_space > device_managed_local_index_type
std::enable_if< 1==T::rank, T >::type createView(std::string str, int dim_0, int dim_1)
Kokkos::View< int *, host_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_local_index_type
Kokkos::View< double *, host_execution_space > host_managed_vector_type
Kokkos::View< double **, layout_right, host_execution_space > host_managed_matrix_right_type
Kokkos::View< int *, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_unmanaged_local_index_type
Kokkos::View< double **, layout_right, device_memory_space > device_managed_matrix_right_type
Kokkos::View< double *, device_memory_space > device_managed_vector_type
team_policy::member_type member_type
Kokkos::View< double *, device_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_vector_type
Kokkos::TeamPolicy< host_execution_space > host_team_policy
pool_type::generator_type generator_type
Kokkos::View< double **, layout_right, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_unmanaged_matrix_right_type
Kokkos::TeamPolicy< device_execution_space > team_policy
Kokkos::View< double **, layout_left, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_unmanaged_matrix_left_type
Kokkos::LayoutRight layout_right
Kokkos::View< int *, host_execution_space > host_managed_local_index_type
Kokkos::View< double **, layout_right, device_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Kokkos::View< double **, layout_left, device_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_left_type
Kokkos::View< int *, device_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_local_index_type
typename std::enable_if< B, T >::type enable_if_t
Kokkos::View< double **, layout_left, host_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_matrix_left_type
Kokkos::View< double *, host_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_unmanaged_vector_type
host_team_policy::member_type host_member_type
Kokkos::View< double **, layout_left, host_execution_space > host_managed_matrix_left_type
constexpr char KOKKOS_THREADS_ARG[]
Kokkos::DefaultHostExecutionSpace host_execution_space
Kokkos::InitializationSettings KokkosInitArguments
host_execution_space::memory_space host_memory_space
std::size_t global_index_type
Kokkos::View< double **, layout_right, host_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_matrix_right_type
Kokkos::View< double **, layout_right, device_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > device_unmanaged_matrix_right_type
Kokkos::View< int *, device_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > device_unmanaged_local_index_type
Kokkos::View< double **, layout_left, device_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > device_unmanaged_matrix_left_type
host_execution_space::scratch_memory_space host_scratch
device_execution_space::memory_space device_memory_space
device_execution_space::scratch_memory_space device_scratch
Kokkos::DefaultExecutionSpace device_execution_space
Kokkos::View< double **, layout_left, device_memory_space > device_managed_matrix_left_type
Kokkos::LayoutLeft layout_left
Kokkos::View< double *, device_execution_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > device_unmanaged_vector_type
Kokkos::View< double *, host_scratch, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_scratch_vector_type