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 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef KOKKOS_VIEW_FAD_FWD_HPP
31 #define KOKKOS_VIEW_FAD_FWD_HPP
32 
33 #include "Sacado_ConfigDefs.h"
34 #if defined(HAVE_SACADO_KOKKOS)
35 
36 // We are hooking into Kokkos Core internals here
37 // Need to define this macro since we include non-public headers
38 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
39 #define KOKKOS_IMPL_PUBLIC_INCLUDE
40 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
41 #endif
42 // Only include forward declarations so any overloads appear before they
43 // might be used inside Kokkos
44 #include "Kokkos_Core_fwd.hpp"
45 #include "Kokkos_View.hpp"
46 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
47 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
48 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
49 #endif
50 
51 namespace Kokkos {
52 
53 // Whether a given type is a view with Sacado FAD scalar type
54 template <typename view_type>
55 struct is_view_fad;
56 
57 }
58 
59 // Make sure the user really wants these View specializations
60 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
61 
62 namespace Kokkos {
63 namespace Impl {
64 
65 struct ViewSpecializeSacadoFad;
66 struct ViewSpecializeSacadoFadContiguous;
67 
68 // Overload view_copy for Fad View's:
69 // 1. Should be faster than using Fad directly
70 // 2. Fixes issues with hierarchical parallelism since the default
71 // implementation uses MDRangePolicy which doesn't work with hierarchical
72 // parallelism.
73 // Needs to go before include of Kokkos_Core.hpp so it is in scope when
74 // Kokkos_CopyViews.hpp is included by Kokkos_Core.hpp, which internally
75 // calls view_copy().
76 template<class DT, class ... DP,
77  class ST, class ... SP>
78 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
79  is_view_fad< Kokkos::View<ST,SP...> >::value
80  >::type
81 view_copy(const Kokkos::View<DT,DP...>& dst, const Kokkos::View<ST,SP...>& src);
82 
83 template<class ExecutionSpace,
84  class DT, class ... DP,
85  class ST, class ... SP>
86 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
87  is_view_fad< Kokkos::View<ST,SP...> >::value
88  >::type
89 view_copy(const ExecutionSpace& space,
90  const Kokkos::View<DT,DP...>& dst, const Kokkos::View<ST,SP...>& src);
91 
92 template<class Space, class T, class ... P>
93 struct MirrorType;
94 template<class Space, class T, class ... P>
95 struct MirrorViewType;
96 
97 } // namespace Impl
98 
99 // Declare overloads of create_mirror() so they are in scope
100 // Kokkos_Core.hpp is included later
101 
102 template< class T , class ... P >
103 inline
104 typename std::enable_if<
105  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
106  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
107  std::is_same< typename ViewTraits<T,P...>::specialize ,
108  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
109  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
110  Kokkos::LayoutStride >::value,
111  typename Kokkos::View<T,P...>::HostMirror>::type
112 create_mirror(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(const Kokkos::View<T,P...> & src);
125 
126 template<class Space, class T, class ... P,
128 typename std::enable_if<
129  std::is_same< typename ViewTraits<T,P...>::specialize ,
130  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
131  std::is_same< typename ViewTraits<T,P...>::specialize ,
132  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value,
133  typename Impl::MirrorType<Space,T,P ...>::view_type>::type
134 create_mirror(const Space&, const Kokkos::View<T,P...> & src);
135 
136 template< class T , class ... P >
137 inline
138 typename std::enable_if<
139  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
140  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
141  std::is_same< typename ViewTraits<T,P...>::specialize ,
142  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
143  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
144  Kokkos::LayoutStride >::value,
145  typename Kokkos::View<T,P...>::HostMirror>::type
146 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
147  const Kokkos::View<T,P...> & src);
148 
149 template< class T , class ... P >
150 inline
151 typename std::enable_if<
152  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
153  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
154  std::is_same< typename ViewTraits<T,P...>::specialize ,
155  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
156  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
157  Kokkos::LayoutStride >::value,
158  typename Kokkos::View<T,P...>::HostMirror>::type
159 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
160  const Kokkos::View<T,P...> & src);
161 
162 template<class Space, class T, class ... P,
164 typename std::enable_if<
165  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
166  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
167  std::is_same< typename ViewTraits<T,P...>::specialize ,
168  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ),
169  typename Impl::MirrorType<Space,T,P ...>::view_type>::type
170 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
171  const Space&, const Kokkos::View<T,P...> & src);
172 
173 template <class Space, class T, class... P>
174 typename Impl::MirrorViewType<Space, T, P...>::view_type
175 create_mirror_view_and_copy(
176  const Space&, const Kokkos::View<T, P...>& src,
177  std::string const& name = "",
178  typename std::enable_if<
179  ( std::is_same<typename ViewTraits<T, P...>::specialize,
180  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
181  std::is_same< typename ViewTraits<T,P...>::specialize ,
182  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
183  Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
184  nullptr);
185 
186 template <class Space, class T, class... P>
187 typename Impl::MirrorViewType<Space, T, P...>::view_type
188 create_mirror_view_and_copy(
189  const Space&, const Kokkos::View<T, P...>& src,
190  std::string const& name = "",
191  typename std::enable_if<
192  ( std::is_same<typename ViewTraits<T, P...>::specialize,
193  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
194  std::is_same< typename ViewTraits<T,P...>::specialize ,
195  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
196  !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
197  nullptr);
198 
199 namespace Impl {
200 
201 template <unsigned N, typename... Args>
202 KOKKOS_FUNCTION std::enable_if_t<
203  N == View<Args...>::Rank &&
204  (std::is_same<typename ViewTraits<Args...>::specialize,
205  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
206  std::is_same<typename ViewTraits<Args...>::specialize,
207  Kokkos::Impl::ViewSpecializeSacadoFadContiguous>::value),
208  View<Args...>>
209 as_view_of_rank_n(View<Args...> v);
210 
211 // Placeholder implementation to compile generic code for DynRankView; should
212 // never be called
213 template <unsigned N, typename T, typename... Args>
214 std::enable_if_t<
215  N != View<T, Args...>::Rank &&
216  (std::is_same<typename ViewTraits<T, Args...>::specialize,
217  Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
218  std::is_same<typename ViewTraits<T, Args...>::specialize,
219  Kokkos::Impl::ViewSpecializeSacadoFadContiguous>::value),
220  View<typename RankDataType<typename View<T, Args...>::value_type, N>::type,
221  Args...>>
222 as_view_of_rank_n(View<T, Args...>);
223 
224 }
225 
226 namespace Experimental {
227 
228 template <class DT, class... DP>
229 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
230  const View<DT, DP...>& dst,
231  typename ViewTraits<DT, DP...>::const_value_type& value,
232  typename std::enable_if<(
233  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
234  Kokkos::Impl::ViewSpecializeSacadoFad >::value
235  ||
236  std::is_same< typename ViewTraits<DT,DP...>::specialize,
237  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
238  && (unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type* = nullptr);
239 
240 template <class DT, class... DP>
241 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
242  const View<DT, DP...>& dst,
243  typename ViewTraits<DT, DP...>::const_value_type& value,
244  typename std::enable_if<(
245  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
246  Kokkos::Impl::ViewSpecializeSacadoFad >::value
247  ||
248  std::is_same< typename ViewTraits<DT,DP...>::specialize,
249  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
250  && (unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type* = nullptr);
251 
252 template <class DT, class... DP>
253 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
254  const View<DT, DP...>& dst,
255  typename ViewTraits<DT, DP...>::const_value_type& value,
256  typename std::enable_if<(
257  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
258  Kokkos::Impl::ViewSpecializeSacadoFad >::value
259  ||
260  std::is_same< typename ViewTraits<DT,DP...>::specialize,
261  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
262  && (unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type* = nullptr);
263 
264 template <class DT, class... DP>
265 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
266  const View<DT, DP...>& dst,
267  typename ViewTraits<DT, DP...>::const_value_type& value,
268  typename std::enable_if<(
269  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
270  Kokkos::Impl::ViewSpecializeSacadoFad >::value
271  ||
272  std::is_same< typename ViewTraits<DT,DP...>::specialize,
273  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
274  && (unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type* = nullptr);
275 
276 template <class DT, class... DP>
277 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
278  const View<DT, DP...>& dst,
279  typename ViewTraits<DT, DP...>::const_value_type& value,
280  typename std::enable_if<(
281  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
282  Kokkos::Impl::ViewSpecializeSacadoFad >::value
283  ||
284  std::is_same< typename ViewTraits<DT,DP...>::specialize,
285  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
286  && (unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type* = nullptr);
287 
288 template <class DT, class... DP>
289 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
290  const View<DT, DP...>& dst,
291  typename ViewTraits<DT, DP...>::const_value_type& value,
292  typename std::enable_if<(
293  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
294  Kokkos::Impl::ViewSpecializeSacadoFad >::value
295  ||
296  std::is_same< typename ViewTraits<DT,DP...>::specialize,
297  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
298  && (unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type* = nullptr);
299 
300 template <class DT, class... DP>
301 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
302  const View<DT, DP...>& dst,
303  typename ViewTraits<DT, DP...>::const_value_type& value,
304  typename std::enable_if<(
305  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
306  Kokkos::Impl::ViewSpecializeSacadoFad >::value
307  ||
308  std::is_same< typename ViewTraits<DT,DP...>::specialize,
309  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
310  && (unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type* = nullptr);
311 
312 template <class TeamType, class DT, class... DP>
313 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
314  const TeamType& team, const View<DT, DP...>& dst,
315  typename ViewTraits<DT, DP...>::const_value_type& value,
316  typename std::enable_if<(
317  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
318  Kokkos::Impl::ViewSpecializeSacadoFad >::value
319  ||
320  std::is_same< typename ViewTraits<DT,DP...>::specialize,
321  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
322  && (unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type* = nullptr);
323 
324 template <class TeamType, class DT, class... DP>
325 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
326  const TeamType& team, const View<DT, DP...>& dst,
327  typename ViewTraits<DT, DP...>::const_value_type& value,
328  typename std::enable_if<(
329  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
330  Kokkos::Impl::ViewSpecializeSacadoFad >::value
331  ||
332  std::is_same< typename ViewTraits<DT,DP...>::specialize,
333  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
334  && (unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type* = nullptr);
335 
336 template <class TeamType, class DT, class... DP>
337 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
338  const TeamType& team, const View<DT, DP...>& dst,
339  typename ViewTraits<DT, DP...>::const_value_type& value,
340  typename std::enable_if<(
341  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
342  Kokkos::Impl::ViewSpecializeSacadoFad >::value
343  ||
344  std::is_same< typename ViewTraits<DT,DP...>::specialize,
345  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
346  && (unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type* = nullptr);
347 
348 template <class TeamType, class DT, class... DP>
349 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
350  const TeamType& team, const View<DT, DP...>& dst,
351  typename ViewTraits<DT, DP...>::const_value_type& value,
352  typename std::enable_if<(
353  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
354  Kokkos::Impl::ViewSpecializeSacadoFad >::value
355  ||
356  std::is_same< typename ViewTraits<DT,DP...>::specialize,
357  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
358  && (unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type* = nullptr);
359 
360 template <class TeamType, class DT, class... DP>
361 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
362  const TeamType& team, const View<DT, DP...>& dst,
363  typename ViewTraits<DT, DP...>::const_value_type& value,
364  typename std::enable_if<(
365  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
366  Kokkos::Impl::ViewSpecializeSacadoFad >::value
367  ||
368  std::is_same< typename ViewTraits<DT,DP...>::specialize,
369  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
370  && (unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type* = nullptr);
371 
372 template <class TeamType, class DT, class... DP>
373 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
374  const TeamType& team, const View<DT, DP...>& dst,
375  typename ViewTraits<DT, DP...>::const_value_type& value,
376  typename std::enable_if<(
377  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
378  Kokkos::Impl::ViewSpecializeSacadoFad >::value
379  ||
380  std::is_same< typename ViewTraits<DT,DP...>::specialize,
381  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
382  && (unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type* = nullptr);
383 
384 template <class TeamType, class DT, class... DP>
385 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
386  const TeamType& team, const View<DT, DP...>& dst,
387  typename ViewTraits<DT, DP...>::const_value_type& value,
388  typename std::enable_if<(
389  ( std::is_same< typename ViewTraits<DT,DP...>::specialize,
390  Kokkos::Impl::ViewSpecializeSacadoFad >::value
391  ||
392  std::is_same< typename ViewTraits<DT,DP...>::specialize,
393  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
394  && (unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type* = nullptr);
395 
396 }
397 
398 } // namespace Kokkos
399 
400 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
401 
402 #endif // defined(HAVE_SACADO_KOKKOS)
403 
404 #endif /* #ifndef KOKKOS_VIEW_FAD_FWD_HPP */
#define T
Definition: Sacado_rad.hpp:573
const int N
int value