XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
my_mirror_view.hpp
Go to the documentation of this file.
1 #ifndef MY_MIRROR_VIEW_HPP
2 #define MY_MIRROR_VIEW_HPP
3 
4 #include "space_settings.hpp"
5 #include "globals.hpp"
6 
7 /* Creating my own mirror view because there is not currently a NoInit option with the standard mirror view */
8 
9 // 1D mirrorview
10 // view is the view that the output will mirror
11 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
12 // scratch_view is if there is already a place for the mirror to go if needed
13 template<class Device, typename T>
14 View<T*,CLayout,Device> my_mirror_view(const View<T*,CLayout,Device>& view, Device nd){
15  return view;
16 }
17 
18 template<class NewDevice, class Device, typename T>
19 View<T*,CLayout,NewDevice> my_mirror_view(const View<T*,CLayout,Device>& view, NewDevice nd){
20  return View<T*,CLayout,NewDevice>(NoInit("mirror"), view.layout());
21 }
22 
23 // 1D mirrorview - with scratch
24 // view is the view that the output will mirror
25 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
26 // scratch_view is if there is already a place for the mirror to go if needed
27 template<class Device, typename T>
28 View<T*,CLayout,Device> my_mirror_view(const View<T*,CLayout,Device>& view, Device nd, const View<T*,CLayout,Device> scratch_view){
29  return view;
30 }
31 
32 template<class NewDevice, class Device, typename T>
33 View<T*,CLayout,NewDevice> my_mirror_view(const View<T*,CLayout,Device>& view, NewDevice nd, const View<T*,CLayout,NewDevice> scratch_view){
34  return scratch_view;
35 }
36 
37 // 2D mirrorview
38 // view is the view that the output will mirror
39 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
40 // scratch_view is if there is already a place for the mirror to go if needed
41 template<class Device, typename T>
42 View<T**,CLayout,Device> my_mirror_view(const View<T**,CLayout,Device>& view, Device nd){
43  return view;
44 }
45 
46 template<class NewDevice, class Device, typename T>
47 View<T**,CLayout,NewDevice> my_mirror_view(const View<T**,CLayout,Device>& view, NewDevice nd){
48  return View<T**,CLayout,NewDevice>(NoInit("mirror"), view.layout());
49 }
50 
51 // 2D mirrorview with scratch
52 // view is the view that the output will mirror
53 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
54 // scratch_view is if there is already a place for the mirror to go if needed
55 template<class Device, typename T>
56 View<T**,CLayout,Device> my_mirror_view(const View<T**,CLayout,Device>& view, Device nd, const View<T**,CLayout,Device> scratch_view){
57  return view;
58 }
59 
60 template<class NewDevice, class Device, typename T>
61 View<T**,CLayout,NewDevice> my_mirror_view(const View<T**,CLayout,Device>& view, NewDevice nd, const View<T**,CLayout,NewDevice> scratch_view){
62  return scratch_view;
63 }
64 
65 // 1D mirrorview - unmanaged
66 // view is the view that the output will mirror
67 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
68 // scratch_view is if there is already a place for the mirror to go if needed
69 template<class Device, typename T, typename T2>
70 View<T*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>> my_mirror_view(const View<T*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, Device nd, const T2& scratch_view){
71  return view;
72 }
73 
74 template<class NewDevice, class Device, typename T, typename T2>
75 View<T*,CLayout,NewDevice, Kokkos::MemoryTraits<Kokkos::Unmanaged>> my_mirror_view(const View<T*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, NewDevice nd, const T2& scratch_view){
76  return View<T*,CLayout,NewDevice, Kokkos::MemoryTraits<Kokkos::Unmanaged>>(scratch_view.data(), view.layout());
77 }
78 
79 // 2D mirrorview - unmanaged
80 // view is the view that the output will mirror
81 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
82 // scratch_view is if there is already a place for the mirror to go if needed
83 template<class Device, typename T, typename T2>
84 View<T**,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>> my_mirror_view(const View<T**,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, Device nd, const T2& scratch_view){
85  return view;
86 }
87 
88 template<class NewDevice, class Device, typename T, typename T2>
89 View<T**,CLayout,NewDevice, Kokkos::MemoryTraits<Kokkos::Unmanaged>> my_mirror_view(const View<T**,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, NewDevice nd, const T2& scratch_view){
90  return View<T**,CLayout,NewDevice, Kokkos::MemoryTraits<Kokkos::Unmanaged>>(scratch_view.data(), view.layout());
91 }
92 
93 // 1D mirror scratch view - A managed view to reflect an unmanaged view if needed
94 // view is the view that the output will mirror
95 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
96 template<class Device, typename T>
97 View<T*,CLayout,Device> my_mirror_scratch_view(const View<T*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, Device nd){
98  return View<T*,CLayout,Device>();
99 }
100 
101 template<class NewDevice, class Device, typename T>
102 View<T*,CLayout,NewDevice> my_mirror_scratch_view(const View<T*,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, NewDevice nd){
103  return View<T*,CLayout,NewDevice>("mirror_scratch", view.layout());
104 }
105 
106 // 2D mirror scratch view - A managed view to reflect an unmanaged view if needed
107 // view is the view that the output will mirror
108 // nd is used only for the templating, to get the new device (a bit cleaner than the alternative since partial template specialization is not permitted)
109 template<class Device, typename T>
110 View<T**,CLayout,Device> my_mirror_scratch_view(const View<T**,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, Device nd){
111  return View<T**,CLayout,Device>();
112 }
113 
114 template<class NewDevice, class Device, typename T>
115 View<T**,CLayout,NewDevice> my_mirror_scratch_view(const View<T**,CLayout,Device, Kokkos::MemoryTraits<Kokkos::Unmanaged>>& view, NewDevice nd){
116  return View<T**,CLayout,NewDevice>("mirror_scratch", view.layout());
117 }
118 
119 // Copies from view_src to view_dest unless they are pointing to the same location.
120 // This may already be checked in Kokkos::deep_copy.
121 template<class T1, class T2>
122 void mirror_copy(T1& view_dest, const T2& view_src){
123  if(std::is_same<typename T1::device_type,typename T2::device_type>() && view_dest.data()==view_src.data()){
124  // No-op
125  }else{
126  Kokkos::deep_copy(view_dest, view_src);
127  }
128 }
129 
130 #endif
void mirror_copy(T1 &view_dest, const T2 &view_src)
Definition: my_mirror_view.hpp:122
Kokkos::LayoutRight CLayout
Definition: space_settings.hpp:67
View< T *, CLayout, Device > my_mirror_scratch_view(const View< T *, CLayout, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged >> &view, Device nd)
Definition: my_mirror_view.hpp:97
View< T *, CLayout, Device > my_mirror_view(const View< T *, CLayout, Device > &view, Device nd)
Definition: my_mirror_view.hpp:14
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68