KokkosUtilities.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __KokkosUtilities_hpp__
22 #define __KokkosUtilities_hpp__
23 
24 
25 #include "KokkosTypes.hpp"
26 #include "pFlowMacros.hpp"
27 #include "types.hpp"
28 
29 
30 namespace pFlow
31 {
32 
33 template<typename ExecutionSpace>
35 bool constexpr isHostAccessible()
36 {
37  return Kokkos::SpaceAccessibility<ExecutionSpace,HostSpace>::accessible;
38 }
39 
40 template<typename ExecutionSpace, typename MemoerySpace>
42 bool constexpr areAccessible()
43 {
44  return Kokkos::SpaceAccessibility<ExecutionSpace,MemoerySpace>::accessible;
45 }
46 
47 template <
48  typename Type,
49  typename... Properties>
52 {
53  Kokkos::realloc(view, len);
54 }
55 
56 template <
57  typename Type,
58  typename... Properties>
61 {
62  using ViewType = ViewType1D<Type,Properties...>;
63  word vl = view.label();
64  view = ViewType(); // Deallocate first
65  view = ViewType(
66  Kokkos::view_alloc(
67  Kokkos::WithoutInitializing,
68  vl),
69  len);
70 }
71 
72 template <
73  typename Type,
74  typename... Properties>
77 {
78  reallocNoInit(view, len);
79  Kokkos::deep_copy(view, val);
80 }
81 
82 
83 template <
84  typename Type,
85  typename... Properties>
87 void realloc( ViewType3D<Type,Properties...>& view, int32 len1, int32 len2, int32 len3)
88 {
89  Kokkos::realloc(view, len1, len2, len3);
90 }
91 
92 template <
93  typename Type,
94  typename... Properties>
97 {
98  using ViewType = ViewType3D<Type,Properties...>;
99  word vl = view.label();
100  view = ViewType(); // Deallocate first
101  view = ViewType(
102  Kokkos::view_alloc(
103  Kokkos::WithoutInitializing,
104  vl),
105  len1, len2, len3);
106 }
107 
108 template <
109  typename Type,
110  typename... Properties>
112 void reallocFill( ViewType3D<Type,Properties...>& view, int32 len1, int32 len2, int32 len3, Type val)
113 {
114  reallocNoInit(view, len1, len2, len3);
115  Kokkos::deep_copy(view, val);
116 }
117 
118 
119 template<typename ViewType>
121 void swapViews(ViewType& v1, ViewType &v2)
122 {
123  auto tmp = v1;
124  v1 = v2;
125  v2 = tmp;
126 }
127 
128 } // pFlow
129 
130 #endif //__KokkosUtilities_hpp__
pFlow::reallocFill
INLINE_FUNCTION_H void reallocFill(ViewType1D< Type, Properties... > &view, int32 len, Type val)
Definition: KokkosUtilities.hpp:76
types.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
KokkosTypes.hpp
pFlow::reallocNoInit
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:60
pFlow
Definition: demComponent.hpp:28
pFlowMacros.hpp
pFlow::realloc
INLINE_FUNCTION_H void realloc(ViewType1D< Type, Properties... > &view, int32 len)
Definition: KokkosUtilities.hpp:51
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::areAccessible
INLINE_FUNCTION_H constexpr bool areAccessible()
Definition: KokkosUtilities.hpp:42
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::isHostAccessible
INLINE_FUNCTION_H constexpr bool isHostAccessible()
Definition: KokkosUtilities.hpp:35
pFlow::realloc
INLINE_FUNCTION_H void realloc(ViewType3D< Type, Properties... > &view, int32 len1, int32 len2, int32 len3)
Definition: KokkosUtilities.hpp:87
pFlow::swapViews
INLINE_FUNCTION_H void swapViews(ViewType &v1, ViewType &v2)
Definition: KokkosUtilities.hpp:121
pFlow::ViewType3D
Kokkos::View< T ***, properties... > ViewType3D
Definition: KokkosTypes.hpp:68