Compadre 1.7.0
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#ifdef COMPADRE_USE_CUDA
52 typedef typename Kokkos::CudaSpace device_memory_space;
53#else
54 typedef typename device_execution_space::memory_space device_memory_space;
55#endif
56
57// team policies
58typedef typename Kokkos::TeamPolicy<device_execution_space> team_policy;
59typedef typename team_policy::member_type member_type;
60
61typedef typename Kokkos::TeamPolicy<host_execution_space> host_team_policy;
62typedef typename host_team_policy::member_type host_member_type;
63
64// layout types
65typedef Kokkos::LayoutRight layout_right;
66typedef Kokkos::LayoutLeft layout_left;
67
68// scratch data wrappers
69typedef Kokkos::View<double**, layout_right, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
71typedef Kokkos::View<double**, layout_left, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
73typedef Kokkos::View<double*, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
75typedef Kokkos::View<int*, device_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
77
78// host equivalents
79typedef Kokkos::View<double**, layout_right, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
81typedef Kokkos::View<double**, layout_left, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
83typedef Kokkos::View<double*, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
85typedef Kokkos::View<int*, host_scratch, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
87
88// unmanaged devicedata deviews
89typedef Kokkos::View<double**, layout_right, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
91typedef Kokkos::View<double**, layout_left, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
93typedef Kokkos::View<double*, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
95typedef Kokkos::View<int*, device_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
97
98// host equivalents
99typedef Kokkos::View<double**, layout_right, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
101typedef Kokkos::View<double**, layout_left, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
103typedef Kokkos::View<double*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
105typedef Kokkos::View<int*, host_execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged> >
107
108// managed device data views
109typedef Kokkos::View<double**, layout_right, device_memory_space>
111typedef Kokkos::View<double**, layout_left, device_memory_space>
113typedef Kokkos::View<double*, device_memory_space>
115typedef Kokkos::View<int*, device_memory_space>
117
118// managed host data views
119typedef Kokkos::View<double**, layout_right, host_execution_space>
121typedef Kokkos::View<double**, layout_left, host_execution_space>
123typedef Kokkos::View<double*, host_execution_space>
125typedef Kokkos::View<int*, host_execution_space>
127
128// random number generator
129typedef Kokkos::Random_XorShift64_Pool<> pool_type;
130typedef typename pool_type::generator_type generator_type;
131
132using KokkosInitArguments = Kokkos::InitializationSettings;
133constexpr char KOKKOS_THREADS_ARG[] = "--kokkos-num-threads";
134
135template< bool B, class T = void >
136using enable_if_t = typename std::enable_if<B,T>::type;
137
138template<typename T>
139typename std::enable_if<1==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
140{ return T(str, dim_0); }
141
142template<typename T>
143typename std::enable_if<2==T::rank,T>::type createView(std::string str, int dim_0, int dim_1)
144{ return T(str, dim_0, dim_1); }
145
146//void compadre_rethrow_exception(std::exception &e, const std::string &extra_message) {
147// std::cout << extra_message + "\n\n" + e.what() << std::endl;
148//}
149
150//! compadre_assert_release is used for assertions that should always be checked, but generally
151//! are not expensive to verify or are not called frequently.
152# define compadre_assert_release(condition) do { \
153 if ( ! (condition)) { \
154 std::stringstream _ss_; \
155 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
156 << "\n"; \
157 throw std::logic_error(_ss_.str()); \
158 } \
159 } while (0)
160
161//! compadre_kernel_assert_release is similar to compadre_assert_release, but is a call on the device,
162//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
163# define compadre_kernel_assert_release(condition) do { \
164 if ( ! (condition)) \
165 Kokkos::abort(#condition); \
166 } while (0)
167
168//! compadre_assert_debug is used for assertions that are checked in loops, as these significantly
169//! impact performance. When NDEBUG is set, these conditions are not checked.
170#ifdef COMPADRE_DEBUG
171# define compadre_assert_debug(condition) do { \
172 if ( ! (condition)) { \
173 std::stringstream _ss_; \
174 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
175 << "\n"; \
176 throw std::logic_error(_ss_.str()); \
177 } \
178 } while (0)
179# define compadre_kernel_assert_debug(condition) do { \
180 if ( ! (condition)) \
181 Kokkos::abort(#condition); \
182 } while (0)
183#else
184# define compadre_assert_debug(condition)
185# define compadre_kernel_assert_debug(condition)
186#endif
187//! compadre_kernel_assert_debug is similar to compadre_assert_debug, but is a call on the device,
188//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
189
190#ifdef COMPADRE_EXTREME_DEBUG
191# define compadre_assert_extreme_debug(condition) do { \
192 if ( ! (condition)) { \
193 std::stringstream _ss_; \
194 _ss_ << __FILE__ << ":" << __LINE__ << ": FAIL:\n" << #condition \
195 << "\n"; \
196 throw std::logic_error(_ss_.str()); \
197 } \
198 } while (0)
199# define compadre_kernel_assert_extreme_debug(condition) do { \
200 if ( ! (condition)) \
201 Kokkos::abort(#condition); \
202 } while (0)
203#else
204# define compadre_assert_extreme_debug(condition)
205# define compadre_kernel_assert_extreme_debug(condition)
206#endif
207//! compadre_kernel_assert_extreme_debug is similar to compadre_assert_debug, but is a call on the device,
208//! namely inside of a function marked KOKKOS_INLINE_FUNCTION
209
210} // Compadre namespace
211
212#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