23template <
typename T >
28 Kokkos::atomic_add( ptr, val );
32 Kokkos::atomic_min( ptr, val );
36 Kokkos::atomic_max( ptr, val );
43template <
typename DataView,
bool is_scalar >
44KOKKOS_INLINE_FUNCTION DataView::value_type
45 value(
const DataView& data,
int local_subdomain_id,
int x,
int y,
int r,
int d )
47 if constexpr ( is_scalar )
49 return data( local_subdomain_id, x, y, r );
53 return data( local_subdomain_id, x, y, r, d );
57template <
typename DataView,
bool is_scalar >
58KOKKOS_INLINE_FUNCTION DataView::value_type&
59 value_ref(
const DataView& data,
int local_subdomain_id,
int x,
int y,
int r,
int d )
61 if constexpr ( is_scalar )
63 return data( local_subdomain_id, x, y, r );
67 return data( local_subdomain_id, x, y, r, d );
73 idx(
const int loop_idx,
94 return size - 1 - loop_idx;
101namespace detail_view_constraints {
107template <
class... Args >
120template <
int VecDim,
typename BufferView,
typename ViewType >
121std::enable_if_t< detail_view_constraints::is_kokkos_view_v< BufferView > && ( std::decay_t< BufferView >::rank == 1 ) >
123 const BufferView& buffer,
124 const ViewType& data,
125 const int local_subdomain_id,
130 std::decay_t< ViewType >::rank == 4 || std::decay_t< ViewType >::rank == 5,
131 "copy_to_buffer expects ViewType rank 4 (scalar) or 5 (vector-valued)." );
133 constexpr bool is_scalar = ( std::decay_t< ViewType >::rank == 4 );
135 if ( buffer.extent( 0 ) != VecDim )
136 Kokkos::abort(
"The buffer VecDim should match its respective extent. This abort should not happen." );
142 const auto size_x = data.extent( 1 );
143 const auto size_y = data.extent( 2 );
144 const auto size_r = data.extent( 3 );
146 Kokkos::parallel_for(
147 "copy_to_buffer_0D", Kokkos::RangePolicy( 0, buffer.extent( 0 ) ), KOKKOS_LAMBDA(
const int d ) {
159template <
int VecDim,
typename BufferView,
typename ViewType >
160std::enable_if_t< detail_view_constraints::is_kokkos_view_v< BufferView > && ( std::decay_t< BufferView >::rank == 2 ) >
162 const BufferView& buffer,
163 const ViewType& data,
164 const int local_subdomain_id,
168 std::decay_t< ViewType >::rank == 4 || std::decay_t< ViewType >::rank == 5,
169 "copy_to_buffer expects ViewType rank 4 (scalar) or 5 (vector-valued)." );
171 constexpr bool is_scalar = ( std::decay_t< ViewType >::rank == 4 );
173 if ( buffer.extent( 1 ) != VecDim )
174 Kokkos::abort(
"The buffer VecDim should match its respective extent. This abort should not happen." );
180 const auto size_x = data.extent( 1 );
181 const auto size_y = data.extent( 2 );
182 const auto size_r = data.extent( 3 );
184 Kokkos::parallel_for(
186 Kokkos::MDRangePolicy( { 0, 0 }, { buffer.extent( 0 ), buffer.extent( 1 ) } ),
187 KOKKOS_LAMBDA(
const int idx,
const int d ) {
199template <
int VecDim,
typename BufferView,
typename ViewType >
200std::enable_if_t< detail_view_constraints::is_kokkos_view_v< BufferView > && ( std::decay_t< BufferView >::rank == 3 ) >
202 const BufferView& buffer,
203 const ViewType& data,
204 const int local_subdomain_id,
208 std::decay_t< ViewType >::rank == 4 || std::decay_t< ViewType >::rank == 5,
209 "copy_to_buffer expects ViewType rank 4 (scalar) or 5 (vector-valued)." );
211 constexpr bool is_scalar = ( std::decay_t< ViewType >::rank == 4 );
213 if ( buffer.extent( 2 ) != VecDim )
214 Kokkos::abort(
"The buffer VecDim should match its respective extent. This abort should not happen." );
220 const auto size_x = data.extent( 1 );
221 const auto size_y = data.extent( 2 );
222 const auto size_r = data.extent( 3 );
224 Kokkos::parallel_for(
226 Kokkos::MDRangePolicy( { 0, 0, 0 }, { buffer.extent( 0 ), buffer.extent( 1 ), buffer.extent( 2 ) } ),
227 KOKKOS_LAMBDA(
const int i,
const int j,
const int d ) {
228 int x = 0, y = 0, r = 0;
253template <
typename ScalarType,
int VecDim,
typename ViewType >
256 const ViewType& data,
257 const int local_subdomain_id,
261 std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > > ||
262 std::is_same_v< ViewType, grid::Grid4DDataVec< ScalarType, VecDim > > );
264 constexpr bool is_scalar = std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > >;
266 if ( buffer.extent( 0 ) != VecDim )
268 Kokkos::abort(
"The buffer VecDim should match its respective extent. This abort should not happen." );
275 const auto size_x = data.extent( 1 );
276 const auto size_y = data.extent( 2 );
277 const auto size_r = data.extent( 3 );
279 Kokkos::parallel_for(
280 "copy_to_buffer_0D", Kokkos::RangePolicy( 0, buffer.extent( 0 ) ), KOKKOS_LAMBDA(
const int d ) {
288template <
typename ScalarType,
int VecDim,
typename ViewType >
291 const ViewType& data,
292 const int local_subdomain_id,
296 std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > > ||
297 std::is_same_v< ViewType, grid::Grid4DDataVec< ScalarType, VecDim > > );
299 constexpr bool is_scalar = std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > >;
301 if ( buffer.extent( 1 ) != VecDim )
303 Kokkos::abort(
"The buffer VecDim should match its respective extent. This abort should not happen." );
310 const auto size_x = data.extent( 1 );
311 const auto size_y = data.extent( 2 );
312 const auto size_r = data.extent( 3 );
314 Kokkos::parallel_for(
316 Kokkos::MDRangePolicy( { 0, 0 }, { buffer.extent( 0 ), buffer.extent( 1 ) } ),
317 KOKKOS_LAMBDA(
const int idx,
const int d ) {
325template <
typename ScalarType,
int VecDim,
typename ViewType >
328 const ViewType& data,
329 const int local_subdomain_id,
333 std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > > ||
334 std::is_same_v< ViewType, grid::Grid4DDataVec< ScalarType, VecDim > > );
336 constexpr bool is_scalar = std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > >;
338 if ( buffer.extent( 2 ) != VecDim )
340 Kokkos::abort(
"The buffer VecDim should match its respective extent. This abort should not happen." );
347 const auto size_x = data.extent( 1 );
348 const auto size_y = data.extent( 2 );
349 const auto size_r = data.extent( 3 );
351 Kokkos::parallel_for(
353 Kokkos::MDRangePolicy( { 0, 0, 0 }, { buffer.extent( 0 ), buffer.extent( 1 ), buffer.extent( 2 ) } ),
354 KOKKOS_LAMBDA(
const int i,
const int j,
const int d ) {
385template <
typename BufferView,
typename ViewType >
387 const BufferView& buffer,
388 const ViewType& data,
389 const int local_subdomain_id,
393 using ScalarType =
typename BufferView::value_type;
394 constexpr bool is_scalar = std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > >;
400 const auto size_x = data.extent( 1 );
401 const auto size_y = data.extent( 2 );
402 const auto size_r = data.extent( 3 );
404 Kokkos::parallel_for(
405 "copy_from_buffer_0D", Kokkos::RangePolicy( 0, buffer.extent( 0 ) ), KOKKOS_LAMBDA(
const int d ) {
416template <
typename BufferView,
typename ViewType >
418 const BufferView& buffer,
419 const ViewType& data,
420 const int local_subdomain_id,
425 using ScalarType =
typename BufferView::value_type;
426 constexpr bool is_scalar = std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > >;
432 const auto size_x = data.extent( 1 );
433 const auto size_y = data.extent( 2 );
434 const auto size_r = data.extent( 3 );
436 Kokkos::parallel_for(
437 "copy_from_buffer_1D",
438 Kokkos::MDRangePolicy( { 0, 0 }, { buffer.extent( 0 ), buffer.extent( 1 ) } ),
439 KOKKOS_LAMBDA(
const int idx,
const int d ) {
440 auto x =
detail::idx( idx, size_x, boundary_position_x, boundary_direction );
441 auto y =
detail::idx( idx, size_y, boundary_position_y, boundary_direction );
442 auto r =
detail::idx( idx, size_r, boundary_position_r, boundary_direction );
450template <
typename BufferView,
typename ViewType >
452 const BufferView& buffer,
453 const ViewType& data,
454 const int local_subdomain_id,
456 const std::tuple< grid::BoundaryDirection, grid::BoundaryDirection > boundary_directions,
459 using ScalarType =
typename BufferView::value_type;
460 constexpr bool is_scalar = std::is_same_v< ViewType, grid::Grid4DDataScalar< ScalarType > >;
466 const auto size_x = data.extent( 1 );
467 const auto size_y = data.extent( 2 );
468 const auto size_r = data.extent( 3 );
470 const auto boundary_direction_0 = std::get< 0 >( boundary_directions );
471 const auto boundary_direction_1 = std::get< 1 >( boundary_directions );
473 Kokkos::parallel_for(
474 "copy_from_buffer_2D",
475 Kokkos::MDRangePolicy( { 0, 0, 0 }, { buffer.extent( 0 ), buffer.extent( 1 ), buffer.extent( 2 ) } ),
476 KOKKOS_LAMBDA(
const int i,
const int j,
const int d ) {
484 y =
detail::idx( i, size_y, boundary_position_y, boundary_direction_0 );
485 r =
detail::idx( j, size_r, boundary_position_r, boundary_direction_1 );
489 x =
detail::idx( i, size_x, boundary_position_x, boundary_direction_0 );
491 r =
detail::idx( j, size_r, boundary_position_r, boundary_direction_1 );
495 x =
detail::idx( i, size_x, boundary_position_x, boundary_direction_0 );
496 y =
detail::idx( j, size_y, boundary_position_y, boundary_direction_1 );
constexpr bool is_kokkos_view_v
Definition buffer_copy_kernels.hpp:112
constexpr int idx(const int loop_idx, const int size, const grid::BoundaryPosition position, const grid::BoundaryDirection direction)
Definition buffer_copy_kernels.hpp:73
DataView::value_type value(const DataView &data, int local_subdomain_id, int x, int y, int r, int d)
Definition buffer_copy_kernels.hpp:45
void reduction_function(T *ptr, const T &val, const CommunicationReduction reduction_type)
Helper function to defer to the respective Kokkos::atomic_xxx() reduction function.
Definition buffer_copy_kernels.hpp:24
DataView::value_type & value_ref(const DataView &data, int local_subdomain_id, int x, int y, int r, int d)
Definition buffer_copy_kernels.hpp:59
Definition buffer_copy_kernels.hpp:5
std::enable_if_t< detail_view_constraints::is_kokkos_view_v< BufferView > &&(std::decay_t< BufferView >::rank==1) > copy_to_buffer(const BufferView &buffer, const ViewType &data, const int local_subdomain_id, const grid::BoundaryVertex boundary_vertex)
Definition buffer_copy_kernels.hpp:122
void copy_from_buffer_rotate_and_reduce(const BufferView &buffer, const ViewType &data, const int local_subdomain_id, const grid::BoundaryVertex boundary_vertex, const CommunicationReduction reduction)
Definition buffer_copy_kernels.hpp:386
CommunicationReduction
Communication reduction modes.
Definition buffer_copy_kernels.hpp:9
@ MAX
Stores the max of all received values during receive.
@ SUM
Sums up the node values during receive.
@ MIN
Stores the min of all received values during receive.
BoundaryPosition
Enum for encoding the boundary type tuples (in BoundaryVertex, BoundaryEdge, BoundaryFace).
Definition grid_types.hpp:223
BoundaryVertex
Enum for identification of the 8 boundary vertices of a subdomain.
Definition grid_types.hpp:248
BoundaryDirection
Enum for the iteration direction at a boundary.
Definition grid_types.hpp:311
Kokkos::View< ScalarType **[VecDim], Layout > Grid2DDataVec
Definition grid_types.hpp:39
Kokkos::View< ScalarType *[VecDim], Layout > Grid1DDataVec
Definition grid_types.hpp:36
constexpr BoundaryPosition boundary_position_from_boundary_type_y(const BoundaryType &boundary_type)
Definition grid_types.hpp:327
constexpr BoundaryPosition boundary_position_from_boundary_type_r(const BoundaryType &boundary_type)
Definition grid_types.hpp:337
Kokkos::View< ScalarType[VecDim], Layout > Grid0DDataVec
Definition grid_types.hpp:33
BoundaryFace
Enum for identification of the 6 boundary faces of a subdomain.
Definition grid_types.hpp:297
constexpr BoundaryPosition boundary_position_from_boundary_type_x(const BoundaryType &boundary_type)
Definition grid_types.hpp:317
BoundaryEdge
Enum for identification of the 12 boundary edges of a subdomain.
Definition grid_types.hpp:269
Definition buffer_copy_kernels.hpp:105