Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kokkos_View_Fad_Fwd.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef KOKKOS_VIEW_FAD_FWD_HPP
11 #define KOKKOS_VIEW_FAD_FWD_HPP
12 
13 #include "Sacado_ConfigDefs.h"
14 #if defined(HAVE_SACADO_KOKKOS)
15 
16 // We are hooking into Kokkos Core internals here
17 // Need to define this macro since we include non-public headers
18 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
19 #define KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
21 #endif
22 // Only include forward declarations so any overloads appear before they
23 // might be used inside Kokkos
24 #include "Kokkos_Core_fwd.hpp"
25 #include "Kokkos_View.hpp"
26 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
27 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
28 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
29 #endif
30 
31 namespace Kokkos {
32 
33 // Whether a given type is a view with Sacado FAD scalar type
34 template <typename view_type>
35 struct is_view_fad;
36 
37 }
38 
39 // Make sure the user really wants these View specializations
40 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
41 
42 namespace Kokkos {
43 namespace Impl {
44 
45 struct ViewSpecializeSacadoFad;
46 struct ViewSpecializeSacadoFadContiguous;
47 
48 // Overload view_copy for Fad View's:
49 // 1. Should be faster than using Fad directly
50 // 2. Fixes issues with hierarchical parallelism since the default
51 // implementation uses MDRangePolicy which doesn't work with hierarchical
52 // parallelism.
53 // Needs to go before include of Kokkos_Core.hpp so it is in scope when
54 // Kokkos_CopyViews.hpp is included by Kokkos_Core.hpp, which internally
55 // calls view_copy().
56 template<class DT, class ... DP,
57  class ST, class ... SP>
58 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
59  is_view_fad< Kokkos::View<ST,SP...> >::value
60  >::type
61 view_copy(const Kokkos::View<DT,DP...>& dst, const Kokkos::View<ST,SP...>& src);
62 
63 template<class ExecutionSpace,
64  class DT, class ... DP,
65  class ST, class ... SP>
66 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
67  is_view_fad< Kokkos::View<ST,SP...> >::value
68  >::type
69 view_copy(const ExecutionSpace& space,
70  const Kokkos::View<DT,DP...>& dst, const Kokkos::View<ST,SP...>& src);
71 
72 template<class Space, class T, class ... P>
73 struct MirrorViewType;
74 
75 } // namespace Impl
76 
77 // Declare overloads of create_mirror() so they are in scope
78 // Kokkos_Core.hpp is included later
79 
80 template< class T , class ... P >
81 inline
82 typename std::enable_if<
83  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
84  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
85  std::is_same< typename ViewTraits<T,P...>::specialize ,
86  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
87  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
88  Kokkos::LayoutStride >::value,
89  typename Kokkos::View<T,P...>::HostMirror>::type
90 create_mirror(const Kokkos::View<T,P...> & src);
91 
92 template< class T , class ... P >
93 inline
94 typename std::enable_if<
95  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
96  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
97  std::is_same< typename ViewTraits<T,P...>::specialize ,
98  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
99  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
100  Kokkos::LayoutStride >::value,
101  typename Kokkos::View<T,P...>::HostMirror>::type
102 create_mirror(const Kokkos::View<T,P...> & src);
103 
104 template<class Space, class T, class ... P,
106 typename std::enable_if<
107  std::is_same< typename ViewTraits<T,P...>::specialize ,
108  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
109  std::is_same< typename ViewTraits<T,P...>::specialize ,
110  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value,
111  typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type>::type
112 create_mirror(const Space&, const Kokkos::View<T,P...> & src);
113 
114 template< class T , class ... P >
115 inline
116 typename std::enable_if<
117  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
118  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
119  std::is_same< typename ViewTraits<T,P...>::specialize ,
120  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
121  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
122  Kokkos::LayoutStride >::value,
123  typename Kokkos::View<T,P...>::HostMirror>::type
124 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
125  const Kokkos::View<T,P...> & src);
126 
127 template< class T , class ... P >
128 inline
129 typename std::enable_if<
130  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
131  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
132  std::is_same< typename ViewTraits<T,P...>::specialize ,
133  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
134  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
135  Kokkos::LayoutStride >::value,
136  typename Kokkos::View<T,P...>::HostMirror>::type
137 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
138  const Kokkos::View<T,P...> & src);
139 
140 template<class Space, class T, class ... P,
142 typename std::enable_if<
143  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
144  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
145  std::is_same< typename ViewTraits<T,P...>::specialize ,
146  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ),
147  typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type>::type
148 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
149  const Space&, const Kokkos::View<T,P...> & src);
150 
151 template <class Space, class T, class... P>
152 typename Impl::MirrorViewType<Space, T, P...>::view_type
153 create_mirror_view_and_copy(
154  const Space&, const Kokkos::View<T, P...>& src,
155  std::string const& name = "",
156  typename std::enable_if<
157  ( std::is_same<typename ViewTraits<T, P...>::specialize,
158  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
159  std::is_same< typename ViewTraits<T,P...>::specialize ,
160  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
161  Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
162  nullptr);
163 
164 template <class Space, class T, class... P>
165 typename Impl::MirrorViewType<Space, T, P...>::view_type
166 create_mirror_view_and_copy(
167  const Space&, const Kokkos::View<T, P...>& src,
168  std::string const& name = "",
169  typename std::enable_if<
170  ( std::is_same<typename ViewTraits<T, P...>::specialize,
171  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
172  std::is_same< typename ViewTraits<T,P...>::specialize ,
173  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
174  !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
175  nullptr);
176 
177 namespace Impl {
178 
179 template <unsigned N, typename... Args>
180 KOKKOS_FUNCTION std::enable_if_t<
181  N == View<Args...>::Rank &&
182  (std::is_same<typename ViewTraits<Args...>::specialize,
183  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
184  std::is_same<typename ViewTraits<Args...>::specialize,
185  Kokkos::Impl::ViewSpecializeSacadoFadContiguous>::value),
186  View<Args...>>
187 as_view_of_rank_n(View<Args...> v);
188 
189 // Placeholder implementation to compile generic code for DynRankView; should
190 // never be called
191 template <unsigned N, typename T, typename... Args>
192 std::enable_if_t<
193  N != View<T, Args...>::Rank &&
194  (std::is_same<typename ViewTraits<T, Args...>::specialize,
195  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
196  std::is_same<typename ViewTraits<T, Args...>::specialize,
197  Kokkos::Impl::ViewSpecializeSacadoFadContiguous>::value),
198  View<typename RankDataType<typename View<T, Args...>::value_type, N>::type,
199  Args...>>
200 as_view_of_rank_n(View<T, Args...>);
201 
202 }
203 
204 namespace Experimental {
205 
206 template <class DT, class... DP>
207 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
208  const View<DT, DP...>& dst,
209  typename ViewTraits<DT, DP...>::const_value_type& value,
210  typename std::enable_if<(
211  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
212  Kokkos::Impl::ViewSpecializeSacadoFad >::value
213  ||
214  std::is_same< typename ViewTraits<DT,DP...>::specialize,
215  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
216  && (unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type* = nullptr);
217 
218 template <class DT, class... DP>
219 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
220  const View<DT, DP...>& dst,
221  typename ViewTraits<DT, DP...>::const_value_type& value,
222  typename std::enable_if<(
223  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
224  Kokkos::Impl::ViewSpecializeSacadoFad >::value
225  ||
226  std::is_same< typename ViewTraits<DT,DP...>::specialize,
227  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
228  && (unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type* = nullptr);
229 
230 template <class DT, class... DP>
231 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
232  const View<DT, DP...>& dst,
233  typename ViewTraits<DT, DP...>::const_value_type& value,
234  typename std::enable_if<(
235  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
236  Kokkos::Impl::ViewSpecializeSacadoFad >::value
237  ||
238  std::is_same< typename ViewTraits<DT,DP...>::specialize,
239  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
240  && (unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type* = nullptr);
241 
242 template <class DT, class... DP>
243 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
244  const View<DT, DP...>& dst,
245  typename ViewTraits<DT, DP...>::const_value_type& value,
246  typename std::enable_if<(
247  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
248  Kokkos::Impl::ViewSpecializeSacadoFad >::value
249  ||
250  std::is_same< typename ViewTraits<DT,DP...>::specialize,
251  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
252  && (unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type* = nullptr);
253 
254 template <class DT, class... DP>
255 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
256  const View<DT, DP...>& dst,
257  typename ViewTraits<DT, DP...>::const_value_type& value,
258  typename std::enable_if<(
259  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
260  Kokkos::Impl::ViewSpecializeSacadoFad >::value
261  ||
262  std::is_same< typename ViewTraits<DT,DP...>::specialize,
263  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
264  && (unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type* = nullptr);
265 
266 template <class DT, class... DP>
267 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
268  const View<DT, DP...>& dst,
269  typename ViewTraits<DT, DP...>::const_value_type& value,
270  typename std::enable_if<(
271  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
272  Kokkos::Impl::ViewSpecializeSacadoFad >::value
273  ||
274  std::is_same< typename ViewTraits<DT,DP...>::specialize,
275  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
276  && (unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type* = nullptr);
277 
278 template <class DT, class... DP>
279 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
280  const View<DT, DP...>& dst,
281  typename ViewTraits<DT, DP...>::const_value_type& value,
282  typename std::enable_if<(
283  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
284  Kokkos::Impl::ViewSpecializeSacadoFad >::value
285  ||
286  std::is_same< typename ViewTraits<DT,DP...>::specialize,
287  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
288  && (unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type* = nullptr);
289 
290 template <class TeamType, class DT, class... DP>
291 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
292  const TeamType& team, const View<DT, DP...>& dst,
293  typename ViewTraits<DT, DP...>::const_value_type& value,
294  typename std::enable_if<(
295  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
296  Kokkos::Impl::ViewSpecializeSacadoFad >::value
297  ||
298  std::is_same< typename ViewTraits<DT,DP...>::specialize,
299  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
300  && (unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type* = nullptr);
301 
302 template <class TeamType, class DT, class... DP>
303 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
304  const TeamType& team, const View<DT, DP...>& dst,
305  typename ViewTraits<DT, DP...>::const_value_type& value,
306  typename std::enable_if<(
307  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
308  Kokkos::Impl::ViewSpecializeSacadoFad >::value
309  ||
310  std::is_same< typename ViewTraits<DT,DP...>::specialize,
311  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
312  && (unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type* = nullptr);
313 
314 template <class TeamType, class DT, class... DP>
315 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
316  const TeamType& team, const View<DT, DP...>& dst,
317  typename ViewTraits<DT, DP...>::const_value_type& value,
318  typename std::enable_if<(
319  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
320  Kokkos::Impl::ViewSpecializeSacadoFad >::value
321  ||
322  std::is_same< typename ViewTraits<DT,DP...>::specialize,
323  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
324  && (unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type* = nullptr);
325 
326 template <class TeamType, class DT, class... DP>
327 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
328  const TeamType& team, const View<DT, DP...>& dst,
329  typename ViewTraits<DT, DP...>::const_value_type& value,
330  typename std::enable_if<(
331  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
332  Kokkos::Impl::ViewSpecializeSacadoFad >::value
333  ||
334  std::is_same< typename ViewTraits<DT,DP...>::specialize,
335  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
336  && (unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type* = nullptr);
337 
338 template <class TeamType, class DT, class... DP>
339 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
340  const TeamType& team, const View<DT, DP...>& dst,
341  typename ViewTraits<DT, DP...>::const_value_type& value,
342  typename std::enable_if<(
343  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
344  Kokkos::Impl::ViewSpecializeSacadoFad >::value
345  ||
346  std::is_same< typename ViewTraits<DT,DP...>::specialize,
347  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
348  && (unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type* = nullptr);
349 
350 template <class TeamType, class DT, class... DP>
351 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
352  const TeamType& team, const View<DT, DP...>& dst,
353  typename ViewTraits<DT, DP...>::const_value_type& value,
354  typename std::enable_if<(
355  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
356  Kokkos::Impl::ViewSpecializeSacadoFad >::value
357  ||
358  std::is_same< typename ViewTraits<DT,DP...>::specialize,
359  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
360  && (unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type* = nullptr);
361 
362 template <class TeamType, class DT, class... DP>
363 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
364  const TeamType& team, const View<DT, DP...>& dst,
365  typename ViewTraits<DT, DP...>::const_value_type& value,
366  typename std::enable_if<(
367  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
368  Kokkos::Impl::ViewSpecializeSacadoFad >::value
369  ||
370  std::is_same< typename ViewTraits<DT,DP...>::specialize,
371  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
372  && (unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type* = nullptr);
373 
374 }
375 
376 } // namespace Kokkos
377 
378 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
379 
380 #endif // defined(HAVE_SACADO_KOKKOS)
381 
382 #endif /* #ifndef KOKKOS_VIEW_FAD_FWD_HPP */
#define T
Definition: Sacado_rad.hpp:553
const int N
int value