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