Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fad_KokkosTests.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
30 
31 #include "Sacado.hpp"
33 
34 template <typename T>
35 struct is_sfad {
36  static const bool value = false;
37 };
38 
39 template <typename T, int N>
40 struct is_sfad< Sacado::Fad::SFad<T,N> > {
41  static const bool value = true;
42 };
43 
44 template <typename T>
45 struct is_dfad {
46  static const bool value = false;
47 };
48 
49 template <typename T>
50 struct is_dfad< Sacado::Fad::DFad<T> > {
51  static const bool value = true;
52 };
53 
54 template <typename FadType1, typename FadType2>
55 bool checkFads(const FadType1& x, const FadType2& x2,
56  Teuchos::FancyOStream& out, double tol = 1.0e-15)
57 {
58  bool success = true;
59 
60  // Check sizes match
61  TEUCHOS_TEST_EQUALITY(x.size(), x2.size(), out, success);
62 
63  // Check values match
64  TEUCHOS_TEST_FLOATING_EQUALITY(x.val(), x2.val(), tol, out, success);
65 
66  // Check derivatives match
67  for (int i=0; i<x.size(); ++i)
68  TEUCHOS_TEST_FLOATING_EQUALITY(x.dx(i), x2.dx(i), tol, out, success);
69 
70  return success;
71 }
72 
73 template <typename fadtype, typename ordinal>
74 inline
75 fadtype generate_fad( const ordinal num_rows,
76  const ordinal num_cols,
77  const ordinal fad_size,
78  const ordinal row,
79  const ordinal col )
80 {
81  typedef typename fadtype::value_type scalar;
82  fadtype x(fad_size, scalar(0.0));
83 
84  const scalar x_row = 100.0 + scalar(num_rows) / scalar(row+1);
85  const scalar x_col = 10.0 + scalar(num_cols) / scalar(col+1);
86  x.val() = x_row + x_col;
87  for (ordinal i=0; i<fad_size; ++i) {
88  const scalar x_fad = 1.0 + scalar(fad_size) / scalar(i+1);
89  x.fastAccessDx(i) = x_row + x_col + x_fad;
90  }
91  return x;
92 }
93 
94 #ifndef GLOBAL_FAD_SIZE
95 #define GLOBAL_FAD_SIZE 5
96 #endif
97 const int global_num_rows = 11;
98 const int global_num_cols = 7;
100 
101 // Kernel to multiply two views
102 template <typename InputViewType1,
103  typename InputViewType2 = InputViewType1,
104  typename OutputViewType = InputViewType1>
106  typedef typename InputViewType1::execution_space execution_space;
107  typedef typename InputViewType1::size_type size_type;
108  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
109  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
110  typedef typename team_policy_type::member_type team_handle;
111 
112  const InputViewType1 m_v1;
113  const InputViewType2 m_v2;
114  const OutputViewType m_v3;
115  const bool m_update;
116 
117  MultiplyKernel(const InputViewType1 v1,
118  const InputViewType2 v2,
119  const OutputViewType v3,
120  const bool update) :
121  m_v1(v1), m_v2(v2), m_v3(v3), m_update(update) {};
122 
123  // Multiply entries for row 'i' with a value
125  void operator() (const size_type i) const {
126  if (m_update)
127  m_v3(i) += m_v1(i)*m_v2(i);
128  else
129  m_v3(i) = m_v1(i)*m_v2(i);
130  }
131 
133  void operator()( const team_handle& team ) const
134  {
135  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
136  if (i < m_v1.extent(0))
137  (*this)(i);
138  }
139 
140  // Kernel launch
141  static void apply(const InputViewType1 v1,
142  const InputViewType2 v2,
143  const OutputViewType v3,
144  const bool update = false) {
145  const size_type nrow = v1.extent(0);
146 
147 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
148  const size_type stride = Kokkos::ViewScalarStride<InputViewType1>::stride;
149  const bool use_team =
150  std::is_same<execution_space, Kokkos::Cuda>::value &&
151  ( Kokkos::is_view_fad_contiguous<InputViewType1>::value ||
152  Kokkos::is_dynrankview_fad_contiguous<InputViewType1>::value ) &&
153  ( stride > 1 );
154 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
155  const size_type stride = 32;
156  const bool use_team =
157  std::is_same<execution_space, Kokkos::Cuda>::value &&
158  ( Kokkos::is_view_fad_contiguous<InputViewType1>::value ||
159  Kokkos::is_dynrankview_fad_contiguous<InputViewType1>::value ) &&
161 #else
162  const size_type stride = 1;
163  const bool use_team = false;
164 #endif
165 
166  if (use_team) {
167  const size_type team_size = 256 / stride;
168  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
169  Kokkos::parallel_for( policy, MultiplyKernel(v1,v2,v3,update) );
170  }
171  else {
172  range_policy_type policy( 0, nrow );
173  Kokkos::parallel_for( policy, MultiplyKernel(v1,v2,v3,update) );
174  }
175  }
176 };
177 
178 // Kernel to assign a constant to a view
179 template <typename ViewType>
181  typedef typename ViewType::execution_space execution_space;
182  typedef typename ViewType::size_type size_type;
183  typedef typename ViewType::value_type::value_type ScalarType;
184  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
185  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
186  typedef typename team_policy_type::member_type team_handle;
187  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
188 
189  const ViewType m_v;
191 
192  ScalarAssignKernel(const ViewType& v, const ScalarType& s) :
193  m_v(v), m_s(s) {};
194 
195  // Multiply entries for row 'i' with a value
197  void operator() (const size_type i) const {
198  m_v(i) = m_s;
199  }
200 
202  void operator()( const team_handle& team ) const
203  {
204  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
205  if (i < m_v.extent(0))
206  (*this)(i);
207  }
208 
209  // Kernel launch
210  static void apply(const ViewType& v, const ScalarType& s) {
211  const size_type nrow = v.extent(0);
212 
213 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
214  const bool use_team =
215  std::is_same<execution_space, Kokkos::Cuda>::value &&
216  ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
217  Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
218  ( stride > 1 );
219 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
220  const bool use_team =
221  std::is_same<execution_space, Kokkos::Cuda>::value &&
222  ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
223  Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
225 #else
226  const bool use_team = false;
227 #endif
228 
229  if (use_team) {
230  const size_type team_size = 256 / stride;
231  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
232  Kokkos::parallel_for( policy, ScalarAssignKernel(v,s) );
233  }
234  else {
235  range_policy_type policy( 0, nrow );
236  Kokkos::parallel_for( policy, ScalarAssignKernel(v,s) );
237  }
238  }
239 };
240 
241 // Kernel to assign a constant to a view
242 template <typename ViewType>
244  typedef typename ViewType::execution_space execution_space;
245  typedef typename ViewType::size_type size_type;
246  typedef typename ViewType::value_type ValueType;
247  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
248  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
249  typedef typename team_policy_type::member_type team_handle;
250  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_scalar_type;
251  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
252 
253  const ViewType m_v;
254  const ValueType m_s;
255 
256  ValueAssignKernel(const ViewType& v, const ValueType& s) :
257  m_v(v), m_s(s) {};
258 
259  // Multiply entries for row 'i' with a value
261  void operator() (const size_type i) const {
262  local_scalar_type s = Sacado::partition_scalar<stride>(m_s);
263  m_v(i) = s;
264  }
265 
267  void operator()( const team_handle& team ) const
268  {
269  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
270  if (i < m_v.extent(0))
271  (*this)(i);
272  }
273 
274  // Kernel launch
275  static void apply(const ViewType& v, const ValueType& s) {
276  const size_type nrow = v.extent(0);
277 
278 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
279  const bool use_team =
280  std::is_same<execution_space, Kokkos::Cuda>::value &&
281  ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
282  Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
283  ( stride > 1 );
284 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
285  const bool use_team =
286  std::is_same<execution_space, Kokkos::Cuda>::value &&
287  ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
288  Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
290 #else
291  const bool use_team = false;
292 #endif
293 
294  if (use_team) {
295  const size_type team_size = 256 / stride;
296  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
297  Kokkos::parallel_for( policy, ValueAssignKernel(v,s) );
298  }
299  else {
300  range_policy_type policy( 0, nrow );
301  Kokkos::parallel_for( policy, ValueAssignKernel(v,s) );
302  }
303  }
304 };
305 
306 // Kernel to assign a column of a rank-2 to a rank-1
307 template <typename InputViewType,
308  typename OutputViewType,
309  typename Enabled = void>
311  typedef typename InputViewType::execution_space execution_space;
312  typedef typename InputViewType::size_type size_type;
313  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
314  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
315  typedef typename team_policy_type::member_type team_handle;
316  static const size_type stride = Kokkos::ViewScalarStride<InputViewType>::stride;
317 
318  const InputViewType m_v1;
319  const OutputViewType m_v2;
321 
322  AssignRank2Rank1Kernel(const InputViewType v1,
323  const OutputViewType v2,
324  const size_type col) :
325  m_v1(v1), m_v2(v2), m_col(col) {
326  static_assert( unsigned(InputViewType::Rank) == 2 ,
327  "Require rank-2 input view" );
328  static_assert( unsigned(OutputViewType::Rank) == 1 ,
329  "Require rank-1 output view" );
330  };
331 
332  // Multiply entries for row 'i' with a value
334  void operator() (const size_type i) const {
335  m_v2(i) = m_v1(i,m_col);
336  }
337 
339  void operator()( const team_handle& team ) const
340  {
341  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
342  if (i < m_v1.extent(0))
343  (*this)(i);
344  }
345 
346  // Kernel launch
347  static void apply(const InputViewType v1,
348  const OutputViewType v2,
349  const size_type col) {
350  const size_type nrow = v1.extent(0);
351 
352 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
353  const bool use_team =
354  std::is_same<execution_space, Kokkos::Cuda>::value &&
355  ( Kokkos::is_view_fad_contiguous<InputViewType>::value ||
356  Kokkos::is_dynrankview_fad_contiguous<InputViewType>::value ) &&
357  ( stride > 1 );
358 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
359  const bool use_team =
360  std::is_same<execution_space, Kokkos::Cuda>::value &&
361  ( Kokkos::is_view_fad_contiguous<InputViewType>::value ||
362  Kokkos::is_dynrankview_fad_contiguous<InputViewType>::value ) &&
364 #else
365  const bool use_team = false;
366 #endif
367 
368  if (use_team) {
369  const size_type team_size = 256 / stride;
370  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
371  Kokkos::parallel_for( policy, AssignRank2Rank1Kernel(v1,v2,col) );
372  }
373  else {
374  range_policy_type policy( 0, nrow );
375  Kokkos::parallel_for( policy, AssignRank2Rank1Kernel(v1,v2,col) );
376  }
377  }
378 };
379 
380 // Kernel to test atomic_add
381 template <typename ViewType, typename ScalarViewType>
383  typedef typename ViewType::execution_space execution_space;
384  typedef typename ViewType::size_type size_type;
385  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
386  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
387  typedef typename team_policy_type::member_type team_handle;
388  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_scalar_type;
389  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
390 
391  const ViewType m_v;
392  const ScalarViewType m_s;
393 
394  AtomicAddKernel(const ViewType& v, const ScalarViewType& s) :
395  m_v(v), m_s(s) {};
396 
397  // Multiply entries for row 'i' with a value
399  void operator() (const size_type i) const {
400  local_scalar_type x = m_v(i);
401  Kokkos::atomic_add(&(m_s()), x);
402  }
403 
405  void operator()( const team_handle& team ) const
406  {
407  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
408  if (i < m_v.extent(0))
409  (*this)(i);
410  }
411 
412  // Kernel launch
413  static void apply(const ViewType& v, const ScalarViewType& s) {
414  const size_type nrow = v.extent(0);
415 
416 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
417  const bool use_team =
418  std::is_same<execution_space, Kokkos::Cuda>::value &&
419  ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
420  Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
421  ( stride > 1 );
422 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
423  const bool use_team =
424  std::is_same<execution_space, Kokkos::Cuda>::value &&
425  ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
426  Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
428 #else
429  const bool use_team = false;
430 #endif
431 
432  if (use_team) {
433  const size_type team_size = 256 / stride;
434  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
435  Kokkos::parallel_for( policy, AtomicAddKernel(v,s) );
436  }
437  else {
438  range_policy_type policy( 0, nrow );
439  Kokkos::parallel_for( policy, AtomicAddKernel(v,s) );
440  }
441  }
442 };
443 
445  Kokkos_View_Fad, Size, FadType, Layout, Device )
446 {
447  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
448  typedef typename ViewType::size_type size_type;
449 
450  const size_type num_rows = global_num_rows;
451 
452  // Create and fill view
453  ViewType v;
454 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
455  v = ViewType("view", num_rows);
456 #else
457  const size_type fad_size = global_fad_size;
458  v = ViewType("view", num_rows, fad_size+1);
459 #endif
460  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
461 }
462 
464  Kokkos_View_Fad, DeepCopy, FadType, Layout, Device )
465 {
466  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
467  typedef typename ViewType::size_type size_type;
468  typedef typename ViewType::HostMirror host_view_type;
469 
470  const size_type num_rows = global_num_rows;
471  const size_type num_cols = global_num_cols;
472  const size_type fad_size = global_fad_size;
473 
474  // Create and fill view
475  ViewType v;
476 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
477  v = ViewType ("view", num_rows, num_cols);
478 #else
479  v = ViewType ("view", num_rows, num_cols, fad_size+1);
480 #endif
481  host_view_type h_v = Kokkos::create_mirror_view(v);
482  for (size_type i=0; i<num_rows; ++i)
483  for (size_type j=0; j<num_cols; ++j)
484  h_v(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
485  Kokkos::deep_copy(v, h_v);
486 
487  // Copy back
488  host_view_type h_v2 = Kokkos::create_mirror_view(v);
489  Kokkos::deep_copy(h_v2, v);
490 
491  // Check
492  success = true;
493  for (size_type i=0; i<num_rows; ++i) {
494  for (size_type j=0; j<num_cols; ++j) {
495  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
496  success = success && checkFads(f, h_v2(i,j), out);
497  }
498  }
499 }
500 
502  Kokkos_View_Fad, DeepCopy_ConstantScalar, FadType, Layout, Device )
503 {
504  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
505  typedef typename ViewType::size_type size_type;
506  typedef typename ViewType::HostMirror host_view_type;
507  typedef typename FadType::value_type value_type;
508 
509  const size_type num_rows = global_num_rows;
510  const size_type num_cols = global_num_cols;
511 
512  // Create and fill view
513  ViewType v;
514 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
515  v = ViewType ("view", num_rows, num_cols);
516 #else
517  const size_type fad_size = global_fad_size;
518  v = ViewType ("view", num_rows, num_cols, fad_size+1);
519 #endif
520  typename ViewType::array_type va = v;
521  Kokkos::deep_copy( va, 1.0 );
522 
523  // Deep copy a constant scalar
524  value_type a = 2.3456;
525  Kokkos::deep_copy( v, a );
526 
527  // Copy to host
528  host_view_type hv = Kokkos::create_mirror_view(v);
529  Kokkos::deep_copy(hv, v);
530 
531  // Check
532  success = true;
533  for (size_type i=0; i<num_rows; ++i) {
534  for (size_type j=0; j<num_cols; ++j) {
535 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
536  FadType f = FadType(fad_size, a);
537 #else
538  FadType f = a;
539 #endif
540  success = success && checkFads(f, hv(i,j), out);
541  }
542  }
543 }
544 
546  Kokkos_View_Fad, DeepCopy_ConstantZero, FadType, Layout, Device )
547 {
548  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
549  typedef typename ViewType::size_type size_type;
550  typedef typename ViewType::HostMirror host_view_type;
551  typedef typename FadType::value_type value_type;
552 
553  const size_type num_rows = global_num_rows;
554  const size_type num_cols = global_num_cols;
555 
556  // Create and fill view
557  ViewType v;
558 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
559  v = ViewType ("view", num_rows, num_cols);
560 #else
561  const size_type fad_size = global_fad_size;
562  v = ViewType ("view", num_rows, num_cols, fad_size+1);
563 #endif
564  typename ViewType::array_type va = v;
565  Kokkos::deep_copy( va, 1.0 );
566 
567  // Deep copy a constant scalar
568  value_type a = 0.0;
569  Kokkos::deep_copy( v, a );
570 
571  // Copy to host
572  host_view_type hv = Kokkos::create_mirror_view(v);
573  Kokkos::deep_copy(hv, v);
574 
575  // Check
576  success = true;
577  for (size_type i=0; i<num_rows; ++i) {
578  for (size_type j=0; j<num_cols; ++j) {
579 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
580  FadType f = FadType(fad_size, a);
581 #else
582  FadType f = a;
583 #endif
584  success = success && checkFads(f, hv(i,j), out);
585  }
586  }
587 }
588 
590  Kokkos_View_Fad, DeepCopy_ConstantFad, FadType, Layout, Device )
591 {
592  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
593  typedef typename ViewType::size_type size_type;
594  typedef typename ViewType::HostMirror host_view_type;
595 
596  const size_type num_rows = global_num_rows;
597  const size_type num_cols = global_num_cols;
598 
599  // Create and fill view
600  ViewType v;
601 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
602  v = ViewType ("view", num_rows, num_cols);
603 #else
604  const size_type fad_size = global_fad_size;
605  v = ViewType ("view", num_rows, num_cols, fad_size+1);
606 #endif
607  typename ViewType::array_type va = v;
608  Kokkos::deep_copy( va, 1.0 );
609 
610  // Deep copy a constant scalar
611  FadType a = 2.3456;
612  Kokkos::deep_copy( v, a );
613 
614  // Copy to host
615  host_view_type hv = Kokkos::create_mirror_view(v);
616  Kokkos::deep_copy(hv, v);
617 
618  // Check
619  success = true;
620  for (size_type i=0; i<num_rows; ++i) {
621  for (size_type j=0; j<num_cols; ++j) {
622 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
623  FadType f = FadType(fad_size, a.val());
624 #else
625  FadType f = a;
626 #endif
627  success = success && checkFads(f, hv(i,j), out);
628  }
629  }
630 }
631 
633  Kokkos_View_Fad, DeepCopy_ConstantFadFull, FadType, Layout, Device )
634 {
635  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
636  typedef typename ViewType::size_type size_type;
637  typedef typename ViewType::HostMirror host_view_type;
638 
639  const size_type num_rows = global_num_rows;
640  const size_type num_cols = global_num_cols;
641  const size_type fad_size = global_fad_size;
642 
643  // Create and fill view
644  ViewType v;
645 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
646  v = ViewType ("view", num_rows, num_cols);
647 #else
648  v = ViewType ("view", num_rows, num_cols, fad_size+1);
649 #endif
650  typename ViewType::array_type va = v;
651  Kokkos::deep_copy( va, 1.0 );
652 
653  // Deep copy a constant Fad
654  FadType a(fad_size, 2.3456);
655  for (size_type i=0; i<fad_size; ++i)
656  a.fastAccessDx(i) = 7.89 + (i+1);
657  Kokkos::deep_copy( v, a );
658 
659  // Copy to host
660  host_view_type hv = Kokkos::create_mirror_view(v);
661  Kokkos::deep_copy(hv, v);
662 
663  // Check
664  success = true;
665  for (size_type i=0; i<num_rows; ++i) {
666  for (size_type j=0; j<num_cols; ++j) {
667  success = success && checkFads(a, hv(i,j), out);
668  }
669  }
670 }
671 
673  Kokkos_View_Fad, ScalarAssign, FadType, Layout, Device )
674 {
675  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
676  typedef typename ViewType::size_type size_type;
677  typedef typename ViewType::HostMirror host_view_type;
678  typedef typename FadType::value_type value_type;
679 
680  const size_type num_rows = global_num_rows;
681 
682  // Create and fill view
683  ViewType v;
684 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
685  v = ViewType ("view", num_rows);
686 #else
687  const size_type fad_size = global_fad_size;
688  v = ViewType ("view", num_rows, fad_size+1);
689 #endif
690  typename ViewType::array_type va = v;
691  Kokkos::deep_copy( va, 1.0 );
692 
693  // Deep copy a constant scalar
694  value_type a = 2.3456;
696 
697  // Copy to host
698  host_view_type hv = Kokkos::create_mirror_view(v);
699  Kokkos::deep_copy(hv, v);
700 
701  // Check
702  success = true;
703  for (size_type i=0; i<num_rows; ++i) {
704 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
705  FadType f = FadType(fad_size, a);
706 #else
707  FadType f = a;
708 #endif
709  success = success && checkFads(f, hv(i), out);
710  }
711 }
712 
714  Kokkos_View_Fad, ValueAssign, FadType, Layout, Device )
715 {
716  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
717  typedef typename ViewType::size_type size_type;
718  typedef typename ViewType::HostMirror host_view_type;
719 
720  const size_type num_rows = global_num_rows;
721  const size_type fad_size = global_fad_size;
722 
723  // Create and fill view
724  ViewType v;
725 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
726  v = ViewType ("view", num_rows);
727 #else
728  v = ViewType ("view", num_rows, fad_size+1);
729 #endif
730  typename ViewType::array_type va = v;
731  Kokkos::deep_copy( va, 1.0 );
732 
733  // Deep copy a constant scalar
734  FadType a(fad_size, 2.3456);
735  for (size_type i=0; i<fad_size; ++i)
736  a.fastAccessDx(i) = 7.89+i;
738 
739  // Copy to host
740  host_view_type hv = Kokkos::create_mirror_view(v);
741  Kokkos::deep_copy(hv, v);
742 
743  // Check
744  success = true;
745  for (size_type i=0; i<num_rows; ++i) {
746  success = success && checkFads(a, hv(i), out);
747  }
748 }
749 
751  Kokkos_View_Fad, Resize, FadType, Layout, Device )
752 {
753  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
754  typedef typename ViewType::size_type size_type;
755  typedef typename ViewType::HostMirror host_view_type;
756 
757  const size_type num_rows = global_num_rows;
758  const size_type num_cols = global_num_cols;
759  const size_type fad_size = global_fad_size;
760 
761  // Create and fill view
762  ViewType v;
763 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
764  v = ViewType ("view", num_rows, num_cols);
765 #else
766  v = ViewType ("view", num_rows, num_cols, fad_size+1);
767 #endif
768  host_view_type h_v = Kokkos::create_mirror_view(v);
769  for (size_type i=0; i<num_rows; ++i)
770  for (size_type j=0; j<num_cols; ++j)
771  h_v(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
772  Kokkos::deep_copy(v, h_v);
773 
774  // Resize
775 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
776  Kokkos::resize(v, num_rows, num_cols+1);
777 #else
778  Kokkos::resize(v, num_rows, num_cols+1, fad_size+1);
779 #endif
780 
781  // Copy back
782  host_view_type h_v2 = Kokkos::create_mirror_view(v);
783  Kokkos::deep_copy(h_v2, v);
784 
785  // Check
786  success = true;
787  for (size_type i=0; i<num_rows; ++i) {
788  for (size_type j=0; j<num_cols; ++j) {
789  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
790  success = success && checkFads(f, h_v2(i,j), out);
791  }
792 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
793  FadType f = 0.0;
794 #else
795  FadType f(fad_size, 0.0);
796 #endif
797  success = success && checkFads(f, h_v2(i,num_cols), out);
798  }
799 }
800 
802  Kokkos_View_Fad, Multiply, FadType, Layout, Device )
803 {
804  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
805  typedef typename ViewType::size_type size_type;
806  typedef typename ViewType::HostMirror host_view_type;
807 
808  const size_type num_rows = global_num_rows;
809  const size_type fad_size = global_fad_size;
810 
811  // Create and fill views
812  ViewType v1, v2;
813 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
814  v1 = ViewType ("view1", num_rows);
815  v2 = ViewType ("view2", num_rows);
816 #else
817  v1 = ViewType ("view1", num_rows, fad_size+1);
818  v2 = ViewType ("view2", num_rows, fad_size+1);
819 #endif
820  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
821  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
822  for (size_type i=0; i<num_rows; ++i) {
823  h_v1(i) = generate_fad<FadType>(
824  num_rows, size_type(2), fad_size, i, size_type(0));
825  h_v2(i) = generate_fad<FadType>(
826  num_rows, size_type(2), fad_size, i, size_type(1));
827  }
828  Kokkos::deep_copy(v1, h_v1);
829  Kokkos::deep_copy(v2, h_v2);
830 
831  // Launch kernel
832  ViewType v3;
833 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
834  v3 = ViewType ("view3", num_rows);
835 #else
836  v3 = ViewType ("view3", num_rows, fad_size+1);
837 #endif
839 
840  // Copy back
841  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
842  Kokkos::deep_copy(h_v3, v3);
843 
844  // Check
845  success = true;
846  for (size_type i=0; i<num_rows; ++i) {
847  FadType f1 =
848  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
849  FadType f2 =
850  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
851  FadType f3 = f1*f2;
852  success = success && checkFads(f3, h_v3(i), out);
853  }
854 }
855 
857  Kokkos_View_Fad, MultiplyUpdate, FadType, Layout, Device )
858 {
859  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
860  typedef typename ViewType::size_type size_type;
861  typedef typename ViewType::HostMirror host_view_type;
862 
863  const size_type num_rows = global_num_rows;
864  const size_type fad_size = global_fad_size;
865 
866  // Create and fill views
867  ViewType v1, v2;
868 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
869  v1 = ViewType ("view1", num_rows);
870  v2 = ViewType ("view2", num_rows);
871 #else
872  v1 = ViewType ("view1", num_rows, fad_size+1);
873  v2 = ViewType ("view2", num_rows, fad_size+1);
874 #endif
875  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
876  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
877  for (size_type i=0; i<num_rows; ++i) {
878  h_v1(i) = generate_fad<FadType>(
879  num_rows, size_type(2), fad_size, i, size_type(0));
880  h_v2(i) = generate_fad<FadType>(
881  num_rows, size_type(2), fad_size, i, size_type(1));
882  }
883  Kokkos::deep_copy(v1, h_v1);
884  Kokkos::deep_copy(v2, h_v2);
885 
886  // Launch kernel
887  ViewType v3;
888 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
889  v3 = ViewType ("view3", num_rows);
890 #else
891  v3 = ViewType ("view3", num_rows, fad_size+1);
892 #endif
893  Kokkos::deep_copy(v3, 1.0);
894  MultiplyKernel<ViewType>::apply(v1,v2,v3,true);
895 
896  // Copy back
897  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
898  Kokkos::deep_copy(h_v3, v3);
899 
900  // Check
901  success = true;
902  for (size_type i=0; i<num_rows; ++i) {
903  FadType f1 =
904  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
905  FadType f2 =
906  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
907  FadType f3 = 1.0 + f1*f2;
908  success = success && checkFads(f3, h_v3(i), out);
909  }
910 }
911 
913  Kokkos_View_Fad, MultiplyConst, FadType, Layout, Device )
914 {
915  typedef Kokkos::View<const FadType*,Layout,Device,Kokkos::MemoryUnmanaged> ConstViewType;
916  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
917  typedef typename ViewType::size_type size_type;
918  typedef typename ViewType::HostMirror host_view_type;
919 
920  const size_type num_rows = global_num_rows;
921  const size_type fad_size = global_fad_size;
922 
923  // Create and fill views
924  ViewType v1, v2;
925 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
926  v1 = ViewType ("view1", num_rows);
927  v2 = ViewType ("view2", num_rows);
928 #else
929  v1 = ViewType ("view1", num_rows, fad_size+1);
930  v2 = ViewType ("view2", num_rows, fad_size+1);
931 #endif
932  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
933  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
934  for (size_type i=0; i<num_rows; ++i) {
935  h_v1(i) = generate_fad<FadType>(
936  num_rows, size_type(2), fad_size, i, size_type(0));
937  h_v2(i) = generate_fad<FadType>(
938  num_rows, size_type(2), fad_size, i, size_type(1));
939  }
940  Kokkos::deep_copy(v1, h_v1);
941  Kokkos::deep_copy(v2, h_v2);
942 
943  ConstViewType cv1 = v1;
944 
945  // Launch kernel
946  ViewType v3;
947 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
948  v3 = ViewType ("view3", num_rows);
949 #else
950  v3 = ViewType ("view3", num_rows, fad_size+1);
951 #endif
953 
954  // Copy back
955  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
956  Kokkos::deep_copy(h_v3, v3);
957 
958  // Check
959  success = true;
960  for (size_type i=0; i<num_rows; ++i) {
961  FadType f1 =
962  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
963  FadType f2 =
964  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
965  FadType f3 = f1*f2;
966  success = success && checkFads(f3, h_v3(i), out);
967  }
968 }
969 
971  Kokkos_View_Fad, MultiplyMixed, FadType, Layout, Device )
972 {
973  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
974  typedef typename ViewType::size_type size_type;
975  typedef typename ViewType::HostMirror host_view_type;
976 
977  const size_type num_rows = 2;
978  const size_type fad_size = global_fad_size;
979 
980  // Create and fill views -- do everything on the host for this test
981  FadType f0 = generate_fad<FadType>(
982  num_rows, size_type(2), fad_size, size_type(0), size_type(0));
983  FadType f1 = generate_fad<FadType>(
984  num_rows, size_type(2), fad_size, size_type(1), size_type(0));
985  host_view_type h_v;
986 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
987  h_v = host_view_type ("view1", num_rows);
988 #else
989  h_v = host_view_type ("view1", num_rows, fad_size+1);
990 #endif
991  h_v(0) = f0;
992  h_v(1) = f1;
993 
994  FadType f2 = f0 * h_v(1);
995 
996  // Check
997  FadType f3 = f0 * f1;
998  success = checkFads(f3, f2, out);
999 }
1000 
1002  Kokkos_View_Fad, AtomicAdd, FadType, Layout, Device )
1003 {
1004  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1005  typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
1006  typedef typename ViewType::size_type size_type;
1007  typedef typename ScalarViewType::HostMirror host_scalar_view_type;
1008 
1009  const size_type num_rows = global_num_rows;
1010  const size_type fad_size = global_fad_size;
1011 
1012  // Create and fill view
1013  ViewType v;
1014 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1015  v = ViewType ("view", num_rows);
1016 #else
1017  v = ViewType ("view", num_rows, fad_size+1);
1018 #endif
1019  FadType a(fad_size, 2.3456);
1020  for (size_type i=0; i<fad_size; ++i)
1021  a.fastAccessDx(i) = 7.89+i;
1022  Kokkos::deep_copy( v, a );
1023 
1024  // Create scalar view
1025  ScalarViewType s;
1026 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1027  s = ScalarViewType ("scalar view");
1028 #else
1029  s = ScalarViewType ("scalar view", fad_size+1);
1030 #endif
1031  Kokkos::deep_copy( s, FadType(fad_size,0.0) );
1032 
1033  // Call atomic_add kernel, which adds up entries in v
1035 
1036  // Copy to host
1037  host_scalar_view_type hs = Kokkos::create_mirror_view(s);
1038  Kokkos::deep_copy(hs, s);
1039 
1040  // Check
1041  FadType b = num_rows*a;
1042  success = checkFads(b, hs(), out);
1043 }
1044 
1046  Kokkos_View_Fad, Rank8, FadType, Layout, Device )
1047 {
1048  typedef Kokkos::View<FadType*******,Layout,Device> ViewType;
1049  typedef typename ViewType::size_type size_type;
1050  typedef typename ViewType::HostMirror host_view_type;
1051 
1052  const size_type fad_size = global_fad_size;
1053 
1054  // Create and fill view
1055  ViewType v;
1056 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1057  v = ViewType ("view", 100, 1, 2, 3, 4, 5, 6);
1058 #else
1059  v = ViewType ("view", 100, 1, 2, 3, 4, 5, 6, fad_size+1);
1060 #endif
1061  host_view_type h_v = Kokkos::create_mirror_view(v);
1062  typename host_view_type::array_type h_a = h_v;
1063  Kokkos::deep_copy(h_a, 1.0);
1064 
1065  FadType f1 = FadType(fad_size, 2.0);
1066  h_v(99,0,1,2,3,4,5) = f1;
1067  FadType f2 = h_v(99,0,1,2,3,4,5);
1068 
1069  // Check
1070  success = checkFads(f1, f2, out);
1071 }
1072 
1074  Kokkos_View_Fad, Roger, FadType, Layout, Device )
1075 {
1076  Kokkos::View<FadType*,Layout,Device> a;
1077  Kokkos::View<FadType**,Layout,Device> b;
1078  Kokkos::View<FadType***,Layout,Device> c;
1079  Kokkos::View<FadType****,Layout,Device> d;
1080  Kokkos::View<FadType*****,Layout,Device> e;
1081  Kokkos::View<FadType******,Layout,Device> f;
1082  Kokkos::View<FadType*******,Layout,Device> g;
1083 
1084 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1085  a = Kokkos::View<FadType*,Layout,Device>("a",4);
1086  b = Kokkos::View<FadType**,Layout,Device> ("b",4,4);
1087  c = Kokkos::View<FadType***,Layout,Device> ("c",4,4,4);
1088  d = Kokkos::View<FadType****,Layout,Device> ("d",4,4,4,4);
1089  e = Kokkos::View<FadType*****,Layout,Device> ("e",4,4,4,4,4);
1090  f = Kokkos::View<FadType******,Layout,Device> ("f",4,4,4,4,4,4);
1091  g = Kokkos::View<FadType*******,Layout,Device> ("g",4,4,4,4,4,4,4);
1092 #else
1093  const unsigned fad_size = global_fad_size;
1094  a = Kokkos::View<FadType*,Layout,Device>("a",4,fad_size+1);
1095  b = Kokkos::View<FadType**,Layout,Device> ("b",4,4,fad_size+1);
1096  c = Kokkos::View<FadType***,Layout,Device> ("c",4,4,4,fad_size+1);
1097  d = Kokkos::View<FadType****,Layout,Device> ("d",4,4,4,4,fad_size+1);
1098  e = Kokkos::View<FadType*****,Layout,Device> ("e",4,4,4,4,4,fad_size+1);
1099  f = Kokkos::View<FadType******,Layout,Device> ("f",4,4,4,4,4,4,fad_size+1);
1100  g = Kokkos::View<FadType*******,Layout,Device> ("g",4,4,4,4,4,4,4,fad_size+1);
1101 #endif
1102 
1103  typedef typename Device::memory_space memory_space;
1104  const bool is_accessible =
1105  Kokkos::Impl::MemorySpaceAccess<Kokkos::HostSpace,
1106  memory_space>::accessible;
1107  if (is_accessible) {
1108  a(0) = FadType(1.0);
1109  f(0,0,0,0,0,0) = FadType(1.0);
1110  g(0,0,0,0,0,0,0) = FadType(1.0);
1111  }
1112 
1113  // Check
1114  success = true;
1115 }
1116 
1118  Kokkos_View_Fad, AssignDifferentStrides, FadType, Layout, Device )
1119 {
1120  typedef Kokkos::View<FadType**,Layout,Device> ViewType1;
1121  typedef Kokkos::View<FadType*,Layout,Device> ViewType2;
1122  typedef typename ViewType1::size_type size_type;
1123  typedef typename ViewType1::HostMirror host_view_type1;
1124  typedef typename ViewType2::HostMirror host_view_type2;
1125 
1126  const size_type num_rows = global_num_rows;
1127  const size_type num_cols = global_num_cols;
1128  const size_type fad_size = global_fad_size;
1129 
1130  // Create and fill views
1131  ViewType1 v1;
1132 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1133  v1 = ViewType1 ("view1", num_rows, num_cols);
1134 #else
1135  v1 = ViewType1 ("view1", num_rows, num_cols, fad_size+1);
1136 #endif
1137  host_view_type1 h_v1 = Kokkos::create_mirror_view(v1);
1138  for (size_type i=0; i<num_rows; ++i) {
1139  for (size_type j=0; j<num_cols; ++j) {
1140  h_v1(i,j) = generate_fad<FadType>(
1141  num_rows, num_cols, fad_size, i, j);
1142  }
1143  }
1144  Kokkos::deep_copy(v1, h_v1);
1145 
1146  // Launch kernel
1147  ViewType2 v2;
1148 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1149  v2 = ViewType2 ("view2", num_rows);
1150 #else
1151  v2 = ViewType2 ("view2", num_rows, fad_size+1);
1152 #endif
1154 
1155  // Copy back
1156  host_view_type2 h_v2 = Kokkos::create_mirror_view(v2);
1157  Kokkos::deep_copy(h_v2, v2);
1158 
1159  // Check
1160  success = true;
1161  for (size_type i=0; i<num_rows; ++i) {
1162  FadType f =
1163  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(1));
1164  success = success && checkFads(f, h_v2(i), out);
1165  }
1166 }
1167 
1168 #if defined(HAVE_SACADO_KOKKOSCONTAINERS) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1169 
1171  Kokkos_View_Fad, DynRankDimensionScalar, FadType, Layout, Device )
1172 {
1173  typedef Kokkos::DynRankView<double,Layout,Device> DoubleViewType;
1174  typedef Kokkos::DynRankView<FadType,Layout,Device> FadViewType;
1175  typedef typename FadViewType::size_type size_type;
1176 
1177  const size_type num_rows = global_num_rows;
1178  const size_type fad_size = global_fad_size;
1179 
1180  // Create views
1181  DoubleViewType v1("view1", num_rows);
1182  FadViewType v2 ("view2", num_rows, fad_size+1);
1183 
1184  // Check dimension scalar works
1185  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v1), 0, out, success);
1186  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1187 }
1188 
1190  Kokkos_View_Fad, DynRankAssignStatic0, FadType, Layout, Device )
1191 {
1192  typedef Kokkos::View<FadType,Layout,Device> StaticViewType;
1193  typedef Kokkos::DynRankView<FadType,Layout,Device> DynamicViewType;
1194  typedef typename StaticViewType::size_type size_type;
1195 
1196  const size_type num_rows = global_num_rows;
1197  const size_type num_cols = global_num_cols;
1198  const size_type fad_size = global_fad_size;
1199 
1200  // Create and fill views
1201  StaticViewType v1("view", fad_size+1);
1202  auto h_v1 = Kokkos::create_mirror_view(v1);
1203  h_v1() = generate_fad<FadType>(num_rows, num_cols, fad_size, size_type(0), size_type(0));
1204  Kokkos::deep_copy(v1, h_v1);
1205 
1206  // Assign static to dynamic
1207  DynamicViewType v2 = v1;
1208 
1209  // Copy back
1210  auto h_v2 = Kokkos::create_mirror_view(v2);
1211  Kokkos::deep_copy(h_v2, v2);
1212 
1213  // Check dimensions are correct
1214  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1215  TEUCHOS_TEST_EQUALITY(v2.stride_0(), v1.stride_0(), out, success);
1216 
1217  // Check values
1218  FadType f =
1219  generate_fad<FadType>(num_rows, num_cols, fad_size, size_type(0), size_type(0));
1220  success = success && checkFads(f, h_v2(), out);
1221 }
1222 
1224  Kokkos_View_Fad, DynRankAssignStatic1, FadType, Layout, Device )
1225 {
1226  typedef Kokkos::View<FadType*,Layout,Device> StaticViewType;
1227  typedef Kokkos::DynRankView<FadType,Layout,Device> DynamicViewType;
1228  typedef typename StaticViewType::size_type size_type;
1229 
1230  const size_type num_rows = global_num_rows;
1231  const size_type num_cols = global_num_cols;
1232  const size_type fad_size = global_fad_size;
1233 
1234  // Create and fill views
1235  StaticViewType v1("view", num_rows, fad_size+1);
1236  auto h_v1 = Kokkos::create_mirror_view(v1);
1237  for (size_type i=0; i<num_rows; ++i)
1238  h_v1(i) =
1239  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(0));
1240  Kokkos::deep_copy(v1, h_v1);
1241 
1242  // Assign static to dynamic
1243  DynamicViewType v2 = v1;
1244 
1245  // Copy back
1246  auto h_v2 = Kokkos::create_mirror_view(v2);
1247  Kokkos::deep_copy(h_v2, v2);
1248 
1249  // Check dimensions are correct
1250  TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
1251  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1252  TEUCHOS_TEST_EQUALITY(v2.stride_0(), v1.stride_0(), out, success);
1253  TEUCHOS_TEST_EQUALITY(v2.stride_1(), v1.stride_1(), out, success);
1254 
1255  // Check values
1256  for (size_type i=0; i<num_rows; ++i) {
1257  FadType f =
1258  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(0));
1259  success = success && checkFads(f, h_v2(i), out);
1260  }
1261 }
1262 
1264  Kokkos_View_Fad, DynRankAssignStatic2, FadType, Layout, Device )
1265 {
1266  typedef Kokkos::View<FadType**,Layout,Device> StaticViewType;
1267  typedef Kokkos::DynRankView<FadType,Layout,Device> DynamicViewType;
1268  typedef typename StaticViewType::size_type size_type;
1269 
1270  const size_type num_rows = global_num_rows;
1271  const size_type num_cols = global_num_cols;
1272  const size_type fad_size = global_fad_size;
1273 
1274  // Create and fill views
1275  StaticViewType v1("view", num_rows, num_cols, fad_size+1);
1276  auto h_v1 = Kokkos::create_mirror_view(v1);
1277  for (size_type i=0; i<num_rows; ++i)
1278  for (size_type j=0; j<num_cols; ++j)
1279  h_v1(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1280  Kokkos::deep_copy(v1, h_v1);
1281 
1282  // Assign static to dynamic
1283  DynamicViewType v2 = v1;
1284 
1285  // Copy back
1286  auto h_v2 = Kokkos::create_mirror_view(v2);
1287  Kokkos::deep_copy(h_v2, v2);
1288 
1289  // Check dimensions are correct
1290  TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
1291  TEUCHOS_TEST_EQUALITY(v2.extent(1), num_cols, out, success);
1292  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1293  TEUCHOS_TEST_EQUALITY(v2.stride_0(), v1.stride_0(), out, success);
1294  TEUCHOS_TEST_EQUALITY(v2.stride_1(), v1.stride_1(), out, success);
1295  TEUCHOS_TEST_EQUALITY(v2.stride_2(), v1.stride_2(), out, success);
1296 
1297  // Check values
1298  for (size_type i=0; i<num_rows; ++i) {
1299  for (size_type j=0; j<num_cols; ++j) {
1300  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1301  success = success && checkFads(f, h_v2(i,j), out);
1302  }
1303  }
1304 }
1305 
1307  Kokkos_View_Fad, DynRankMultiply, FadType, Layout, Device )
1308 {
1309  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1310  typedef typename ViewType::size_type size_type;
1311  typedef typename ViewType::HostMirror host_view_type;
1312 
1313  const size_type num_rows = global_num_rows;
1314  const size_type fad_size = global_fad_size;
1315 
1316  // Create and fill views
1317  ViewType v1("view1", num_rows, fad_size+1);
1318  ViewType v2("view2", num_rows, fad_size+1);
1319  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1320  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
1321  for (size_type i=0; i<num_rows; ++i) {
1322  h_v1(i) = generate_fad<FadType>(
1323  num_rows, size_type(2), fad_size, i, size_type(0));
1324  h_v2(i) = generate_fad<FadType>(
1325  num_rows, size_type(2), fad_size, i, size_type(1));
1326  }
1327  Kokkos::deep_copy(v1, h_v1);
1328  Kokkos::deep_copy(v2, h_v2);
1329 
1330  // Launch kernel
1331  ViewType v3("view3", num_rows, fad_size+1);
1333 
1334  // Copy back
1335  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
1336  Kokkos::deep_copy(h_v3, v3);
1337 
1338  // Check
1339  success = true;
1340  TEUCHOS_TEST_EQUALITY(v3.rank(), 1, out, success);
1341  for (size_type i=0; i<num_rows; ++i) {
1342  FadType f1 =
1343  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
1344  FadType f2 =
1345  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
1346  FadType f3 = f1*f2;
1347  success = success && checkFads(f3, h_v3(i), out);
1348  }
1349 }
1350 
1352  Kokkos_View_Fad, SubdynrankviewCol, FadType, Layout, Device )
1353 {
1354  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1355  typedef typename ViewType::size_type size_type;
1356  typedef typename ViewType::HostMirror host_view_type;
1357 
1358  const size_type num_rows = global_num_rows;
1359  const size_type num_cols = global_num_cols;
1360  const size_type fad_size = global_fad_size;
1361 
1362  // Create and fill view
1363  ViewType v("view", num_rows, num_cols, fad_size+1);
1364  host_view_type h_v = Kokkos::create_mirror_view(v);
1365  for (size_type i=0; i<num_rows; ++i) {
1366  for (size_type j=0; j<num_cols; ++j) {
1367  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1368  h_v(i,j) = f;
1369  }
1370  }
1371  Kokkos::deep_copy(v, h_v);
1372 
1373  // Create subview of first column
1374  size_type col = 1;
1375  auto s = Kokkos::subdynrankview(v, Kokkos::ALL(), col);
1376 
1377  // Copy back
1378  typedef decltype(s) SubviewType;
1379  typedef typename SubviewType::HostMirror HostSubviewType;
1380 
1381  // Note: don't create h_s through create_mirror_view and deep_copy
1382  // since Kokkos doesn't support deep_copy of non-contiguous views
1383  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1384  //Kokkos::deep_copy(h_s, s);
1385  HostSubviewType h_s = Kokkos::subdynrankview(h_v, Kokkos::ALL(), col);
1386 
1387  // Check
1388  success = true;
1389  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1390  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1391  TEUCHOS_TEST_EQUALITY(h_s.extent(0), num_rows, out, success);
1392  TEUCHOS_TEST_EQUALITY(h_s.extent(1), 1, out, success);
1393  TEUCHOS_TEST_EQUALITY(h_s.extent(7), 1, out, success);
1394 
1395  for (size_type i=0; i<num_rows; ++i) {
1396  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
1397  success = success && checkFads(f, h_s(i), out);
1398  }
1399 }
1400 
1402  Kokkos_View_Fad, SubdynrankviewRow, FadType, Layout, Device )
1403 {
1404  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1405  typedef typename ViewType::size_type size_type;
1406  typedef typename ViewType::HostMirror host_view_type;
1407 
1408  const size_type num_rows = global_num_rows;
1409  const size_type num_cols = global_num_cols;
1410  const size_type num_planes = 9;
1411  const size_type fad_size = global_fad_size;
1412 
1413  // Create and fill view
1414  ViewType v("view", num_rows, num_cols, num_planes, fad_size+1);
1415  host_view_type h_v = Kokkos::create_mirror_view(v);
1416  for (size_type i=0; i<num_rows; ++i) {
1417  for (size_type j=0; j<num_cols; ++j) {
1418  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1419  for (size_type k=0; k<num_planes; ++k) {
1420  h_v(i,j,k) = (k+1)*f;
1421  }
1422  }
1423  }
1424  Kokkos::deep_copy(v, h_v);
1425 
1426  // Create subview of first column
1427  size_type row = 2;
1428  auto s = Kokkos::subdynrankview(v, row, Kokkos::ALL(), Kokkos::ALL());
1429 
1430  // Copy back
1431  typedef decltype(s) SubviewType;
1432  typedef typename SubviewType::HostMirror HostSubviewType;
1433 
1434  // Note: don't create h_s through create_mirror_view and deep_copy
1435  // since Kokkos doesn't support deep_copy of non-contiguous views
1436  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1437  //Kokkos::deep_copy(h_s, s);
1438  HostSubviewType h_s =
1439  Kokkos::subdynrankview(h_v, row, Kokkos::ALL(), Kokkos::ALL());
1440 
1441  // Check
1442  success = true;
1443  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1444  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1445  TEUCHOS_TEST_EQUALITY(h_s.extent(0), num_cols, out, success);
1446  TEUCHOS_TEST_EQUALITY(h_s.extent(1), num_planes, out, success);
1447  TEUCHOS_TEST_EQUALITY(h_s.extent(2), 1, out, success);
1448  TEUCHOS_TEST_EQUALITY(h_s.extent(7), 1, out, success);
1449 
1450  for (size_type j=0; j<num_cols; ++j) {
1451  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, row, j);
1452  for (size_type k=0; k<num_planes; ++k) {
1453  FadType g = (k+1)*f;
1454  success = success && checkFads(g, h_s(j,k), out);
1455  }
1456  }
1457 }
1458 
1460  Kokkos_View_Fad, SubdynrankviewScalar, FadType, Layout, Device )
1461 {
1462  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1463  typedef typename ViewType::size_type size_type;
1464  typedef typename ViewType::HostMirror host_view_type;
1465 
1466  const size_type num_rows = global_num_rows;
1467  const size_type num_cols = global_num_cols;
1468  const size_type fad_size = global_fad_size;
1469 
1470  // Create and fill view
1471  ViewType v("view", num_rows, num_cols, fad_size+1);
1472  host_view_type h_v = Kokkos::create_mirror_view(v);
1473  for (size_type i=0; i<num_rows; ++i) {
1474  for (size_type j=0; j<num_cols; ++j) {
1475  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1476  h_v(i,j) = f;
1477  }
1478  }
1479  Kokkos::deep_copy(v, h_v);
1480 
1481  // Create subview of first column
1482  size_type row = 3;
1483  size_type col = 1;
1484  auto s = Kokkos::subdynrankview(v, row, col);
1485 
1486  // Copy back
1487  typedef decltype(s) SubviewType;
1488  typedef typename SubviewType::HostMirror HostSubviewType;
1489 
1490  // Note: don't create h_s through create_mirror_view and deep_copy
1491  // since Kokkos doesn't support deep_copy of non-contiguous views
1492  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1493  //Kokkos::deep_copy(h_s, s);
1494  HostSubviewType h_s = Kokkos::subdynrankview(h_v, row, col);
1495 
1496  // Check
1497  success = true;
1498  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1499  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1500  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, row, col);
1501  success = success && checkFads(f, h_s(), out);
1502 }
1503 
1504 #else
1505 
1507  Kokkos_View_Fad, DynRankDimensionScalar, FadType, Layout, Device ) {}
1509  Kokkos_View_Fad, DynRankAssignStatic0, FadType, Layout, Device ) {}
1511  Kokkos_View_Fad, DynRankAssignStatic1, FadType, Layout, Device ) {}
1513  Kokkos_View_Fad, DynRankAssignStatic2, FadType, Layout, Device ) {}
1515  Kokkos_View_Fad, DynRankMultiply, FadType, Layout, Device ) {}
1517  Kokkos_View_Fad, SubdynrankviewCol, FadType, Layout, Device ) {}
1519  Kokkos_View_Fad, SubdynrankviewRow, FadType, Layout, Device ) {}
1521  Kokkos_View_Fad, SubdynrankviewScalar, FadType, Layout, Device ) {}
1522 
1523 #endif
1524 
1526  Kokkos_View_Fad, Subview, FadType, Layout, Device )
1527 {
1528  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1529  typedef typename ViewType::size_type size_type;
1530  typedef typename ViewType::HostMirror host_view_type;
1531 
1532  const size_type num_rows = global_num_rows;
1533  const size_type num_cols = global_num_cols;
1534  const size_type fad_size = global_fad_size;
1535 
1536  // Create and fill view
1537  ViewType v;
1538 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1539  v = ViewType ("view", num_rows, num_cols);
1540 #else
1541  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1542 #endif
1543  host_view_type h_v = Kokkos::create_mirror_view(v);
1544  for (size_type i=0; i<num_rows; ++i) {
1545  for (size_type j=0; j<num_cols; ++j) {
1546  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1547  h_v(i,j) = f;
1548  }
1549  }
1550  Kokkos::deep_copy(v, h_v);
1551 
1552  // Create subview of first column
1553  size_type col = 1;
1554  auto s = Kokkos::subview(v, Kokkos::ALL(), col);
1555 
1556  // Copy back
1557  typedef decltype(s) SubviewType;
1558  typedef typename SubviewType::HostMirror HostSubviewType;
1559 
1560  // Note: don't create h_s through create_mirror_view and deep_copy
1561  // since Kokkos doesn't support deep_copy of non-contiguous views
1562  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1563  //Kokkos::deep_copy(h_s, s);
1564  HostSubviewType h_s = Kokkos::subview(h_v, Kokkos::ALL(), col);
1565 
1566  // Check
1567  success = true;
1568 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1569  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1570  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1571 #endif
1572  for (size_type i=0; i<num_rows; ++i) {
1573  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
1574  success = success && checkFads(f, h_s(i), out);
1575  }
1576 }
1577 
1578 // Tests that require view spec
1579 
1580 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1582  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
1583 {
1584  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1585  typedef typename FadType::value_type value_type;
1586  typedef typename ViewType::size_type size_type;
1587 
1588  const size_type num_rows = global_num_rows;
1589  const size_type num_cols = global_num_cols;
1590  const size_type fad_size = global_fad_size;
1591 
1592  // Compute shared memory size for View
1593  const size_type shmem_size =
1594  ViewType::shmem_size(num_rows, num_cols, fad_size+1);
1595 
1596  // Check
1597  const size_type align = 8;
1598  const size_type mask = align - 1;
1599  ViewType v;
1600 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1601  v = ViewType ("view", num_rows, num_cols);
1602 #else
1603  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1604 #endif
1605  const size_type shmem_size_expected =
1606  (( sizeof(value_type) * global_num_rows * global_num_cols * (fad_size+1) + mask ) & ~mask) + sizeof(typename ViewType::traits::value_type);
1607  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
1608 }
1609 
1611  Kokkos_View_Fad, Unmanaged, FadType, Layout, Device )
1612 {
1613  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
1614  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
1615 
1616  typedef typename FadType::value_type scalar_type;
1617  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
1618  typedef Kokkos::View<FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> FadViewType;
1619  typedef typename ViewType::size_type size_type;
1620  typedef typename ViewType::HostMirror host_view_type;
1621  typedef typename FadViewType::HostMirror fad_host_view_type;
1622 
1623  const size_type num_rows = global_num_rows;
1624  const size_type num_cols = global_num_cols;
1625  const size_type fad_size = global_fad_size;
1626 
1627  // Create and fill view
1628  ViewType v;
1629  host_view_type h_v;
1630  if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
1631  std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
1632  v = ViewType ("view", fad_size+1, num_rows, num_cols);
1633  h_v = Kokkos::create_mirror_view(v);
1634  for (size_type i=0; i<num_rows; ++i) {
1635  for (size_type j=0; j<num_cols; ++j) {
1636  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1637  for (size_type k=0; k<fad_size; k++)
1638  h_v(k,i,j) = f.dx(k);
1639  h_v(fad_size,i,j) = f.val();
1640  }
1641  }
1642  }
1643  else {
1644  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1645  h_v = Kokkos::create_mirror_view(v);
1646  for (size_type i=0; i<num_rows; ++i) {
1647  for (size_type j=0; j<num_cols; ++j) {
1648  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1649  for (size_type k=0; k<fad_size; k++)
1650  h_v(i,j,k) = f.dx(k);
1651  h_v(i,j,fad_size) = f.val();
1652  }
1653  }
1654  }
1655  Kokkos::deep_copy(v, h_v);
1656 
1657  // Create unmanaged view
1658  FadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
1659  fad_host_view_type h_v_fad;
1660 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1661  v_fad = FadViewType ( v.data(), num_rows, num_cols);
1662  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
1663 #else
1664  v_fad = FadViewType ( v.data(), num_rows, num_cols, fad_size+1);
1665  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
1666 #endif
1667 
1668  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1669  Kokkos::deep_copy(h_v_fad, v_fad);
1670 
1671  // Check
1672  success = true;
1673  for (size_type i=0; i<num_rows; ++i) {
1674  for (size_type j=0; j<num_cols; ++j) {
1675  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1676  success = success && checkFads(f, h_v_fad(i,j), out);
1677  }
1678  }
1679 }
1680 
1682  Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device )
1683 {
1684  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
1685  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
1686 
1687  typedef typename FadType::value_type scalar_type;
1688  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
1689  typedef Kokkos::View<FadType**,TestLayout,Device> FadViewType;
1690  typedef typename ViewType::size_type size_type;
1691  typedef typename ViewType::HostMirror host_view_type;
1692  typedef typename FadViewType::HostMirror fad_host_view_type;
1693 
1694  const size_type num_rows = global_num_rows;
1695  const size_type num_cols = global_num_cols;
1696  const size_type fad_size = global_fad_size;
1697 
1698  // Create and fill view
1699  ViewType v;
1700  host_view_type h_v;
1701  if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
1702  std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
1703  v = ViewType ("view", fad_size+1, num_rows, num_cols);
1704  h_v = Kokkos::create_mirror_view(v);
1705  for (size_type i=0; i<num_rows; ++i) {
1706  for (size_type j=0; j<num_cols; ++j) {
1707  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1708  for (size_type k=0; k<fad_size; k++)
1709  h_v(k,i,j) = f.dx(k);
1710  h_v(fad_size,i,j) = f.val();
1711  }
1712  }
1713  }
1714  else {
1715  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1716  h_v = Kokkos::create_mirror_view(v);
1717  for (size_type i=0; i<num_rows; ++i) {
1718  for (size_type j=0; j<num_cols; ++j) {
1719  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1720  for (size_type k=0; k<fad_size; k++)
1721  h_v(i,j,k) = f.dx(k);
1722  h_v(i,j,fad_size) = f.val();
1723  }
1724  }
1725  }
1726  Kokkos::deep_copy(v, h_v);
1727 
1728  // Create unmanaged view
1729  FadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
1730  fad_host_view_type h_v_fad;
1731 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1732  v_fad = FadViewType ( v.data(), num_rows, num_cols);
1733  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
1734 #else
1735  v_fad = FadViewType ( v.data(), num_rows, num_cols, fad_size+1);
1736  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
1737 #endif
1738 
1739  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1740  Kokkos::deep_copy(h_v_fad, v_fad);
1741 
1742  // Check
1743  success = true;
1744  for (size_type i=0; i<num_rows; ++i) {
1745  for (size_type j=0; j<num_cols; ++j) {
1746  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1747  success = success && checkFads(f, h_v_fad(i,j), out);
1748  }
1749  }
1750 }
1751 
1753  Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device )
1754 {
1755  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
1756  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
1757 
1758  typedef typename FadType::value_type scalar_type;
1759  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
1760  typedef Kokkos::View<const scalar_type***,TestLayout,Device> ConstViewType;
1761  typedef Kokkos::View<FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> FadViewType;
1762  typedef Kokkos::View<const FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> ConstFadViewType;
1763  typedef typename ViewType::size_type size_type;
1764  typedef typename ViewType::HostMirror host_view_type;
1765  typedef typename FadViewType::HostMirror fad_host_view_type;
1766 
1767  const size_type num_rows = global_num_rows;
1768  const size_type num_cols = global_num_cols;
1769  const size_type fad_size = global_fad_size;
1770 
1771  // Create and fill view
1772  ViewType v;
1773  host_view_type h_v;
1774  if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
1775  std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
1776  v = ViewType ("view", fad_size+1, num_rows, num_cols);
1777  h_v = Kokkos::create_mirror_view(v);
1778  for (size_type i=0; i<num_rows; ++i) {
1779  for (size_type j=0; j<num_cols; ++j) {
1780  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1781  for (size_type k=0; k<fad_size; k++)
1782  h_v(k,i,j) = f.dx(k);
1783  h_v(fad_size,i,j) = f.val();
1784  }
1785  }
1786  }
1787  else {
1788  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1789  h_v = Kokkos::create_mirror_view(v);
1790  for (size_type i=0; i<num_rows; ++i) {
1791  for (size_type j=0; j<num_cols; ++j) {
1792  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1793  for (size_type k=0; k<fad_size; k++)
1794  h_v(i,j,k) = f.dx(k);
1795  h_v(i,j,fad_size) = f.val();
1796  }
1797  }
1798  }
1799  Kokkos::deep_copy(v, h_v);
1800  ConstViewType v_const = v;
1801 
1802  // Create unmanaged view
1803 
1804  ConstFadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
1805  fad_host_view_type h_v_fad;
1806 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1807  v_fad = ConstFadViewType ( v_const.data(), num_rows, num_cols);
1808  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
1809 #else
1810  v_fad = ConstFadViewType ( v_const.data(), num_rows, num_cols, fad_size+1);
1811  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
1812 #endif
1813 
1814  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1815  Kokkos::deep_copy(h_v_fad, v_fad);
1816 
1817  // Check
1818  success = true;
1819  for (size_type i=0; i<num_rows; ++i) {
1820  for (size_type j=0; j<num_cols; ++j) {
1821  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1822  success = success && checkFads(f, h_v_fad(i,j), out);
1823  }
1824  }
1825 }
1826 
1828  Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device )
1829 {
1830  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
1831  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
1832  typedef typename FadType::value_type scalar_type;
1833  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
1834  typedef Kokkos::View<const scalar_type***,TestLayout,Device> ConstViewType;
1835  typedef Kokkos::View<FadType**,TestLayout,Device> FadViewType;
1836  typedef Kokkos::View<const FadType**,TestLayout,Device> ConstFadViewType;
1837  typedef typename ViewType::size_type size_type;
1838  typedef typename ViewType::HostMirror host_view_type;
1839  typedef typename FadViewType::HostMirror fad_host_view_type;
1840 
1841  const size_type num_rows = global_num_rows;
1842  const size_type num_cols = global_num_cols;
1843  const size_type fad_size = global_fad_size;
1844 
1845  // Create and fill view
1846  ViewType v;
1847  host_view_type h_v;
1848  if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
1849  std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
1850  v = ViewType ("view", fad_size+1, num_rows, num_cols);
1851  h_v = Kokkos::create_mirror_view(v);
1852  for (size_type i=0; i<num_rows; ++i) {
1853  for (size_type j=0; j<num_cols; ++j) {
1854  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1855  for (size_type k=0; k<fad_size; k++)
1856  h_v(k,i,j) = f.dx(k);
1857  h_v(fad_size,i,j) = f.val();
1858  }
1859  }
1860  }
1861  else {
1862  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1863  h_v = Kokkos::create_mirror_view(v);
1864  for (size_type i=0; i<num_rows; ++i) {
1865  for (size_type j=0; j<num_cols; ++j) {
1866  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1867  for (size_type k=0; k<fad_size; k++)
1868  h_v(i,j,k) = f.dx(k);
1869  h_v(i,j,fad_size) = f.val();
1870  }
1871  }
1872  }
1873  Kokkos::deep_copy(v, h_v);
1874  ConstViewType v_const = v;
1875 
1876  // Create unmanaged view
1877  ConstFadViewType v_fad;
1878  fad_host_view_type h_v_fad;
1879 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1880  v_fad = ConstFadViewType (v_const.data(), num_rows, num_cols);
1881  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
1882 #else
1883  v_fad = ConstFadViewType (v_const.data(), num_rows, num_cols, fad_size+1);
1884  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
1885 #endif
1886 
1887  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1888  Kokkos::deep_copy(h_v_fad, v_fad);
1889 
1890  // Check
1891  success = true;
1892  for (size_type i=0; i<num_rows; ++i) {
1893  for (size_type j=0; j<num_cols; ++j) {
1894  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1895  success = success && checkFads(f, h_v_fad(i,j), out);
1896  }
1897  }
1898 }
1899 
1900 // This test checks we can allocate a view
1901 // with SFad without specifying the fad size in the constructor
1903  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device )
1904 {
1905  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1906  typedef typename ViewType::size_type size_type;
1907  typedef typename ViewType::HostMirror host_view_type;
1908 
1909  const size_type num_rows = global_num_rows;
1910  const size_type num_cols = global_num_cols;
1911  const size_type fad_size = global_fad_size;
1912 
1913  // Create and fill view
1914  ViewType v("view", num_rows, num_cols);
1915  host_view_type h_v = Kokkos::create_mirror_view(v);
1916  for (size_type i=0; i<num_rows; ++i) {
1917  for (size_type j=0; j<num_cols; ++j) {
1918  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1919  h_v(i,j) = f;
1920  }
1921  }
1922  Kokkos::deep_copy(v, h_v);
1923 
1924  // Copy back
1925  Kokkos::deep_copy(h_v, v);
1926 
1927  // Check
1928  success = true;
1929  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v), fad_size+1, out, success);
1930  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v), fad_size+1, out, success);
1931  for (size_type i=0; i<num_rows; ++i) {
1932  for (size_type j=0; j<num_cols; ++j) {
1933  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1934  success = success && checkFads(f, h_v(i,j), out);
1935  }
1936  }
1937 }
1938 
1940  Kokkos_View_Fad, Partition, FadType, Layout, Device )
1941 {
1942 #if !defined(SACADO_VIEW_CUDA_HIERARCHICAL) && !defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
1943  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1944  typedef typename ViewType::size_type size_type;
1945  typedef typename ViewType::HostMirror host_view_type;
1946 
1947  const size_type num_rows = global_num_rows;
1948  const size_type num_cols = global_num_cols;
1949  const size_type fad_size = global_fad_size;
1950 
1951  // Create and fill view
1952  ViewType v;
1953 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1954  v = ViewType ("view", num_rows, num_cols);
1955 #else
1956  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1957 #endif
1958  host_view_type h_v = Kokkos::create_mirror_view(v);
1959 
1960  for (size_type i=0; i<num_rows; ++i) {
1961  for (size_type j=0; j<num_cols; ++j) {
1962  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1963  h_v(i,j) = f;
1964  }
1965  }
1966  Kokkos::deep_copy(v, h_v);
1967 
1968  // Copy back
1969  Kokkos::deep_copy(h_v, v);
1970 
1971  // Partition derivative array of h_v into 2, first one starting at index 0,
1972  // the second at 1
1973  const size_type stride = 2;
1974  auto h_v1 = Kokkos::partition<2>(h_v, 0, stride);
1975  auto h_v2 = Kokkos::partition<2>(h_v, 1, stride);
1976 
1977  // Check
1978  const size_type fad_size_1 = (fad_size + stride - 0 - 1) / stride;
1979  const size_type fad_size_2 = (fad_size + stride - 1 - 1) / stride;
1980  success = true;
1981  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v1), fad_size_1+1, out, success);
1982  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v2), fad_size_2+1, out, success);
1983  for (size_type i=0; i<num_rows; ++i) {
1984  for (size_type j=0; j<num_cols; ++j) {
1985  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1986  Sacado::Fad::DFad<double> f1( fad_size_1, f.val() );
1987  Sacado::Fad::DFad<double> f2( fad_size_2, f.val() );
1988  for (unsigned int k=0; k<fad_size_1; ++k)
1989  if (2*k < fad_size) f1.fastAccessDx(k) = f.dx(2*k);
1990  for (unsigned int k=0; k<fad_size_2; ++k)
1991  if (2*k+1 < fad_size) f2.fastAccessDx(k) = f.dx(2*k+1);
1992  success = success && checkFads(f1, h_v1(i,j), out);
1993  success = success && checkFads(f2, h_v2(i,j), out);
1994  }
1995  }
1996 #endif
1997 }
1998 
2000  Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, FadType, Layout, Device )
2001 {
2002  typedef Kokkos::View<FadType**,Kokkos::LayoutContiguous<Layout>,Device> ContViewType;
2003  typedef Kokkos::View<FadType**,Kokkos::LayoutStride,Device> StrideViewType;
2004  typedef typename ContViewType::size_type size_type;
2005  typedef typename ContViewType::HostMirror cont_host_view_type;
2006  typedef typename StrideViewType::HostMirror stride_host_view_type;
2007 
2008  const size_type num_rows = global_num_rows;
2009  const size_type num_cols = global_num_cols;
2010  const size_type fad_size = global_fad_size;
2011 
2012  // Create and fill view
2013  ContViewType v;
2014 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2015  v = ContViewType ("view", num_rows, num_cols);
2016 #else
2017  v = ContViewType ("view", num_rows, num_cols, fad_size+1);
2018 #endif
2019  cont_host_view_type h_v = Kokkos::create_mirror_view(v);
2020 
2021  for (size_type i=0; i<num_rows; ++i) {
2022  for (size_type j=0; j<num_cols; ++j) {
2023  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2024  h_v(i,j) = f;
2025  }
2026  }
2027  Kokkos::deep_copy(v, h_v);
2028 
2029  // Assign to LayoutStride view
2030  StrideViewType vs = v;
2031 
2032  // Copy back
2033  // Note: don't create h_vs through create_mirror_view and deep_copy
2034  // since Kokkos doesn't support deep_copy of non-contiguous views
2035  //stride_host_view_type h_vs = Kokkos::create_mirror_view(vs);
2036  //Kokkos::deep_copy(h_vs, vs);
2037  stride_host_view_type h_vs = h_v;
2038 
2039  // Check
2040  success = true;
2041  TEUCHOS_TEST_EQUALITY(h_vs.extent(0), num_rows, out, success);
2042  TEUCHOS_TEST_EQUALITY(h_vs.extent(1), num_cols, out, success);
2043  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_vs), fad_size+1, out, success);
2044  for (size_type i=0; i<num_rows; ++i) {
2045  for (size_type j=0; j<num_cols; ++j) {
2046  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2047  success = success && checkFads(f, h_vs(i,j), out);
2048  }
2049  }
2050 }
2051 
2053  Kokkos_View_Fad, CommonViewAllocMixedSpec, FadType, Layout, Device )
2054 {
2055  typedef Kokkos::View<FadType**,Kokkos::LayoutContiguous<Layout>,Device> ContViewType;
2056  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2057  typedef typename ContViewType::size_type size_type;
2058 
2059  const size_type num_rows = global_num_rows;
2060  const size_type num_cols = global_num_cols;
2061  const size_type fad_size = global_fad_size;
2062 
2063  // Create contiguous view
2064  ContViewType v1;
2065 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2066  v1 = ContViewType ("view", num_rows, num_cols);
2067 #else
2068  v1 = ContViewType ("view", num_rows, num_cols, fad_size+1);
2069 #endif
2070 
2071  // Create non-contiguous view using commen_view_alloc_prop
2072  auto cprop = Kokkos::common_view_alloc_prop(v1);
2073  ViewType v2(Kokkos::view_alloc("v2",cprop), num_rows, num_cols);
2074 
2075  // Check dimensions are correct for v2
2076  success = true;
2077  TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
2078  TEUCHOS_TEST_EQUALITY(v2.extent(1), num_cols, out, success);
2079  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
2080 }
2081 
2082 #else
2083 
2085  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
2086 {
2087  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2088  typedef typename ViewType::size_type size_type;
2089 
2090  const size_type num_rows = global_num_rows;
2091  const size_type num_cols = global_num_cols;
2092 
2093  // Compute shared memory size for View
2094  const size_type shmem_size =
2095  ViewType::shmem_size(num_rows, num_cols);
2096 
2097  // Check
2098  static const size_type align = 8;
2099  static const size_type mask = align - 1;
2100  const size_type shmem_size_expected =
2101  (( sizeof(FadType) * global_num_rows * global_num_cols + mask ) & ~mask) + sizeof(typename ViewType::traits::value_type);
2102  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
2103 }
2104 
2106  Kokkos_View_Fad, Unmanaged, FadType, Layout, Device ) {}
2107 
2109  Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device ) {}
2110 
2112  Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device ) {}
2113 
2115  Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device ) {}
2116 
2118  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device ) {}
2119 
2121  Kokkos_View_Fad, Partition, FadType, Layout, Device ) {}
2122 
2124  Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, FadType, Layout, Device ) {}
2125 
2127  Kokkos_View_Fad, CommonViewAllocMixedSpec, FadType, Layout, Device ) {}
2128 
2129 #endif
2130 
2131 #define VIEW_FAD_TESTS_FLD( F, L, D ) \
2132  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Size, F, L, D ) \
2133  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy, F, L, D ) \
2134  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantScalar, F, L, D ) \
2135  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantZero, F, L, D ) \
2136  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFad, F, L, D ) \
2137  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFadFull, F, L, D ) \
2138  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ScalarAssign, F, L, D ) \
2139  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ValueAssign, F, L, D ) \
2140  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Resize, F, L, D ) \
2141  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged, F, L, D ) \
2142  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged2, F, L, D ) \
2143  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst, F, L, D ) \
2144  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst2, F, L, D ) \
2145  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Multiply, F, L, D ) \
2146  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyUpdate, F, L, D ) \
2147  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyConst, F, L, D ) \
2148  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyMixed, F, L, D ) \
2149  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicAdd, F, L, D ) \
2150  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Rank8, F, L, D ) \
2151  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Roger, F, L, D ) \
2152  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignDifferentStrides, F, L, D ) \
2153  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankDimensionScalar, F, L, D ) \
2154  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic0, F, L, D ) \
2155  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic1, F, L, D ) \
2156  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic2, F, L, D ) \
2157  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankMultiply, F, L, D ) \
2158  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewCol, F, L, D ) \
2159  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewRow, F, L, D ) \
2160  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewScalar, F, L, D ) \
2161  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Subview, F, L, D ) \
2162  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ShmemSize, F, L, D )
2163 
2164 #define VIEW_FAD_TESTS_SFLD( F, L, D ) \
2165  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SFadNoSizeArg, F, L, D )
2166 
2167 #define VIEW_FAD_TESTS_FDI( F, D ) \
2168  using Kokkos::LayoutLeft; \
2169  using Kokkos::LayoutRight; \
2170  VIEW_FAD_TESTS_FLD( F, LayoutLeft, D ) \
2171  VIEW_FAD_TESTS_FLD( F, LayoutRight, D ) \
2172  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, F, LayoutLeft, D ) \
2173  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, F, LayoutRight, D ) \
2174  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, CommonViewAllocMixedSpec, F, LayoutLeft, D ) \
2175  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, CommonViewAllocMixedSpec, F, LayoutRight, D )
2176 
2177 #define VIEW_FAD_TESTS_SFDI( F, D ) \
2178  using Kokkos::LayoutLeft; \
2179  using Kokkos::LayoutRight; \
2180  VIEW_FAD_TESTS_SFLD( F, LayoutLeft, D ) \
2181  VIEW_FAD_TESTS_SFLD( F, LayoutRight, D )
2182 
2183 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2184 typedef Kokkos::LayoutContiguous<Kokkos::LayoutLeft> LeftContiguous;
2185 typedef Kokkos::LayoutContiguous<Kokkos::LayoutRight> RightContiguous;
2186 #define VIEW_FAD_TESTS_FDC( F, D ) \
2187  VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \
2188  VIEW_FAD_TESTS_FLD( F, RightContiguous, D ) \
2189  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Partition, F, LeftContiguous, D ) \
2190  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Partition, F, RightContiguous, D )
2191 
2192 #define VIEW_FAD_TESTS_SFDC( F, D ) \
2193  VIEW_FAD_TESTS_SFLD( F, LeftContiguous, D ) \
2194  VIEW_FAD_TESTS_SFLD( F, RightContiguous, D )
2195 #else
2196 #define VIEW_FAD_TESTS_FDC( F, D ) /* */
2197 #define VIEW_FAD_TESTS_SFDC( F, D ) /* */
2198 #endif
2199 
2200 #define VIEW_FAD_TESTS_FD( F, D ) \
2201  VIEW_FAD_TESTS_FDI( F, D ) \
2202  VIEW_FAD_TESTS_FDC( F, D )
2203 
2204 #define VIEW_FAD_TESTS_SFD( F, D ) \
2205  VIEW_FAD_TESTS_SFDI( F, D ) \
2206  VIEW_FAD_TESTS_SFDC( F, D )
2207 
2208 // We've unified the implementation for the different Fad variants, so
2209 // there is no reason to test ELRFad, CacheFad, and ELRCacheFad.
2213 
2214 /*
2215 typedef Sacado::ELRFad::DFad<double> ELRDFadType;
2216 typedef Sacado::ELRFad::SLFad<double,2*global_fad_size> ELRSLFadType;
2217 typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRSFadType;
2218 
2219 typedef Sacado::CacheFad::DFad<double> CacheDFadType;
2220 typedef Sacado::CacheFad::SLFad<double,2*global_fad_size> CacheSLFadType;
2221 typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheSFadType;
2222 
2223 typedef Sacado::ELRCacheFad::DFad<double> ELRCacheDFadType;
2224 typedef Sacado::ELRCacheFad::SLFad<double,2*global_fad_size> ELRCacheSLFadType;
2225 typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheSFadType;
2226 */
2227 
2228 // We can't use DFad unless we use the View specialization
2229 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) && SACADO_TEST_DFAD
2230 #define VIEW_FAD_TESTS_D( D ) \
2231  VIEW_FAD_TESTS_FD( SFadType, D ) \
2232  VIEW_FAD_TESTS_FD( SLFadType, D ) \
2233  VIEW_FAD_TESTS_FD( DFadType, D ) \
2234  VIEW_FAD_TESTS_SFD( SFadType, D )
2235 
2236 #if 0
2237  VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
2238  VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
2239  VIEW_FAD_TESTS_FD( ELRDFadType, D ) \
2240  VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
2241  VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
2242  VIEW_FAD_TESTS_FD( CacheDFadType, D ) \
2243  VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
2244  VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
2245  VIEW_FAD_TESTS_FD( ELRCacheDFadType, D ) \
2246  VIEW_FAD_TESTS_SFD( SFadType, D ) \
2247  VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
2248  VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
2249  VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
2250 #endif
2251 
2252 #else
2253 
2254 #define VIEW_FAD_TESTS_D( D ) \
2255  VIEW_FAD_TESTS_FD( SFadType, D ) \
2256  VIEW_FAD_TESTS_FD( SLFadType, D ) \
2257  VIEW_FAD_TESTS_SFD( SFadType, D )
2258 
2259 #if 0
2260  VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
2261  VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
2262  VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
2263  VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
2264  VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
2265  VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
2266  VIEW_FAD_TESTS_SFD( SFadType, D ) \
2267  VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
2268  VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
2269  VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
2270 #endif
2271 
2272 #endif
InputViewType::size_type size_type
team_policy_type::member_type team_handle
static const size_type stride
ViewType::value_type::value_type ScalarType
ViewType::execution_space execution_space
Kokkos::TeamPolicy< execution_space > team_policy_type
Kokkos::TeamPolicy< execution_space > team_policy_type
static const size_type stride
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
void f()
ViewType::size_type size_type
const ViewType m_v
const ValueType m_s
static const size_type stride
ViewType::size_type size_type
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
const int global_fad_size
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
static void apply(const ViewType &v, const ValueType &s)
const ScalarViewType m_s
#define VIEW_FAD_TESTS_SFD(F, D)
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
Sacado::Fad::DFad< double > FadType
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
#define VIEW_FAD_TESTS_FD(F, D)
expr true
Kokkos::ThreadLocalScalarType< ViewType >::type local_scalar_type
Kokkos::RangePolicy< execution_space > range_policy_type
const InputViewType1 m_v1
static const size_type stride
InputViewType::execution_space execution_space
static void apply(const InputViewType v1, const OutputViewType v2, const size_type col)
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
const int global_num_rows
Kokkos::RangePolicy< execution_space > range_policy_type
ViewType::execution_space execution_space
const ScalarType m_s
scalar generate_fad(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const int fad_size, const size_t i0, const size_t i1, const size_t i2, const size_t i3, const int i_fad)
Sacado::Fad::SFad< double, fad_dim > SFadType
const OutputViewType m_v2
#define KOKKOS_INLINE_FUNCTION
Sacado::Fad::DFad< double > DFadType
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Kokkos_View_FadFad, DeepCopy, FadFadType, Layout, Device)
AssignRank2Rank1Kernel(const InputViewType v1, const OutputViewType v2, const size_type col)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
team_policy_type::member_type team_handle
const int global_num_cols
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
ViewType::size_type size_type
GeneralFad< DynamicStorage< T > > DFad
team_policy_type::member_type team_handle
static void apply(const InputViewType1 v1, const InputViewType2 v2, const OutputViewType v3, const bool update=false)
InputViewType1::execution_space execution_space
#define GLOBAL_FAD_SIZE
Kokkos::TeamPolicy< execution_space > team_policy_type
Sacado::Fad::SLFad< double, fad_dim > SLFadType
void g()
static void apply(const ViewType &v, const ScalarViewType &s)
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
ViewType::value_type ValueType
Kokkos::TeamPolicy< execution_space > team_policy_type
ScalarAssignKernel(const ViewType &v, const ScalarType &s)
ValueAssignKernel(const ViewType &v, const ValueType &s)
static const bool value
AtomicAddKernel(const ViewType &v, const ScalarViewType &s)
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
team_policy_type::member_type team_handle
const double tol
ViewType::execution_space execution_space
const ViewType m_v
static void apply(const ViewType &v, const ScalarType &s)
Kokkos::ThreadLocalScalarType< ViewType >::type local_scalar_type
MultiplyKernel(const InputViewType1 v1, const InputViewType2 v2, const OutputViewType v3, const bool update)
team_policy_type::member_type team_handle
const InputViewType m_v1
InputViewType1::size_type size_type
Kokkos::RangePolicy< execution_space > range_policy_type
Kokkos::RangePolicy< execution_space > range_policy_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
GeneralFad< StaticFixedStorage< T, Num > > SFad
const InputViewType2 m_v2
Kokkos::RangePolicy< execution_space > range_policy_type
static const bool value
Kokkos::TeamPolicy< execution_space > team_policy_type
const OutputViewType m_v3