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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
11 
12 #include "Sacado.hpp"
14 
15 template <typename T>
16 struct is_sfad {
17  static const bool value = false;
18 };
19 
20 template <typename T, int N>
21 struct is_sfad< Sacado::Fad::SFad<T,N> > {
22  static const bool value = true;
23 };
24 
25 template <typename T>
26 struct is_dfad {
27  static const bool value = false;
28 };
29 
30 template <typename T>
31 struct is_dfad< Sacado::Fad::DFad<T> > {
32  static const bool value = true;
33 };
34 
35 template <typename FadType1, typename FadType2>
36 bool checkFads(const FadType1& x, const FadType2& x2,
37  Teuchos::FancyOStream& out, double tol = 1.0e-15)
38 {
39  bool success = true;
40 
41  // Check sizes match
42  TEUCHOS_TEST_EQUALITY(x.size(), x2.size(), out, success);
43 
44  // Check values match
45  TEUCHOS_TEST_FLOATING_EQUALITY(x.val(), x2.val(), tol, out, success);
46 
47  // Check derivatives match
48  for (int i=0; i<x.size(); ++i)
49  TEUCHOS_TEST_FLOATING_EQUALITY(x.dx(i), x2.dx(i), tol, out, success);
50 
51  return success;
52 }
53 
54 template <typename fadtype, typename ordinal>
55 inline
56 fadtype generate_fad( const ordinal num_rows,
57  const ordinal num_cols,
58  const ordinal fad_size,
59  const ordinal row,
60  const ordinal col )
61 {
62  typedef typename fadtype::value_type scalar;
63  fadtype x(fad_size, scalar(0.0));
64 
65  const scalar x_row = 100.0 + scalar(num_rows) / scalar(row+1);
66  const scalar x_col = 10.0 + scalar(num_cols) / scalar(col+1);
67  x.val() = x_row + x_col;
68  for (ordinal i=0; i<fad_size; ++i) {
69  const scalar x_fad = 1.0 + scalar(fad_size) / scalar(i+1);
70  x.fastAccessDx(i) = x_row + x_col + x_fad;
71  }
72  return x;
73 }
74 
75 #ifndef GLOBAL_FAD_SIZE
76 #define GLOBAL_FAD_SIZE 5
77 #endif
78 const int global_num_rows = 11;
79 const int global_num_cols = 7;
81 
82 // Kernel to multiply two views
83 template <typename InputViewType1,
84  typename InputViewType2 = InputViewType1,
85  typename OutputViewType = InputViewType1>
87  typedef typename InputViewType1::execution_space execution_space;
88  typedef typename InputViewType1::size_type size_type;
89  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
90  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
91  typedef typename team_policy_type::member_type team_handle;
92 
93  const InputViewType1 m_v1;
94  const InputViewType2 m_v2;
95  const OutputViewType m_v3;
96  const bool m_update;
97 
98  MultiplyKernel(const InputViewType1 v1,
99  const InputViewType2 v2,
100  const OutputViewType v3,
101  const bool update) :
102  m_v1(v1), m_v2(v2), m_v3(v3), m_update(update) {};
103 
104  // Multiply entries for row 'i' with a value
105  KOKKOS_INLINE_FUNCTION
106  void operator() (const size_type i) const {
107  if (m_update)
108  m_v3(i) += m_v1(i)*m_v2(i);
109  else
110  m_v3(i) = m_v1(i)*m_v2(i);
111  }
112 
113  KOKKOS_INLINE_FUNCTION
114  void operator()( const team_handle& team ) const
115  {
116  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
117  if (i < m_v1.extent(0))
118  (*this)(i);
119  }
120 
121  // Kernel launch
122  static void apply(const InputViewType1 v1,
123  const InputViewType2 v2,
124  const OutputViewType v3,
125  const bool update = false) {
126  const size_type nrow = v1.extent(0);
127 
128 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
129  const size_type stride = Kokkos::ViewScalarStride<InputViewType1>::stride;
130  const bool use_team =
134  ( stride > 1 );
135 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
136  const size_type stride = team_policy_type::vector_length_max(); // 32
137  const bool use_team =
142 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
143  const size_type stride = Kokkos::ViewScalarStride<InputViewType1>::stride;
144  const bool use_team =
148  ( stride > 1 );
149 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
150  const size_type stride = team_policy_type::vector_length_max(); // 64
151  const bool use_team =
156 #else
157  const size_type stride = 1;
158  const bool use_team = false;
159 #endif
160 
161  if (use_team) {
162  const size_type team_size = 256 / stride;
163  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
164  Kokkos::parallel_for( policy, MultiplyKernel(v1,v2,v3,update) );
165  }
166  else {
167  range_policy_type policy( 0, nrow );
168  Kokkos::parallel_for( policy, MultiplyKernel(v1,v2,v3,update) );
169  }
170  }
171 };
172 
173 // Kernel to assign a constant to a view
174 template <typename ViewType>
176  typedef typename ViewType::execution_space execution_space;
177  typedef typename ViewType::size_type size_type;
178  typedef typename ViewType::value_type::value_type ScalarType;
179  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
180  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
181  typedef typename team_policy_type::member_type team_handle;
182  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
183 
184  const ViewType m_v;
186 
187  ScalarAssignKernel(const ViewType& v, const ScalarType& s) :
188  m_v(v), m_s(s) {};
189 
190  // Multiply entries for row 'i' with a value
191  KOKKOS_INLINE_FUNCTION
192  void operator() (const size_type i) const {
193  m_v(i) = m_s;
194  }
195 
196  KOKKOS_INLINE_FUNCTION
197  void operator()( const team_handle& team ) const
198  {
199  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
200  if (i < m_v.extent(0))
201  (*this)(i);
202  }
203 
204  // Kernel launch
205  static void apply(const ViewType& v, const ScalarType& s) {
206  const size_type nrow = v.extent(0);
207 
208 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
209  const bool use_team =
213  ( stride > 1 );
214 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
215  const bool use_team =
220 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
221  const bool use_team =
225  ( stride > 1 );
226 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
227  const bool use_team =
232 #else
233  const bool use_team = false;
234 #endif
235 
236  if (use_team) {
237  const size_type team_size = 256 / stride;
238  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
239  Kokkos::parallel_for( policy, ScalarAssignKernel(v,s) );
240  }
241  else {
242  range_policy_type policy( 0, nrow );
243  Kokkos::parallel_for( policy, ScalarAssignKernel(v,s) );
244  }
245  }
246 };
247 
248 // Kernel to assign a constant to a view
249 template <typename ViewType, typename ScalarViewType>
251  typedef typename ViewType::execution_space execution_space;
252  typedef typename ViewType::size_type size_type;
253  typedef typename ViewType::value_type ValueType;
254  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
255  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
256  typedef typename team_policy_type::member_type team_handle;
257  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_scalar_type;
258  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
259 
260  const ViewType m_v;
261  const ScalarViewType m_s;
262 
263  ValueAssignKernel(const ViewType& v, const ScalarViewType& s) :
264  m_v(v), m_s(s) {};
265 
266  // Multiply entries for row 'i' with a value
267  KOKKOS_INLINE_FUNCTION
268  void operator() (const size_type i) const {
269  local_scalar_type s = Sacado::partition_scalar<stride>(m_s());
270  m_v(i) = s;
271  }
272 
273  KOKKOS_INLINE_FUNCTION
274  void operator()( const team_handle& team ) const
275  {
276  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
277  if (i < m_v.extent(0))
278  (*this)(i);
279  }
280 
281  // Kernel launch
282  static void apply(const ViewType& v, const ScalarViewType& s) {
283  const size_type nrow = v.extent(0);
284 
285 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
286  const bool use_team =
290  ( stride > 1 );
291 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
292  const bool use_team =
297 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
298  const bool use_team =
302  ( stride > 1 );
303 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
304  const bool use_team =
309 #else
310  const bool use_team = false;
311 #endif
312 
313  if (use_team) {
314  const size_type team_size = 256 / stride;
315  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
316  Kokkos::parallel_for( policy, ValueAssignKernel(v,s) );
317  }
318  else {
319  range_policy_type policy( 0, nrow );
320  Kokkos::parallel_for( policy, ValueAssignKernel(v,s) );
321  }
322  }
323 };
324 
325 // Kernel to assign a column of a rank-2 to a rank-1
326 template <typename InputViewType,
327  typename OutputViewType,
328  typename Enabled = void>
330  typedef typename InputViewType::execution_space execution_space;
331  typedef typename InputViewType::size_type size_type;
332  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
333  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
334  typedef typename team_policy_type::member_type team_handle;
335  static const size_type stride = Kokkos::ViewScalarStride<InputViewType>::stride;
336 
337  const InputViewType m_v1;
338  const OutputViewType m_v2;
340 
341  AssignRank2Rank1Kernel(const InputViewType v1,
342  const OutputViewType v2,
343  const size_type col) :
344  m_v1(v1), m_v2(v2), m_col(col) {
345  static_assert( unsigned(InputViewType::rank) == 2 ,
346  "Require rank-2 input view" );
347  static_assert( unsigned(OutputViewType::rank) == 1 ,
348  "Require rank-1 output view" );
349  };
350 
351  // Multiply entries for row 'i' with a value
352  KOKKOS_INLINE_FUNCTION
353  void operator() (const size_type i) const {
354  m_v2(i) = m_v1(i,m_col);
355  }
356 
357  KOKKOS_INLINE_FUNCTION
358  void operator()( const team_handle& team ) const
359  {
360  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
361  if (i < m_v1.extent(0))
362  (*this)(i);
363  }
364 
365  // Kernel launch
366  static void apply(const InputViewType v1,
367  const OutputViewType v2,
368  const size_type col) {
369  const size_type nrow = v1.extent(0);
370 
371 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
372  const bool use_team =
376  ( stride > 1 );
377 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
378  const bool use_team =
383 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
384  const bool use_team =
388  ( stride > 1 );
389 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
390  const bool use_team =
395 #else
396  const bool use_team = false;
397 #endif
398 
399  if (use_team) {
400  const size_type team_size = 256 / stride;
401  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
402  Kokkos::parallel_for( policy, AssignRank2Rank1Kernel(v1,v2,col) );
403  }
404  else {
405  range_policy_type policy( 0, nrow );
406  Kokkos::parallel_for( policy, AssignRank2Rank1Kernel(v1,v2,col) );
407  }
408  }
409 };
410 
411 // Kernel to test atomic_add
412 template <typename ViewType, typename ScalarViewType>
414  typedef typename ViewType::execution_space execution_space;
415  typedef typename ViewType::size_type size_type;
416  typedef Kokkos::TeamPolicy< execution_space> team_policy_type;
417  typedef Kokkos::RangePolicy< execution_space> range_policy_type;
418  typedef typename team_policy_type::member_type team_handle;
419  typedef typename Kokkos::ThreadLocalScalarType<ViewType>::type local_scalar_type;
420  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
421 
422  const ViewType m_v;
423  const ScalarViewType m_s;
424 
425  AtomicAddKernel(const ViewType& v, const ScalarViewType& s) :
426  m_v(v), m_s(s) {};
427 
428  // Multiply entries for row 'i' with a value
429  KOKKOS_INLINE_FUNCTION
430  void operator() (const size_type i) const {
431  local_scalar_type x = m_v(i);
432  Kokkos::atomic_add(&(m_s()), x);
433  }
434 
435  KOKKOS_INLINE_FUNCTION
436  void operator()( const team_handle& team ) const
437  {
438  const size_type i = team.league_rank()*team.team_size() + team.team_rank();
439  if (i < m_v.extent(0))
440  (*this)(i);
441  }
442 
443  // Kernel launch
444  static void apply(const ViewType& v, const ScalarViewType& s) {
445  const size_type nrow = v.extent(0);
446 
447 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
448  const bool use_team =
452  ( stride > 1 );
453 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
454  const bool use_team =
459 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
460  const bool use_team =
464  ( stride > 1 );
465 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
466  const bool use_team =
471 #else
472  const bool use_team = false;
473 #endif
474 
475  if (use_team) {
476  const size_type team_size = 256 / stride;
477  team_policy_type policy( (nrow+team_size-1)/team_size, team_size, stride );
478  Kokkos::parallel_for( policy, AtomicAddKernel(v,s) );
479  }
480  else {
481  range_policy_type policy( 0, nrow );
482  Kokkos::parallel_for( policy, AtomicAddKernel(v,s) );
483  }
484  }
485 };
486 
488  Kokkos_View_Fad, Size, FadType, Layout, Device )
489 {
490  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
491  typedef typename ViewType::size_type size_type;
492 
493  const size_type num_rows = global_num_rows;
494 
495  // Create and fill view
496  ViewType v;
497 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
498  v = ViewType("view", num_rows);
499 #else
500  const size_type fad_size = global_fad_size;
501  v = ViewType("view", num_rows, fad_size+1);
502 #endif
503  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
504 }
505 
507  Kokkos_View_Fad, DeepCopy, FadType, Layout, Device )
508 {
509  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
510  typedef typename ViewType::size_type size_type;
511  typedef typename ViewType::host_mirror_type host_view_type;
512 
513  const size_type num_rows = global_num_rows;
514  const size_type num_cols = global_num_cols;
515  const size_type fad_size = global_fad_size;
516 
517  // Create and fill view
518  ViewType v;
519 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
520  v = ViewType ("view", num_rows, num_cols);
521 #else
522  v = ViewType ("view", num_rows, num_cols, fad_size+1);
523 #endif
524  host_view_type h_v = Kokkos::create_mirror_view(v);
525  for (size_type i=0; i<num_rows; ++i)
526  for (size_type j=0; j<num_cols; ++j)
527  h_v(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
528  Kokkos::deep_copy(v, h_v);
529 
530  // Copy back
531  host_view_type h_v2 = Kokkos::create_mirror_view(v);
532  Kokkos::deep_copy(h_v2, v);
533 
534  // Check
535  success = true;
536  for (size_type i=0; i<num_rows; ++i) {
537  for (size_type j=0; j<num_cols; ++j) {
538  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
539  success = success && checkFads(f, h_v2(i,j), out);
540  }
541  }
542 }
543 
545  Kokkos_View_Fad, DeepCopy_ConstantScalar, FadType, Layout, Device )
546 {
547  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
548  typedef typename ViewType::size_type size_type;
549  typedef typename ViewType::host_mirror_type host_view_type;
550  typedef typename FadType::value_type value_type;
551 
552  const size_type num_rows = global_num_rows;
553  const size_type num_cols = global_num_cols;
554 
555  // Create and fill view
556  ViewType v;
557 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
558  v = ViewType ("view", num_rows, num_cols);
559 #else
560  const size_type fad_size = global_fad_size;
561  v = ViewType ("view", num_rows, num_cols, fad_size+1);
562 #endif
563 #if KOKKOS_VERSION >= 40799
564  typename ViewType::type va = v;
565 #else
566  typename ViewType::array_type va = v;
567 #endif
568  Kokkos::deep_copy( va, 1.0 );
569 
570  // Deep copy a constant scalar
571  value_type a = 2.3456;
572  Kokkos::deep_copy( v, a );
573 
574  // Copy to host
575  host_view_type hv = Kokkos::create_mirror_view(v);
576  Kokkos::deep_copy(hv, v);
577 
578  // Check
579  success = true;
580  for (size_type i=0; i<num_rows; ++i) {
581  for (size_type j=0; j<num_cols; ++j) {
582 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
583  FadType f = FadType(fad_size, a);
584 #else
585  FadType f = a;
586 #endif
587  success = success && checkFads(f, hv(i,j), out);
588  }
589  }
590 }
591 
593  Kokkos_View_Fad, DeepCopy_ConstantZero, FadType, Layout, Device )
594 {
595  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
596  typedef typename ViewType::size_type size_type;
597  typedef typename ViewType::host_mirror_type host_view_type;
598  typedef typename FadType::value_type value_type;
599 
600  const size_type num_rows = global_num_rows;
601  const size_type num_cols = global_num_cols;
602 
603  // Create and fill view
604  ViewType v;
605 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
606  v = ViewType ("view", num_rows, num_cols);
607 #else
608  const size_type fad_size = global_fad_size;
609  v = ViewType ("view", num_rows, num_cols, fad_size+1);
610 #endif
611 #if KOKKOS_VERSION >= 40799
612  typename ViewType::type va = v;
613 #else
614  typename ViewType::array_type va = v;
615 #endif
616  Kokkos::deep_copy( va, 1.0 );
617 
618  // Deep copy a constant scalar
619  value_type a = 0.0;
620  Kokkos::deep_copy( v, a );
621 
622  // Copy to host
623  host_view_type hv = Kokkos::create_mirror_view(v);
624  Kokkos::deep_copy(hv, v);
625 
626  // Check
627  success = true;
628  for (size_type i=0; i<num_rows; ++i) {
629  for (size_type j=0; j<num_cols; ++j) {
630 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
631  FadType f = FadType(fad_size, a);
632 #else
633  FadType f = a;
634 #endif
635  success = success && checkFads(f, hv(i,j), out);
636  }
637  }
638 }
639 
641  Kokkos_View_Fad, DeepCopy_ConstantFad, FadType, Layout, Device )
642 {
643  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
644  typedef typename ViewType::size_type size_type;
645  typedef typename ViewType::host_mirror_type host_view_type;
646 
647  const size_type num_rows = global_num_rows;
648  const size_type num_cols = global_num_cols;
649 
650  // Create and fill view
651  ViewType v;
652 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
653  v = ViewType ("view", num_rows, num_cols);
654 #else
655  const size_type fad_size = global_fad_size;
656  v = ViewType ("view", num_rows, num_cols, fad_size+1);
657 #endif
658 #if KOKKOS_VERSION >= 40799
659  typename ViewType::type va = v;
660 #else
661  typename ViewType::array_type va = v;
662 #endif
663  Kokkos::deep_copy( va, 1.0 );
664 
665  // Deep copy a constant scalar
666  FadType a = 2.3456;
667  Kokkos::deep_copy( v, a );
668 
669  // Copy to host
670  host_view_type hv = Kokkos::create_mirror_view(v);
671  Kokkos::deep_copy(hv, v);
672 
673  // Check
674  success = true;
675  for (size_type i=0; i<num_rows; ++i) {
676  for (size_type j=0; j<num_cols; ++j) {
677 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
678  FadType f = FadType(fad_size, a.val());
679 #else
680  FadType f = a;
681 #endif
682  success = success && checkFads(f, hv(i,j), out);
683  }
684  }
685 }
686 
688  Kokkos_View_Fad, DeepCopy_ConstantFadFull, FadType, Layout, Device )
689 {
690  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
691  typedef typename ViewType::size_type size_type;
692  typedef typename ViewType::host_mirror_type host_view_type;
693 
694  const size_type num_rows = global_num_rows;
695  const size_type num_cols = global_num_cols;
696  const size_type fad_size = global_fad_size;
697 
698  // Create and fill view
699  ViewType v;
700 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
701  v = ViewType ("view", num_rows, num_cols);
702 #else
703  v = ViewType ("view", num_rows, num_cols, fad_size+1);
704 #endif
705 #if KOKKOS_VERSION >= 40799
706  typename ViewType::type va = v;
707 #else
708  typename ViewType::array_type va = v;
709 #endif
710  Kokkos::deep_copy( va, 1.0 );
711 
712  // Deep copy a constant Fad
713  FadType a(fad_size, 2.3456);
714  for (size_type i=0; i<fad_size; ++i)
715  a.fastAccessDx(i) = 7.89 + (i+1);
716 
717  // Copy to host
718  host_view_type hv = Kokkos::create_mirror_view(v);
719  Kokkos::deep_copy(hv, a);
720 
721  // Check
722  success = true;
723  for (size_type i=0; i<num_rows; ++i) {
724  for (size_type j=0; j<num_cols; ++j) {
725  success = success && checkFads(a, hv(i,j), out);
726  }
727  }
728 }
729 
731  Kokkos_View_Fad, LocalDeepCopy, FadType, Layout, Device )
732 {
733  typedef Kokkos::View<FadType***,Layout,Device> ViewType;
734  typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
735  typedef typename ViewType::size_type size_type;
736  typedef typename ViewType::host_mirror_type host_view_type;
737  typedef typename ScalarViewType::host_mirror_type host_scalar_view_type;
738 
739  const size_type num_rows = global_num_rows;
740  const size_type num_cols = global_num_cols;
741  const size_type num_slices = 10;
742  const size_type fad_size = global_fad_size;
743 
744  // Create and fill view
745  ViewType v;
746 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
747  v = ViewType ("view", num_rows, num_cols, num_slices);
748 #else
749  v = ViewType ("view", num_rows, num_cols, num_slices, fad_size+1);
750 #endif
751 #if KOKKOS_VERSION >= 40799
752  typename ViewType::type va = v;
753 #else
754  typename ViewType::array_type va = v;
755 #endif
756  Kokkos::deep_copy( va, 1.0 );
757 
758  // Deep copy a constant Fad to the device
759  // Can't deep_copy directly because that doesn't work with DFad
760  FadType a(fad_size, 2.3456);
761  for (size_type i=0; i<fad_size; ++i)
762  a.fastAccessDx(i) = 7.89 + (i+1);
763 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
764  ScalarViewType a_view("a");
765 #else
766  ScalarViewType a_view("a", fad_size+1);
767 #endif
768  host_scalar_view_type ha_view = Kokkos::create_mirror_view(a_view);
769  ha_view() = a;
770  Kokkos::deep_copy( a_view, ha_view );
771 
772  // Excersize local_deep_copy by setting each row of s to a
773  Kokkos::parallel_for(Kokkos::RangePolicy<Device>(0,num_rows),
774  KOKKOS_LAMBDA(const int i)
775  {
776  auto s = Kokkos::subview(v,i,Kokkos::ALL,Kokkos::ALL);
777  Kokkos::Experimental::local_deep_copy(s,a_view());
778  });
779 
780  // Copy back to host
781  host_view_type hv = Kokkos::create_mirror_view(v);
782  Kokkos::deep_copy(hv, a);
783 
784  // Check
785  success = true;
786  for (size_type i=0; i<num_rows; ++i) {
787  for (size_type j=0; j<num_cols; ++j) {
788  for (size_type k=0; k<num_slices; ++k) {
789  success = success && checkFads(a, hv(i,j,k), out);
790  }
791  }
792  }
793 }
794 
796  Kokkos_View_Fad, LocalDeepCopyTeam, FadType, Layout, Device )
797 {
798  typedef Kokkos::View<FadType***,Layout,Device> ViewType;
799  typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
800  typedef typename ViewType::size_type size_type;
801  typedef typename ViewType::host_mirror_type host_view_type;
802  typedef typename ScalarViewType::host_mirror_type host_scalar_view_type;
803 
804  const size_type num_rows = global_num_rows;
805  const size_type num_cols = global_num_cols;
806  const size_type num_slices = 10;
807  const size_type fad_size = global_fad_size;
808 
809  // Create and fill view
810  ViewType v;
811 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
812  v = ViewType ("view", num_rows, num_cols, num_slices);
813 #else
814  v = ViewType ("view", num_rows, num_cols, num_slices, fad_size+1);
815 #endif
816 #if KOKKOS_VERSION >= 40799
817  typename ViewType::type va = v;
818 #else
819  typename ViewType::array_type va = v;
820 #endif
821  Kokkos::deep_copy( va, 1.0 );
822 
823  // Deep copy a constant Fad to the device
824  // Can't deep_copy directly because that doesn't work with DFad
825  FadType a(fad_size, 2.3456);
826  for (size_type i=0; i<fad_size; ++i)
827  a.fastAccessDx(i) = 7.89 + (i+1);
828 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
829  ScalarViewType a_view("a");
830 #else
831  ScalarViewType a_view("a", fad_size+1);
832 #endif
833  host_scalar_view_type ha_view = Kokkos::create_mirror_view(a_view);
834  ha_view() = a;
835  Kokkos::deep_copy( a_view, ha_view );
836 
837  // Excersize local_deep_copy by setting each row of s to a
838  typedef Kokkos::TeamPolicy<Device> Policy;
839  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
840  Kokkos::parallel_for(Policy(num_rows,Kokkos::AUTO,stride),
841  KOKKOS_LAMBDA(const typename Policy::member_type& team)
842  {
843  int i = team.league_rank();
844  auto s = Kokkos::subview(v,i,Kokkos::ALL,Kokkos::ALL);
845  Kokkos::Experimental::local_deep_copy(team,s,a_view());
846  });
847 
848  // Copy back to host
849  host_view_type hv = Kokkos::create_mirror_view(v);
850  Kokkos::deep_copy(hv, a);
851 
852  // Check
853  success = true;
854  for (size_type i=0; i<num_rows; ++i) {
855  for (size_type j=0; j<num_cols; ++j) {
856  for (size_type k=0; k<num_slices; ++k) {
857  success = success && checkFads(a, hv(i,j,k), out);
858  }
859  }
860  }
861 }
862 
864  Kokkos_View_Fad, ScalarAssign, FadType, Layout, Device )
865 {
866  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
867  typedef typename ViewType::size_type size_type;
868  typedef typename ViewType::host_mirror_type host_view_type;
869  typedef typename FadType::value_type value_type;
870 
871  const size_type num_rows = global_num_rows;
872 
873  // Create and fill view
874  ViewType v;
875 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
876  v = ViewType ("view", num_rows);
877 #else
878  const size_type fad_size = global_fad_size;
879  v = ViewType ("view", num_rows, fad_size+1);
880 #endif
881 #if KOKKOS_VERSION >= 40799
882  typename ViewType::type va = v;
883 #else
884  typename ViewType::array_type va = v;
885 #endif
886  Kokkos::deep_copy( va, 1.0 );
887 
888  // Deep copy a constant scalar
889  value_type a = 2.3456;
891 
892  // Copy to host
893  host_view_type hv = Kokkos::create_mirror_view(v);
894  Kokkos::deep_copy(hv, v);
895 
896  // Check
897  success = true;
898  for (size_type i=0; i<num_rows; ++i) {
899 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
900  FadType f = FadType(fad_size, a);
901 #else
902  FadType f = a;
903 #endif
904  success = success && checkFads(f, hv(i), out);
905  }
906 }
907 
909  Kokkos_View_Fad, ValueAssign, FadType, Layout, Device )
910 {
911  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
912  typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
913  typedef typename ViewType::size_type size_type;
914  typedef typename ViewType::host_mirror_type host_view_type;
915  typedef typename ScalarViewType::host_mirror_type host_scalar_view_type;
916 
917  const size_type num_rows = global_num_rows;
918  const size_type fad_size = global_fad_size;
919 
920  // Create and fill view
921  ViewType v;
922  ScalarViewType a;
923 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
924  v = ViewType ("view", num_rows);
925  a = ScalarViewType ("fad");
926 #else
927  v = ViewType ("view", num_rows, fad_size+1);
928  a = ScalarViewType ("fad", fad_size+1);
929 #endif
930 #if KOKKOS_VERSION >= 40799
931  typename ViewType::type va = v;
932 #else
933  typename ViewType::array_type va = v;
934 #endif
935  Kokkos::deep_copy( va, 1.0 );
936 
937  // Deep copy a constant scalar
938  Kokkos::deep_copy(a, 2.3456);
939 
940  Kokkos::parallel_for(Kokkos::RangePolicy< Device>(0, fad_size), KOKKOS_LAMBDA(const int i) {
941  a().fastAccessDx(i) = 7.89 + i;
942  });
943  Kokkos::fence();
944 
946  Kokkos::fence();
947 
948  // Copy to host
949  host_view_type hv = Kokkos::create_mirror_view(v);
950  Kokkos::deep_copy(hv, v);
951 
952  host_scalar_view_type ha = Kokkos::create_mirror_view(a);
953  Kokkos::deep_copy(ha, a);
954 
955  // Check
956  success = true;
957  for (size_type i=0; i<num_rows; ++i) {
958  success = success && checkFads(ha(), hv(i), out);
959  }
960 }
961 
963  Kokkos_View_Fad, Resize, FadType, Layout, Device )
964 {
965  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
966  typedef typename ViewType::size_type size_type;
967  typedef typename ViewType::host_mirror_type host_view_type;
968 
969  const size_type num_rows = global_num_rows;
970  const size_type num_cols = global_num_cols;
971  const size_type fad_size = global_fad_size;
972 
973  // Create and fill view
974  ViewType v;
975 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
976  v = ViewType ("view", num_rows, num_cols);
977 #else
978  v = ViewType ("view", num_rows, num_cols, fad_size+1);
979 #endif
980  host_view_type h_v = Kokkos::create_mirror_view(v);
981  for (size_type i=0; i<num_rows; ++i)
982  for (size_type j=0; j<num_cols; ++j)
983  h_v(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
984  Kokkos::deep_copy(v, h_v);
985 
986  // Resize
987 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
988  Kokkos::resize(v, num_rows, num_cols+1);
989 #else
990  Kokkos::resize(v, num_rows, num_cols+1, fad_size+1);
991 #endif
992 
993  // Copy back
994  host_view_type h_v2 = Kokkos::create_mirror_view(v);
995  Kokkos::deep_copy(h_v2, v);
996 
997  // Check
998  success = true;
999  for (size_type i=0; i<num_rows; ++i) {
1000  for (size_type j=0; j<num_cols; ++j) {
1001  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1002  success = success && checkFads(f, h_v2(i,j), out);
1003  }
1004 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1005  FadType f = 0.0;
1006 #else
1007  FadType f(fad_size, 0.0);
1008 #endif
1009  success = success && checkFads(f, h_v2(i,num_cols), out);
1010  }
1011 }
1012 
1014  Kokkos_View_Fad, Multiply, FadType, Layout, Device )
1015 {
1016  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1017  typedef typename ViewType::size_type size_type;
1018  typedef typename ViewType::host_mirror_type host_view_type;
1019 
1020  const size_type num_rows = global_num_rows;
1021  const size_type fad_size = global_fad_size;
1022 
1023  // Create and fill views
1024  ViewType v1, v2;
1025 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1026  v1 = ViewType ("view1", num_rows);
1027  v2 = ViewType ("view2", num_rows);
1028 #else
1029  v1 = ViewType ("view1", num_rows, fad_size+1);
1030  v2 = ViewType ("view2", num_rows, fad_size+1);
1031 #endif
1032  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1033  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
1034  for (size_type i=0; i<num_rows; ++i) {
1035  h_v1(i) = generate_fad<FadType>(
1036  num_rows, size_type(2), fad_size, i, size_type(0));
1037  h_v2(i) = generate_fad<FadType>(
1038  num_rows, size_type(2), fad_size, i, size_type(1));
1039  }
1040  Kokkos::deep_copy(v1, h_v1);
1041  Kokkos::deep_copy(v2, h_v2);
1042 
1043  // Launch kernel
1044  ViewType v3;
1045 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1046  v3 = ViewType ("view3", num_rows);
1047 #else
1048  v3 = ViewType ("view3", num_rows, fad_size+1);
1049 #endif
1051 
1052  // Copy back
1053  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
1054  Kokkos::deep_copy(h_v3, v3);
1055 
1056  // Check
1057  success = true;
1058  for (size_type i=0; i<num_rows; ++i) {
1059  FadType f1 =
1060  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
1061  FadType f2 =
1062  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
1063  FadType f3 = f1*f2;
1064  success = success && checkFads(f3, h_v3(i), out);
1065  }
1066 }
1067 
1069  Kokkos_View_Fad, MultiplyUpdate, FadType, Layout, Device )
1070 {
1071  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1072  typedef typename ViewType::size_type size_type;
1073  typedef typename ViewType::host_mirror_type host_view_type;
1074 
1075  const size_type num_rows = global_num_rows;
1076  const size_type fad_size = global_fad_size;
1077 
1078  // Create and fill views
1079  ViewType v1, v2;
1080 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1081  v1 = ViewType ("view1", num_rows);
1082  v2 = ViewType ("view2", num_rows);
1083 #else
1084  v1 = ViewType ("view1", num_rows, fad_size+1);
1085  v2 = ViewType ("view2", num_rows, fad_size+1);
1086 #endif
1087  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1088  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
1089  for (size_type i=0; i<num_rows; ++i) {
1090  h_v1(i) = generate_fad<FadType>(
1091  num_rows, size_type(2), fad_size, i, size_type(0));
1092  h_v2(i) = generate_fad<FadType>(
1093  num_rows, size_type(2), fad_size, i, size_type(1));
1094  }
1095  Kokkos::deep_copy(v1, h_v1);
1096  Kokkos::deep_copy(v2, h_v2);
1097 
1098  // Launch kernel
1099  ViewType v3;
1100 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1101  v3 = ViewType ("view3", num_rows);
1102 #else
1103  v3 = ViewType ("view3", num_rows, fad_size+1);
1104 #endif
1105  Kokkos::deep_copy(v3, 1.0);
1106  MultiplyKernel<ViewType>::apply(v1,v2,v3,true);
1107 
1108  // Copy back
1109  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
1110  Kokkos::deep_copy(h_v3, v3);
1111 
1112  // Check
1113  success = true;
1114  for (size_type i=0; i<num_rows; ++i) {
1115  FadType f1 =
1116  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
1117  FadType f2 =
1118  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
1119  FadType f3 = 1.0 + f1*f2;
1120  success = success && checkFads(f3, h_v3(i), out);
1121  }
1122 }
1123 
1125  Kokkos_View_Fad, MultiplyConst, FadType, Layout, Device )
1126 {
1127  typedef Kokkos::View<const FadType*,Layout,Device,Kokkos::MemoryUnmanaged> ConstViewType;
1128  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1129  typedef typename ViewType::size_type size_type;
1130  typedef typename ViewType::host_mirror_type host_view_type;
1131 
1132  const size_type num_rows = global_num_rows;
1133  const size_type fad_size = global_fad_size;
1134 
1135  // Create and fill views
1136  ViewType v1, v2;
1137 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1138  v1 = ViewType ("view1", num_rows);
1139  v2 = ViewType ("view2", num_rows);
1140 #else
1141  v1 = ViewType ("view1", num_rows, fad_size+1);
1142  v2 = ViewType ("view2", num_rows, fad_size+1);
1143 #endif
1144  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1145  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
1146  for (size_type i=0; i<num_rows; ++i) {
1147  h_v1(i) = generate_fad<FadType>(
1148  num_rows, size_type(2), fad_size, i, size_type(0));
1149  h_v2(i) = generate_fad<FadType>(
1150  num_rows, size_type(2), fad_size, i, size_type(1));
1151  }
1152  Kokkos::deep_copy(v1, h_v1);
1153  Kokkos::deep_copy(v2, h_v2);
1154 
1155  ConstViewType cv1 = v1;
1156 
1157  // Launch kernel
1158  ViewType v3;
1159 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1160  v3 = ViewType ("view3", num_rows);
1161 #else
1162  v3 = ViewType ("view3", num_rows, fad_size+1);
1163 #endif
1165 
1166  // Copy back
1167  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
1168  Kokkos::deep_copy(h_v3, v3);
1169 
1170  // Check
1171  success = true;
1172  for (size_type i=0; i<num_rows; ++i) {
1173  FadType f1 =
1174  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
1175  FadType f2 =
1176  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
1177  FadType f3 = f1*f2;
1178  success = success && checkFads(f3, h_v3(i), out);
1179  }
1180 }
1181 
1183  Kokkos_View_Fad, MultiplyMixed, FadType, Layout, Device )
1184 {
1185  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1186  typedef typename ViewType::size_type size_type;
1187  typedef typename ViewType::host_mirror_type host_view_type;
1188 
1189  const size_type num_rows = 2;
1190  const size_type fad_size = global_fad_size;
1191 
1192  // Create and fill views -- do everything on the host for this test
1193  FadType f0 = generate_fad<FadType>(
1194  num_rows, size_type(2), fad_size, size_type(0), size_type(0));
1195  FadType f1 = generate_fad<FadType>(
1196  num_rows, size_type(2), fad_size, size_type(1), size_type(0));
1197  host_view_type h_v;
1198 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1199  h_v = host_view_type ("view1", num_rows);
1200 #else
1201  h_v = host_view_type ("view1", num_rows, fad_size+1);
1202 #endif
1203  h_v(0) = f0;
1204  h_v(1) = f1;
1205 
1206  FadType f2 = f0 * h_v(1);
1207 
1208  // Check
1209  FadType f3 = f0 * f1;
1210  success = checkFads(f3, f2, out);
1211 }
1212 
1214  Kokkos_View_Fad, AtomicAdd, FadType, Layout, Device )
1215 {
1216  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1217  typedef Kokkos::View<FadType,Layout,Device> ScalarViewType;
1218  typedef typename ViewType::size_type size_type;
1219  typedef typename ScalarViewType::host_mirror_type host_scalar_view_type;
1220 
1221  const size_type num_rows = global_num_rows;
1222  const size_type fad_size = global_fad_size;
1223 
1224  // Create and fill view
1225  ViewType v;
1226 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1227  v = ViewType ("view", num_rows);
1228 #else
1229  v = ViewType ("view", num_rows, fad_size+1);
1230 #endif
1231  Kokkos::deep_copy(v, 2.3456);
1232 
1233  Kokkos::parallel_for(Kokkos::RangePolicy<Device>(0, num_rows), KOKKOS_LAMBDA(const size_type i) {
1234  for (size_type j = 0; j < fad_size; ++j)
1235  v(i).fastAccessDx(j) = 7.89 + j;
1236  });
1237 
1238  // Create scalar view
1239  ScalarViewType s;
1240 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1241  s = ScalarViewType ("scalar view");
1242 #else
1243  s = ScalarViewType ("scalar view", fad_size+1);
1244 #endif
1245 
1246  // Call atomic_add kernel, which adds up entries in v
1248 
1249  // Copy to host
1250  host_scalar_view_type hs = Kokkos::create_mirror_view(s);
1251  Kokkos::deep_copy(hs, s);
1252 
1253  // Check
1254  auto hv = Kokkos::create_mirror_view(v);
1255  Kokkos::deep_copy(hv, v);
1256 
1257  FadType b = num_rows*hv(0);
1258  success = checkFads(b, hs(), out);
1259 }
1260 
1262  Kokkos_View_Fad, Rank8, FadType, Layout, Device )
1263 {
1264  typedef Kokkos::View<FadType*******,Layout,Device> ViewType;
1265  typedef typename ViewType::size_type size_type;
1266  typedef typename ViewType::host_mirror_type host_view_type;
1267 
1268  const size_type fad_size = global_fad_size;
1269 
1270  // Create and fill view
1271  ViewType v;
1272 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1273  v = ViewType ("view", 100, 1, 2, 3, 4, 5, 6);
1274 #else
1275  v = ViewType ("view", 100, 1, 2, 3, 4, 5, 6, fad_size+1);
1276 #endif
1277  host_view_type h_v = Kokkos::create_mirror_view(v);
1278 #if KOKKOS_VERSION >= 40799
1279  typename host_view_type::type h_a = h_v;
1280 #else
1281  typename host_view_type::array_type h_a = h_v;
1282 #endif
1283  Kokkos::deep_copy(h_a, 1.0);
1284 
1285  FadType f1 = FadType(fad_size, 2.0);
1286  h_v(99,0,1,2,3,4,5) = f1;
1287  FadType f2 = h_v(99,0,1,2,3,4,5);
1288 
1289  // Check
1290  success = checkFads(f1, f2, out);
1291 }
1292 
1294  Kokkos_View_Fad, Roger, FadType, Layout, Device )
1295 {
1296  Kokkos::View<FadType*,Layout,Device> a;
1297  Kokkos::View<FadType**,Layout,Device> b;
1298  Kokkos::View<FadType***,Layout,Device> c;
1299  Kokkos::View<FadType****,Layout,Device> d;
1300  Kokkos::View<FadType*****,Layout,Device> e;
1301  Kokkos::View<FadType******,Layout,Device> f;
1302  Kokkos::View<FadType*******,Layout,Device> g;
1303 
1304 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1305  a = Kokkos::View<FadType*,Layout,Device>("a",4);
1306  b = Kokkos::View<FadType**,Layout,Device> ("b",4,4);
1307  c = Kokkos::View<FadType***,Layout,Device> ("c",4,4,4);
1308  d = Kokkos::View<FadType****,Layout,Device> ("d",4,4,4,4);
1309  e = Kokkos::View<FadType*****,Layout,Device> ("e",4,4,4,4,4);
1310  f = Kokkos::View<FadType******,Layout,Device> ("f",4,4,4,4,4,4);
1311  g = Kokkos::View<FadType*******,Layout,Device> ("g",4,4,4,4,4,4,4);
1312 #else
1313  const unsigned fad_size = global_fad_size;
1314  a = Kokkos::View<FadType*,Layout,Device>("a",4,fad_size+1);
1315  b = Kokkos::View<FadType**,Layout,Device> ("b",4,4,fad_size+1);
1316  c = Kokkos::View<FadType***,Layout,Device> ("c",4,4,4,fad_size+1);
1317  d = Kokkos::View<FadType****,Layout,Device> ("d",4,4,4,4,fad_size+1);
1318  e = Kokkos::View<FadType*****,Layout,Device> ("e",4,4,4,4,4,fad_size+1);
1319  f = Kokkos::View<FadType******,Layout,Device> ("f",4,4,4,4,4,4,fad_size+1);
1320  g = Kokkos::View<FadType*******,Layout,Device> ("g",4,4,4,4,4,4,4,fad_size+1);
1321 #endif
1322 
1323  typedef typename Device::memory_space memory_space;
1324  const bool is_accessible =
1325  Kokkos::Impl::MemorySpaceAccess<Kokkos::HostSpace,
1326  memory_space>::accessible;
1327  if (is_accessible) {
1328  a(0) = FadType(1.0);
1329  f(0,0,0,0,0,0) = FadType(1.0);
1330  g(0,0,0,0,0,0,0) = FadType(1.0);
1331  }
1332 
1333  // Check
1334  success = true;
1335 }
1336 
1338  Kokkos_View_Fad, AssignDifferentStrides, FadType, Layout, Device )
1339 {
1340  typedef Kokkos::View<FadType**,Layout,Device> ViewType1;
1341  typedef Kokkos::View<FadType*,Layout,Device> ViewType2;
1342  typedef typename ViewType1::size_type size_type;
1343  typedef typename ViewType1::host_mirror_type host_view_type1;
1344  typedef typename ViewType2::host_mirror_type host_view_type2;
1345 
1346  const size_type num_rows = global_num_rows;
1347  const size_type num_cols = global_num_cols;
1348  const size_type fad_size = global_fad_size;
1349 
1350  // Create and fill views
1351  ViewType1 v1;
1352 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1353  v1 = ViewType1 ("view1", num_rows, num_cols);
1354 #else
1355  v1 = ViewType1 ("view1", num_rows, num_cols, fad_size+1);
1356 #endif
1357  host_view_type1 h_v1 = Kokkos::create_mirror_view(v1);
1358  for (size_type i=0; i<num_rows; ++i) {
1359  for (size_type j=0; j<num_cols; ++j) {
1360  h_v1(i,j) = generate_fad<FadType>(
1361  num_rows, num_cols, fad_size, i, j);
1362  }
1363  }
1364  Kokkos::deep_copy(v1, h_v1);
1365 
1366  // Launch kernel
1367  ViewType2 v2;
1368 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1369  v2 = ViewType2 ("view2", num_rows);
1370 #else
1371  v2 = ViewType2 ("view2", num_rows, fad_size+1);
1372 #endif
1374 
1375  // Copy back
1376  host_view_type2 h_v2 = Kokkos::create_mirror_view(v2);
1377  Kokkos::deep_copy(h_v2, v2);
1378 
1379  // Check
1380  success = true;
1381  for (size_type i=0; i<num_rows; ++i) {
1382  FadType f =
1383  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(1));
1384  success = success && checkFads(f, h_v2(i), out);
1385  }
1386 }
1387 
1389  Kokkos_View_Fad, ScalarValue, FadType, Layout, Device )
1390 {
1391  typedef typename Sacado::ScalarType<FadType>::type ScalarType;
1392  typedef Kokkos::View<FadType,Layout,Device> ViewType1;
1393  typedef Kokkos::View<ScalarType,Layout,Device> ViewType2;
1394  typedef typename ViewType1::size_type size_type;
1395  typedef typename ViewType1::host_mirror_type host_view_type1;
1396  typedef typename ViewType2::host_mirror_type host_view_type2;
1397 
1398  const int fad_size = global_fad_size;
1399 
1400  // Create and fill views
1401  ViewType1 v1;
1402 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1403  v1 = ViewType1 ("view1");
1404 #else
1405  v1 = ViewType1 ("view1", fad_size+1);
1406 #endif
1407  host_view_type1 h_v1 = Kokkos::create_mirror_view(v1);
1408  h_v1() = generate_fad<FadType>(1, 1, fad_size, 0, 0);
1409  Kokkos::deep_copy(v1, h_v1);
1410 
1411  // Launch kernel
1412  ViewType2 v2 = ViewType2 ("view2");
1413  Kokkos::parallel_for(Kokkos::RangePolicy<Device>(0,1),
1414  KOKKOS_LAMBDA(const size_type i)
1415  {
1416  v2() = Sacado::scalarValue(v1());
1417  });
1418 
1419  // Copy back
1420  host_view_type2 h_v2 = Kokkos::create_mirror_view(v2);
1421  Kokkos::deep_copy(h_v2, v2);
1422 
1423  // Check
1424  success = true;
1425  TEUCHOS_TEST_EQUALITY(h_v1().val(), h_v2(), out, success);
1426 }
1427 
1428 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1429 
1431  Kokkos_View_Fad, DynRankDimensionScalar, FadType, Layout, Device )
1432 {
1433  typedef Kokkos::DynRankView<double,Layout,Device> DoubleViewType;
1434  typedef Kokkos::DynRankView<FadType,Layout,Device> FadViewType;
1435  typedef typename FadViewType::size_type size_type;
1436 
1437  const size_type num_rows = global_num_rows;
1438  const size_type fad_size = global_fad_size;
1439 
1440  // Create views
1441  DoubleViewType v1("view1", num_rows);
1442  FadViewType v2 ("view2", num_rows, fad_size+1);
1443 
1444  // Check dimension scalar works
1445  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v1), 0, out, success);
1446  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1447 }
1448 
1450  Kokkos_View_Fad, DynRankAssignStatic0, FadType, Layout, Device )
1451 {
1452  typedef Kokkos::View<FadType,Layout,Device> StaticViewType;
1453  typedef Kokkos::DynRankView<FadType,Layout,Device> DynamicViewType;
1454  typedef typename StaticViewType::size_type size_type;
1455 
1456  const size_type num_rows = global_num_rows;
1457  const size_type num_cols = global_num_cols;
1458  const size_type fad_size = global_fad_size;
1459 
1460  // Create and fill views
1461  StaticViewType v1("view", fad_size+1);
1462  auto h_v1 = Kokkos::create_mirror_view(v1);
1463  h_v1() = generate_fad<FadType>(num_rows, num_cols, fad_size, size_type(0), size_type(0));
1464  Kokkos::deep_copy(v1, h_v1);
1465 
1466  // Assign static to dynamic
1467  DynamicViewType v2 = v1;
1468 
1469  // Copy back
1470  auto h_v2 = Kokkos::create_mirror_view(v2);
1471  Kokkos::deep_copy(h_v2, v2);
1472 
1473  // Check dimensions are correct
1474  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1475 
1476  // Check values
1477  FadType f =
1478  generate_fad<FadType>(num_rows, num_cols, fad_size, size_type(0), size_type(0));
1479  success = success && checkFads(f, h_v2(), out);
1480 }
1481 
1483  Kokkos_View_Fad, DynRankAssignStatic1, FadType, Layout, Device )
1484 {
1485  typedef Kokkos::View<FadType*,Layout,Device> StaticViewType;
1486  typedef Kokkos::DynRankView<FadType,Layout,Device> DynamicViewType;
1487  typedef typename StaticViewType::size_type size_type;
1488 
1489  const size_type num_rows = global_num_rows;
1490  const size_type num_cols = global_num_cols;
1491  const size_type fad_size = global_fad_size;
1492 
1493  // Create and fill views
1494  StaticViewType v1("view", num_rows, fad_size+1);
1495  auto h_v1 = Kokkos::create_mirror_view(v1);
1496  for (size_type i=0; i<num_rows; ++i)
1497  h_v1(i) =
1498  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(0));
1499  Kokkos::deep_copy(v1, h_v1);
1500 
1501  // Assign static to dynamic
1502  DynamicViewType v2 = v1;
1503 
1504  // Copy back
1505  auto h_v2 = Kokkos::create_mirror_view(v2);
1506  Kokkos::deep_copy(h_v2, v2);
1507 
1508  // Check dimensions are correct
1509  TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
1510  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1511  TEUCHOS_TEST_EQUALITY(v2.stride(0), v1.stride(0), out, success);
1512 
1513  // Check values
1514  for (size_type i=0; i<num_rows; ++i) {
1515  FadType f =
1516  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(0));
1517  success = success && checkFads(f, h_v2(i), out);
1518  }
1519 }
1520 
1522  Kokkos_View_Fad, DynRankAssignStatic2, FadType, Layout, Device )
1523 {
1524  typedef Kokkos::View<FadType**,Layout,Device> StaticViewType;
1525  typedef Kokkos::DynRankView<FadType,Layout,Device> DynamicViewType;
1526  typedef typename StaticViewType::size_type size_type;
1527 
1528  const size_type num_rows = global_num_rows;
1529  const size_type num_cols = global_num_cols;
1530  const size_type fad_size = global_fad_size;
1531 
1532  // Create and fill views
1533  StaticViewType v1("view", num_rows, num_cols, fad_size+1);
1534  auto h_v1 = Kokkos::create_mirror_view(v1);
1535  for (size_type i=0; i<num_rows; ++i)
1536  for (size_type j=0; j<num_cols; ++j)
1537  h_v1(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1538  Kokkos::deep_copy(v1, h_v1);
1539 
1540  // Assign static to dynamic
1541  DynamicViewType v2 = v1;
1542 
1543  // Copy back
1544  auto h_v2 = Kokkos::create_mirror_view(v2);
1545  Kokkos::deep_copy(h_v2, v2);
1546 
1547  // Check dimensions are correct
1548  TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
1549  TEUCHOS_TEST_EQUALITY(v2.extent(1), num_cols, out, success);
1550  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
1551  TEUCHOS_TEST_EQUALITY(v2.stride(0), v1.stride(0), out, success);
1552  TEUCHOS_TEST_EQUALITY(v2.stride(1), v1.stride(1), out, success);
1553 
1554  // Check values
1555  for (size_type i=0; i<num_rows; ++i) {
1556  for (size_type j=0; j<num_cols; ++j) {
1557  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1558  success = success && checkFads(f, h_v2(i,j), out);
1559  }
1560  }
1561 }
1562 
1564  Kokkos_View_Fad, DynRankMultiply, FadType, Layout, Device )
1565 {
1566  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1567  typedef typename ViewType::size_type size_type;
1568  typedef typename ViewType::host_mirror_type host_view_type;
1569 
1570  const size_type num_rows = global_num_rows;
1571  const size_type fad_size = global_fad_size;
1572 
1573  // Create and fill views
1574  ViewType v1("view1", num_rows, fad_size+1);
1575  ViewType v2("view2", num_rows, fad_size+1);
1576  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1577  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
1578  for (size_type i=0; i<num_rows; ++i) {
1579  h_v1(i) = generate_fad<FadType>(
1580  num_rows, size_type(2), fad_size, i, size_type(0));
1581  h_v2(i) = generate_fad<FadType>(
1582  num_rows, size_type(2), fad_size, i, size_type(1));
1583  }
1584  Kokkos::deep_copy(v1, h_v1);
1585  Kokkos::deep_copy(v2, h_v2);
1586 
1587  // Launch kernel
1588  ViewType v3("view3", num_rows, fad_size+1);
1590 
1591  // Copy back
1592  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
1593  Kokkos::deep_copy(h_v3, v3);
1594 
1595  // Check
1596  success = true;
1597  TEUCHOS_TEST_EQUALITY(v3.rank(), 1, out, success);
1598  for (size_type i=0; i<num_rows; ++i) {
1599  FadType f1 =
1600  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
1601  FadType f2 =
1602  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
1603  FadType f3 = f1*f2;
1604  success = success && checkFads(f3, h_v3(i), out);
1605  }
1606 }
1607 
1609  Kokkos_View_Fad, SubdynrankviewCol, FadType, Layout, Device )
1610 {
1611  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1612  typedef typename ViewType::size_type size_type;
1613  typedef typename ViewType::host_mirror_type host_view_type;
1614 
1615  const size_type num_rows = global_num_rows;
1616  const size_type num_cols = global_num_cols;
1617  const size_type fad_size = global_fad_size;
1618 
1619  // Create and fill view
1620  ViewType v("view", num_rows, num_cols, fad_size+1);
1621  host_view_type h_v = Kokkos::create_mirror_view(v);
1622  for (size_type i=0; i<num_rows; ++i) {
1623  for (size_type j=0; j<num_cols; ++j) {
1624  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1625  h_v(i,j) = f;
1626  }
1627  }
1628  Kokkos::deep_copy(v, h_v);
1629 
1630  // Create subview of first column
1631  size_type col = 1;
1632  auto s = Kokkos::subdynrankview(v, Kokkos::ALL(), col);
1633 
1634  // Copy back
1635  typedef decltype(s) SubviewType;
1636  typedef typename SubviewType::host_mirror_type HostSubviewType;
1637 
1638  // Note: don't create h_s through create_mirror_view and deep_copy
1639  // since Kokkos doesn't support deep_copy of non-contiguous views
1640  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1641  //Kokkos::deep_copy(h_s, s);
1642  HostSubviewType h_s = Kokkos::subdynrankview(h_v, Kokkos::ALL(), col);
1643 
1644  // Check
1645  success = true;
1646  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1647  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1648  TEUCHOS_TEST_EQUALITY(h_s.extent(0), num_rows, out, success);
1649  TEUCHOS_TEST_EQUALITY(h_s.extent(1), 1, out, success);
1650  TEUCHOS_TEST_EQUALITY(h_s.extent(7), 1, out, success);
1651 
1652  for (size_type i=0; i<num_rows; ++i) {
1653  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
1654  success = success && checkFads(f, h_s(i), out);
1655  }
1656 }
1657 
1659  Kokkos_View_Fad, SubdynrankviewRow, FadType, Layout, Device )
1660 {
1661  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1662  typedef typename ViewType::size_type size_type;
1663  typedef typename ViewType::host_mirror_type host_view_type;
1664 
1665  const size_type num_rows = global_num_rows;
1666  const size_type num_cols = global_num_cols;
1667  const size_type num_planes = 9;
1668  const size_type fad_size = global_fad_size;
1669 
1670  // Create and fill view
1671  ViewType v("view", num_rows, num_cols, num_planes, fad_size+1);
1672  host_view_type h_v = Kokkos::create_mirror_view(v);
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  for (size_type k=0; k<num_planes; ++k) {
1677  h_v(i,j,k) = (k+1)*f;
1678  }
1679  }
1680  }
1681  Kokkos::deep_copy(v, h_v);
1682 
1683  // Create subview of first column
1684  size_type row = 2;
1685  auto s = Kokkos::subdynrankview(v, row, Kokkos::ALL(), Kokkos::ALL());
1686 
1687  // Copy back
1688  typedef decltype(s) SubviewType;
1689  typedef typename SubviewType::host_mirror_type HostSubviewType;
1690 
1691  // Note: don't create h_s through create_mirror_view and deep_copy
1692  // since Kokkos doesn't support deep_copy of non-contiguous views
1693  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1694  //Kokkos::deep_copy(h_s, s);
1695  HostSubviewType h_s =
1696  Kokkos::subdynrankview(h_v, row, Kokkos::ALL(), Kokkos::ALL());
1697 
1698  // Check
1699  success = true;
1700  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1701  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1702  TEUCHOS_TEST_EQUALITY(h_s.extent(0), num_cols, out, success);
1703  TEUCHOS_TEST_EQUALITY(h_s.extent(1), num_planes, out, success);
1704  TEUCHOS_TEST_EQUALITY(h_s.extent(2), 1, out, success);
1705  TEUCHOS_TEST_EQUALITY(h_s.extent(7), 1, out, success);
1706 
1707  for (size_type j=0; j<num_cols; ++j) {
1708  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, row, j);
1709  for (size_type k=0; k<num_planes; ++k) {
1710  FadType g = (k+1)*f;
1711  success = success && checkFads(g, h_s(j,k), out);
1712  }
1713  }
1714 }
1715 
1717  Kokkos_View_Fad, SubdynrankviewScalar, FadType, Layout, Device )
1718 {
1719  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
1720  typedef typename ViewType::size_type size_type;
1721  typedef typename ViewType::host_mirror_type host_view_type;
1722 
1723  const size_type num_rows = global_num_rows;
1724  const size_type num_cols = global_num_cols;
1725  const size_type fad_size = global_fad_size;
1726 
1727  // Create and fill view
1728  ViewType v("view", num_rows, num_cols, fad_size+1);
1729  host_view_type h_v = Kokkos::create_mirror_view(v);
1730  for (size_type i=0; i<num_rows; ++i) {
1731  for (size_type j=0; j<num_cols; ++j) {
1732  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1733  h_v(i,j) = f;
1734  }
1735  }
1736  Kokkos::deep_copy(v, h_v);
1737 
1738  // Create subview of first column
1739  size_type row = 3;
1740  size_type col = 1;
1741  auto s = Kokkos::subdynrankview(v, row, col);
1742 
1743  // Copy back
1744  typedef decltype(s) SubviewType;
1745  typedef typename SubviewType::host_mirror_type HostSubviewType;
1746 
1747  // Note: don't create h_s through create_mirror_view and deep_copy
1748  // since Kokkos doesn't support deep_copy of non-contiguous views
1749  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1750  //Kokkos::deep_copy(h_s, s);
1751  HostSubviewType h_s = Kokkos::subdynrankview(h_v, row, col);
1752 
1753  // Check
1754  success = true;
1755  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1756  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1757  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, row, col);
1758  success = success && checkFads(f, h_s(), out);
1759 }
1760 
1761 #else
1762 
1764  Kokkos_View_Fad, DynRankDimensionScalar, FadType, Layout, Device ) {}
1766  Kokkos_View_Fad, DynRankAssignStatic0, FadType, Layout, Device ) {}
1768  Kokkos_View_Fad, DynRankAssignStatic1, FadType, Layout, Device ) {}
1770  Kokkos_View_Fad, DynRankAssignStatic2, FadType, Layout, Device ) {}
1772  Kokkos_View_Fad, DynRankMultiply, FadType, Layout, Device ) {}
1774  Kokkos_View_Fad, SubdynrankviewCol, FadType, Layout, Device ) {}
1776  Kokkos_View_Fad, SubdynrankviewRow, FadType, Layout, Device ) {}
1778  Kokkos_View_Fad, SubdynrankviewScalar, FadType, Layout, Device ) {}
1779 
1780 #endif
1781 
1783  Kokkos_View_Fad, Subview, FadType, Layout, Device )
1784 {
1785  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1786  typedef typename ViewType::size_type size_type;
1787  typedef typename ViewType::host_mirror_type host_view_type;
1788 
1789  const size_type num_rows = global_num_rows;
1790  const size_type num_cols = global_num_cols;
1791  const size_type fad_size = global_fad_size;
1792 
1793  // Create and fill view
1794  ViewType v;
1795 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1796  v = ViewType ("view", num_rows, num_cols);
1797 #else
1798  v = ViewType ("view", num_rows, num_cols, fad_size+1);
1799 #endif
1800  host_view_type h_v = Kokkos::create_mirror_view(v);
1801  for (size_type i=0; i<num_rows; ++i) {
1802  for (size_type j=0; j<num_cols; ++j) {
1803  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1804  h_v(i,j) = f;
1805  }
1806  }
1807  Kokkos::deep_copy(v, h_v);
1808 
1809  // Create subview of first column
1810  size_type col = 1;
1811  auto s = Kokkos::subview(v, Kokkos::ALL(), col);
1812 
1813  // Copy back
1814  typedef decltype(s) SubviewType;
1815  typedef typename SubviewType::host_mirror_type HostSubviewType;
1816 
1817  // Note: don't create h_s through create_mirror_view and deep_copy
1818  // since Kokkos doesn't support deep_copy of non-contiguous views
1819  //HostSubviewType h_s = Kokkos::create_mirror_view(s);
1820  //Kokkos::deep_copy(h_s, s);
1821  HostSubviewType h_s = Kokkos::subview(h_v, Kokkos::ALL(), col);
1822 
1823  // Check
1824  success = true;
1825 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1826  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
1827  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
1828 #endif
1829  for (size_type i=0; i<num_rows; ++i) {
1830  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
1831  success = success && checkFads(f, h_s(i), out);
1832  }
1833 }
1834 
1836  Kokkos_View_Fad, Subview2, FadType, Layout, Device )
1837 {
1838  typedef Kokkos::View<FadType***,Layout,Device> ViewType;
1839  typedef typename ViewType::host_mirror_type host_view_type;
1840 
1841  // Test various subview operations to check the resulting indexing is correct.
1842  // We only need to run these tests on the host because the indexing does
1843  // not depend on the device.
1844 
1845  const int num_cell = 5;
1846  const int num_qp = 4;
1847  const int num_dim = 3;
1848  const int num_deriv = 2;
1849 
1850  // Create and fill view
1851  host_view_type v;
1852 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1853  v = host_view_type ("view", num_cell, num_qp, num_dim);
1854 #else
1855  v = host_view_type ("view", num_cell, num_qp, num_dim, num_deriv+1);
1856 #endif
1857  for (int cell=0; cell < num_cell; ++cell) {
1858  for (int qp=0; qp < num_qp; ++qp) {
1859  for (int dim = 0; dim < num_dim; ++dim) {
1860  v(cell,qp,dim).val() = 100.*cell + 10.*qp + 1.*dim;
1861  for (int deriv = 0; deriv < num_deriv; ++deriv) {
1862  v(cell,qp,dim).fastAccessDx(deriv) = v(cell,qp,dim).val() + (1.0*deriv)/10.;
1863  }
1864  }
1865  }
1866  }
1867 
1868  success = true;
1869 
1870  out << "checking subview(v,ALL,*,*)..." << std::endl;
1871  for (int qp=0; qp < num_qp; ++qp) {
1872  for (int dim=0; dim < num_dim; ++dim) {
1873  auto v_tmp = subview(v,Kokkos::ALL(),qp,dim);
1874  for (int cell=0; cell < num_cell; ++cell) {
1875  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1876  success = success && checkFads(v(cell,qp,dim), v_tmp(cell), out);
1877  }
1878  }
1879  }
1880 
1881  out << "checking subview(v,*,ALL,*)..." << std::endl;
1882  for (int cell=0; cell < num_cell; ++cell) {
1883  for (int dim=0; dim < num_dim; ++dim) {
1884  auto v_tmp = subview(v,cell,Kokkos::ALL(),dim);
1885  for (int qp=0; qp < num_qp; ++qp) {
1886  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1887  success = success && checkFads(v(cell,qp,dim), v_tmp(qp), out);
1888  }
1889  }
1890  }
1891 
1892  out << "checking subview(v,*,*,ALL)..." << std::endl;
1893  for (int cell=0; cell < num_cell; ++cell) {
1894  for (int qp=0; qp < num_qp; ++qp) {
1895  auto v_tmp = subview(v,cell,qp,Kokkos::ALL());
1896  for (int dim=0; dim < num_dim; ++dim) {
1897  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1898  success = success && checkFads(v(cell,qp,dim), v_tmp(dim), out);
1899  }
1900  }
1901  }
1902 
1903  out << "checking subview(v,ALL,ALL,*)..." << std::endl;
1904  for (int dim=0; dim < num_dim; ++dim) {
1905  auto v_tmp = subview(v,Kokkos::ALL(),Kokkos::ALL(),dim);
1906  for (int cell=0; cell < num_cell; ++cell) {
1907  for (int qp=0; qp < num_qp; ++qp) {
1908  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1909  success = success && checkFads(v(cell,qp,dim), v_tmp(cell,qp), out);
1910  }
1911  }
1912  }
1913 
1914  out << "checking subview(v,*,ALL,ALL)..." << std::endl;
1915  for (int cell=0; cell < num_cell; ++cell) {
1916  auto v_tmp = subview(v,cell,Kokkos::ALL(),Kokkos::ALL());
1917  for (int qp=0; qp < num_qp; ++qp) {
1918  for (int dim=0; dim < num_dim; ++dim) {
1919  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1920  success = success && checkFads(v(cell,qp,dim), v_tmp(qp,dim), out);
1921  }
1922  }
1923  }
1924 
1925  out << "checking subview(v,ALL,*,ALL)..." << std::endl;
1926  for (int qp=0; qp < num_qp; ++qp) {
1927  auto v_tmp = subview(v,Kokkos::ALL(),qp,Kokkos::ALL());
1928  for (int cell=0; cell < num_cell; ++cell) {
1929  for (int dim=0; dim < num_dim; ++dim) {
1930  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1931  success = success && checkFads(v(cell,qp,dim), v_tmp(cell,dim), out);
1932  }
1933  }
1934  }
1935 
1936  out << "checking subview(v,range,range,range)..." << std::endl;
1937  auto v_tmp = subview(v,std::make_pair(1,5),std::make_pair(1,4),std::make_pair(1,3));
1938  for (int cell=1; cell < num_cell; ++cell) {
1939  for (int qp=1; qp < num_qp; ++qp) {
1940  for (int dim=1; dim < num_dim; ++dim) {
1941  out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1942  success = success && checkFads(v(cell,qp,dim), v_tmp(cell-1,qp-1,dim-1), out);
1943  }
1944  }
1945  }
1946 }
1947 
1948 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
1950  Kokkos_View_Fad, ConstViewAssign, FadType, Layout, Device )
1951 {
1952  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1953  typedef Kokkos::View<const FadType,Layout,Device> ConstViewType;
1954  typedef typename ViewType::size_type size_type;
1955  typedef typename ViewType::host_mirror_type host_view_type;
1956  typedef typename ViewType::execution_space exec_space;
1957 
1958  const size_type num_rows = global_num_rows;
1959  const size_type fad_size = global_fad_size;
1960 
1961  // Create and fill view
1962 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1963  ViewType v1("view1", num_rows);
1964 #else
1965  ViewType v1("view1", num_rows, fad_size+1);
1966 #endif
1967  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1968  for (size_type i=0; i<num_rows; ++i) {
1969  FadType f = generate_fad<FadType>(num_rows, size_type(1), fad_size, i,
1970  size_type(0));
1971  h_v1(i) = f;
1972  }
1973  Kokkos::deep_copy(v1, h_v1);
1974 
1975 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1976  ViewType v2("view2", num_rows);
1977 #else
1978  ViewType v2("view2", num_rows, fad_size+1);
1979 #endif
1980 
1981  static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
1982 #if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
1983  const bool use_team =
1987  ( stride > 1 );
1988 #elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
1989  const bool use_team =
1994 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
1995  const bool use_team =
1999  ( stride > 1 );
2000 #elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
2001  const bool use_team =
2006 #else
2007  const bool use_team = false;
2008 #endif
2009 
2010  if (use_team) {
2011  typedef Kokkos::TeamPolicy<exec_space> team_policy;
2012  Kokkos::parallel_for(team_policy(num_rows, 1, stride),
2013  KOKKOS_LAMBDA(typename team_policy::member_type team)
2014  {
2015  const int i = team.league_rank();
2016  typename ConstViewType::reference_type x = v1(i);
2017  v2(i) = x;
2018  });
2019  }
2020  else {
2021  Kokkos::parallel_for(Kokkos::RangePolicy<exec_space>(0,num_rows),
2022  KOKKOS_LAMBDA(const int i)
2023  {
2024  typename ConstViewType::reference_type x = v1(i);
2025  v2(i) = x;
2026  });
2027  }
2028 
2029  // Copy back
2030  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
2031  Kokkos::deep_copy(h_v2, v2);
2032 
2033  // Check
2034  success = true;
2035  for (size_type i=0; i<num_rows; ++i) {
2036  FadType f = generate_fad<FadType>(num_rows, size_type(1), fad_size, i,
2037  size_type(0));
2038  success = success && checkFads(f, h_v2(i), out);
2039  }
2040 }
2041 #else
2043  Kokkos_View_Fad, ConstViewAssign, FadType, Layout, Device ) {}
2044 #endif
2045 
2046 // Tests that require view spec
2047 
2048 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2050  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
2051 {
2052  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2053  typedef typename FadType::value_type value_type;
2054  typedef typename ViewType::size_type size_type;
2055 
2056  const size_type num_rows = global_num_rows;
2057  const size_type num_cols = global_num_cols;
2058  const size_type fad_size = global_fad_size;
2059 
2060  // Compute shared memory size for View
2061  const size_type shmem_size =
2062  ViewType::shmem_size(num_rows, num_cols, fad_size+1);
2063 
2064  // Check
2065  ViewType v;
2066 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2067  v = ViewType ("view", num_rows, num_cols);
2068 #else
2069  v = ViewType ("view", num_rows, num_cols, fad_size+1);
2070 #endif
2071 #if defined(SACADO_HAS_NEW_KOKKOS_VIEW_IMPL) || (defined(SACADO_DISABLE_FAD_VIEW_SPEC) && !defined(KOKKOS_ENABLE_IMPL_VIEW_LEGACY))
2072  size_t scratch_value_alignment =
2073  Kokkos::max({sizeof(value_type),
2074  alignof(value_type),
2075  static_cast<size_t>(
2076  ViewType::execution_space::scratch_memory_space::ALIGN)});
2077  const size_type shmem_size_expected =
2078  sizeof(value_type) * global_num_rows * global_num_cols * (fad_size+1) + scratch_value_alignment;
2079 #else
2080  const size_type align = 8;
2081  const size_type mask = align - 1;
2082  const size_type shmem_size_expected =
2083  (( sizeof(value_type) * global_num_rows * global_num_cols * (fad_size+1) + mask ) & ~mask) + sizeof(typename ViewType::traits::value_type);
2084 #endif
2085  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
2086 }
2087 
2089  Kokkos_View_Fad, Unmanaged, FadType, Layout, Device )
2090 {
2091  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2092  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2093 
2094  typedef typename FadType::value_type scalar_type;
2095  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2096  typedef Kokkos::View<FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> FadViewType;
2097  typedef typename ViewType::size_type size_type;
2098  typedef typename ViewType::host_mirror_type host_view_type;
2099  typedef typename FadViewType::host_mirror_type fad_host_view_type;
2100 
2101  const size_type num_rows = global_num_rows;
2102  const size_type num_cols = global_num_cols;
2103  const size_type fad_size = global_fad_size;
2104 
2105  // Create and fill view
2106  ViewType v;
2107  host_view_type h_v;
2110  v = ViewType ("view", fad_size+1, num_rows, num_cols);
2111  h_v = Kokkos::create_mirror_view(v);
2112  for (size_type i=0; i<num_rows; ++i) {
2113  for (size_type j=0; j<num_cols; ++j) {
2114  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2115  for (size_type k=0; k<fad_size; k++)
2116  h_v(k,i,j) = f.dx(k);
2117  h_v(fad_size,i,j) = f.val();
2118  }
2119  }
2120  }
2121  else {
2122  v = ViewType ("view", num_rows, num_cols, fad_size+1);
2123  h_v = Kokkos::create_mirror_view(v);
2124  for (size_type i=0; i<num_rows; ++i) {
2125  for (size_type j=0; j<num_cols; ++j) {
2126  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2127  for (size_type k=0; k<fad_size; k++)
2128  h_v(i,j,k) = f.dx(k);
2129  h_v(i,j,fad_size) = f.val();
2130  }
2131  }
2132  }
2133  Kokkos::deep_copy(v, h_v);
2134 
2135  // Create unmanaged view
2136  FadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
2137  fad_host_view_type h_v_fad;
2138 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2139  v_fad = FadViewType ( v.data(), num_rows, num_cols);
2140  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2141 #else
2142  v_fad = FadViewType ( v.data(), num_rows, num_cols, fad_size+1);
2143  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2144 #endif
2145 
2146  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2147  Kokkos::deep_copy(h_v_fad, v_fad);
2148 
2149  // Check
2150  success = true;
2151  for (size_type i=0; i<num_rows; ++i) {
2152  for (size_type j=0; j<num_cols; ++j) {
2153  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2154  success = success && checkFads(f, h_v_fad(i,j), out);
2155  }
2156  }
2157 }
2158 
2160  Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device )
2161 {
2162  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2163  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2164 
2165  typedef typename FadType::value_type scalar_type;
2166  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2167  typedef Kokkos::View<FadType**,TestLayout,Device> FadViewType;
2168  typedef typename ViewType::size_type size_type;
2169  typedef typename ViewType::host_mirror_type host_view_type;
2170  typedef typename FadViewType::host_mirror_type fad_host_view_type;
2171 
2172  const size_type num_rows = global_num_rows;
2173  const size_type num_cols = global_num_cols;
2174  const size_type fad_size = global_fad_size;
2175 
2176  // Create and fill view
2177  ViewType v;
2178  host_view_type h_v;
2181  v = ViewType ("view", fad_size+1, num_rows, num_cols);
2182  h_v = Kokkos::create_mirror_view(v);
2183  for (size_type i=0; i<num_rows; ++i) {
2184  for (size_type j=0; j<num_cols; ++j) {
2185  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2186  for (size_type k=0; k<fad_size; k++)
2187  h_v(k,i,j) = f.dx(k);
2188  h_v(fad_size,i,j) = f.val();
2189  }
2190  }
2191  }
2192  else {
2193  v = ViewType ("view", num_rows, num_cols, fad_size+1);
2194  h_v = Kokkos::create_mirror_view(v);
2195  for (size_type i=0; i<num_rows; ++i) {
2196  for (size_type j=0; j<num_cols; ++j) {
2197  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2198  for (size_type k=0; k<fad_size; k++)
2199  h_v(i,j,k) = f.dx(k);
2200  h_v(i,j,fad_size) = f.val();
2201  }
2202  }
2203  }
2204  Kokkos::deep_copy(v, h_v);
2205 
2206  // Create unmanaged view
2207  FadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
2208  fad_host_view_type h_v_fad;
2209 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2210  v_fad = FadViewType ( v.data(), num_rows, num_cols);
2211  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2212 #else
2213  v_fad = FadViewType ( v.data(), num_rows, num_cols, fad_size+1);
2214  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2215 #endif
2216 
2217  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2218  Kokkos::deep_copy(h_v_fad, v_fad);
2219 
2220  // Check
2221  success = true;
2222  for (size_type i=0; i<num_rows; ++i) {
2223  for (size_type j=0; j<num_cols; ++j) {
2224  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2225  success = success && checkFads(f, h_v_fad(i,j), out);
2226  }
2227  }
2228 }
2229 
2231  Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device )
2232 {
2233  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2234  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2235 
2236  typedef typename FadType::value_type scalar_type;
2237  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2238  typedef Kokkos::View<const scalar_type***,TestLayout,Device> ConstViewType;
2239  typedef Kokkos::View<FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> FadViewType;
2240  typedef Kokkos::View<const FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> ConstFadViewType;
2241  typedef typename ViewType::size_type size_type;
2242  typedef typename ViewType::host_mirror_type host_view_type;
2243  typedef typename FadViewType::host_mirror_type fad_host_view_type;
2244 
2245  const size_type num_rows = global_num_rows;
2246  const size_type num_cols = global_num_cols;
2247  const size_type fad_size = global_fad_size;
2248 
2249  // Create and fill view
2250  ViewType v;
2251  host_view_type h_v;
2254  v = ViewType ("view", fad_size+1, num_rows, num_cols);
2255  h_v = Kokkos::create_mirror_view(v);
2256  for (size_type i=0; i<num_rows; ++i) {
2257  for (size_type j=0; j<num_cols; ++j) {
2258  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2259  for (size_type k=0; k<fad_size; k++)
2260  h_v(k,i,j) = f.dx(k);
2261  h_v(fad_size,i,j) = f.val();
2262  }
2263  }
2264  }
2265  else {
2266  v = ViewType ("view", num_rows, num_cols, fad_size+1);
2267  h_v = Kokkos::create_mirror_view(v);
2268  for (size_type i=0; i<num_rows; ++i) {
2269  for (size_type j=0; j<num_cols; ++j) {
2270  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2271  for (size_type k=0; k<fad_size; k++)
2272  h_v(i,j,k) = f.dx(k);
2273  h_v(i,j,fad_size) = f.val();
2274  }
2275  }
2276  }
2277  Kokkos::deep_copy(v, h_v);
2278  ConstViewType v_const = v;
2279 
2280  // Create unmanaged view
2281 
2282  ConstFadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
2283  fad_host_view_type h_v_fad;
2284 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2285  v_fad = ConstFadViewType ( v_const.data(), num_rows, num_cols);
2286  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2287 #else
2288  v_fad = ConstFadViewType ( v_const.data(), num_rows, num_cols, fad_size+1);
2289  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2290 #endif
2291 
2292  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2293  Kokkos::deep_copy(h_v_fad, v_fad);
2294 
2295  // Check
2296  success = true;
2297  for (size_type i=0; i<num_rows; ++i) {
2298  for (size_type j=0; j<num_cols; ++j) {
2299  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2300  success = success && checkFads(f, h_v_fad(i,j), out);
2301  }
2302  }
2303 }
2304 
2306  Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device )
2307 {
2308  // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2309  typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2310  typedef typename FadType::value_type scalar_type;
2311  typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2312  typedef Kokkos::View<const scalar_type***,TestLayout,Device> ConstViewType;
2313  typedef Kokkos::View<FadType**,TestLayout,Device> FadViewType;
2314  typedef Kokkos::View<const FadType**,TestLayout,Device> ConstFadViewType;
2315  typedef typename ViewType::size_type size_type;
2316  typedef typename ViewType::host_mirror_type host_view_type;
2317  typedef typename FadViewType::host_mirror_type fad_host_view_type;
2318 
2319  const size_type num_rows = global_num_rows;
2320  const size_type num_cols = global_num_cols;
2321  const size_type fad_size = global_fad_size;
2322 
2323  // Create and fill view
2324  ViewType v;
2325  host_view_type h_v;
2328  v = ViewType ("view", fad_size+1, num_rows, num_cols);
2329  h_v = Kokkos::create_mirror_view(v);
2330  for (size_type i=0; i<num_rows; ++i) {
2331  for (size_type j=0; j<num_cols; ++j) {
2332  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2333  for (size_type k=0; k<fad_size; k++)
2334  h_v(k,i,j) = f.dx(k);
2335  h_v(fad_size,i,j) = f.val();
2336  }
2337  }
2338  }
2339  else {
2340  v = ViewType ("view", num_rows, num_cols, fad_size+1);
2341  h_v = Kokkos::create_mirror_view(v);
2342  for (size_type i=0; i<num_rows; ++i) {
2343  for (size_type j=0; j<num_cols; ++j) {
2344  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2345  for (size_type k=0; k<fad_size; k++)
2346  h_v(i,j,k) = f.dx(k);
2347  h_v(i,j,fad_size) = f.val();
2348  }
2349  }
2350  }
2351  Kokkos::deep_copy(v, h_v);
2352  ConstViewType v_const = v;
2353 
2354  // Create unmanaged view
2355  ConstFadViewType v_fad;
2356  fad_host_view_type h_v_fad;
2357 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2358  v_fad = ConstFadViewType (v_const.data(), num_rows, num_cols);
2359  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2360 #else
2361  v_fad = ConstFadViewType (v_const.data(), num_rows, num_cols, fad_size+1);
2362  h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2363 #endif
2364 
2365  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2366  Kokkos::deep_copy(h_v_fad, v_fad);
2367 
2368  // Check
2369  success = true;
2370  for (size_type i=0; i<num_rows; ++i) {
2371  for (size_type j=0; j<num_cols; ++j) {
2372  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2373  success = success && checkFads(f, h_v_fad(i,j), out);
2374  }
2375  }
2376 }
2377 
2378 // This test checks we can allocate a view
2379 // with SFad without specifying the fad size in the constructor
2381  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device )
2382 {
2383  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2384  typedef typename ViewType::size_type size_type;
2385  typedef typename ViewType::host_mirror_type host_view_type;
2386 
2387  const size_type num_rows = global_num_rows;
2388  const size_type num_cols = global_num_cols;
2389  const size_type fad_size = global_fad_size;
2390 
2391  // Create and fill view
2392  ViewType v("view", num_rows, num_cols);
2393  host_view_type h_v = Kokkos::create_mirror_view(v);
2394  for (size_type i=0; i<num_rows; ++i) {
2395  for (size_type j=0; j<num_cols; ++j) {
2396  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2397  h_v(i,j) = f;
2398  }
2399  }
2400  Kokkos::deep_copy(v, h_v);
2401 
2402  // Copy back
2403  Kokkos::deep_copy(h_v, v);
2404 
2405  // Check
2406  success = true;
2407  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v), fad_size+1, out, success);
2408  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v), fad_size+1, out, success);
2409  for (size_type i=0; i<num_rows; ++i) {
2410  for (size_type j=0; j<num_cols; ++j) {
2411  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2412  success = success && checkFads(f, h_v(i,j), out);
2413  }
2414  }
2415 }
2416 
2417 #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
2419  Kokkos_View_Fad, Partition, FadType, Layout, Device )
2420 {
2421 #if !defined(SACADO_VIEW_CUDA_HIERARCHICAL) && !defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
2422  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2423  typedef typename ViewType::size_type size_type;
2424  typedef typename ViewType::host_mirror_type host_view_type;
2425 
2426  const size_type num_rows = global_num_rows;
2427  const size_type num_cols = global_num_cols;
2428  const size_type fad_size = global_fad_size;
2429 
2430  // Create and fill view
2431  ViewType v;
2432 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2433  v = ViewType ("view", num_rows, num_cols);
2434 #else
2435  v = ViewType ("view", num_rows, num_cols, fad_size+1);
2436 #endif
2437  host_view_type h_v = Kokkos::create_mirror_view(v);
2438 
2439  for (size_type i=0; i<num_rows; ++i) {
2440  for (size_type j=0; j<num_cols; ++j) {
2441  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2442  h_v(i,j) = f;
2443  }
2444  }
2445  Kokkos::deep_copy(v, h_v);
2446 
2447  // Copy back
2448  Kokkos::deep_copy(h_v, v);
2449 
2450  // Partition derivative array of h_v into 2, first one starting at index 0,
2451  // the second at 1
2452  const size_type stride = 2;
2453  auto h_v1 = Kokkos::partition<2>(h_v, 0, stride);
2454  auto h_v2 = Kokkos::partition<2>(h_v, 1, stride);
2455 
2456  // Check
2457  const size_type fad_size_1 = (fad_size + stride - 0 - 1) / stride;
2458  const size_type fad_size_2 = (fad_size + stride - 1 - 1) / stride;
2459  success = true;
2460  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v1), fad_size_1+1, out, success);
2461  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v2), fad_size_2+1, out, success);
2462  for (size_type i=0; i<num_rows; ++i) {
2463  for (size_type j=0; j<num_cols; ++j) {
2464  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2465  Sacado::Fad::DFad<double> f1( fad_size_1, f.val() );
2466  Sacado::Fad::DFad<double> f2( fad_size_2, f.val() );
2467  for (unsigned int k=0; k<fad_size_1; ++k)
2468  if (2*k < fad_size) f1.fastAccessDx(k) = f.dx(2*k);
2469  for (unsigned int k=0; k<fad_size_2; ++k)
2470  if (2*k+1 < fad_size) f2.fastAccessDx(k) = f.dx(2*k+1);
2471  success = success && checkFads(f1, h_v1(i,j), out);
2472  success = success && checkFads(f2, h_v2(i,j), out);
2473  }
2474  }
2475 #endif
2476 }
2477 #endif // SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
2478 
2480  Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, FadType, Layout, Device )
2481 {
2482  typedef Kokkos::View<FadType**,Kokkos::LayoutContiguous<Layout>,Device> ContViewType;
2483  typedef Kokkos::View<FadType**,Kokkos::LayoutStride,Device> StrideViewType;
2484  typedef typename ContViewType::size_type size_type;
2485  typedef typename ContViewType::host_mirror_type cont_host_view_type;
2486  typedef typename StrideViewType::host_mirror_type stride_host_view_type;
2487 
2488  const size_type num_rows = global_num_rows;
2489  const size_type num_cols = global_num_cols;
2490  const size_type fad_size = global_fad_size;
2491 
2492  // Create and fill view
2493  ContViewType v;
2494 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2495  v = ContViewType ("view", num_rows, num_cols);
2496 #else
2497  v = ContViewType ("view", num_rows, num_cols, fad_size+1);
2498 #endif
2499  cont_host_view_type h_v = Kokkos::create_mirror_view(v);
2500 
2501  for (size_type i=0; i<num_rows; ++i) {
2502  for (size_type j=0; j<num_cols; ++j) {
2503  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2504  h_v(i,j) = f;
2505  }
2506  }
2507  Kokkos::deep_copy(v, h_v);
2508 
2509  // Assign to LayoutStride view
2510  StrideViewType vs = v;
2511 
2512  // Copy back
2513  // Note: don't create h_vs through create_mirror_view and deep_copy
2514  // since Kokkos doesn't support deep_copy of non-contiguous views
2515  //stride_host_view_type h_vs = Kokkos::create_mirror_view(vs);
2516  //Kokkos::deep_copy(h_vs, vs);
2517  stride_host_view_type h_vs = h_v;
2518 
2519  // Check
2520  success = true;
2521  TEUCHOS_TEST_EQUALITY(h_vs.extent(0), num_rows, out, success);
2522  TEUCHOS_TEST_EQUALITY(h_vs.extent(1), num_cols, out, success);
2523  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_vs), fad_size+1, out, success);
2524  for (size_type i=0; i<num_rows; ++i) {
2525  for (size_type j=0; j<num_cols; ++j) {
2526  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2527  success = success && checkFads(f, h_vs(i,j), out);
2528  }
2529  }
2530 }
2531 
2533  Kokkos_View_Fad, CommonViewAllocMixedSpec, FadType, Layout, Device )
2534 {
2535  typedef Kokkos::View<FadType**,Kokkos::LayoutContiguous<Layout>,Device> ContViewType;
2536  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2537  typedef typename ContViewType::size_type size_type;
2538 
2539  const size_type num_rows = global_num_rows;
2540  const size_type num_cols = global_num_cols;
2541  const size_type fad_size = global_fad_size;
2542 
2543  // Create contiguous view
2544  ContViewType v1;
2545 #if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2546  v1 = ContViewType ("view", num_rows, num_cols);
2547 #else
2548  v1 = ContViewType ("view", num_rows, num_cols, fad_size+1);
2549 #endif
2550 
2551  // Create non-contiguous view using commen_view_alloc_prop
2552  auto cprop = Kokkos::common_view_alloc_prop(v1);
2553  ViewType v2(Kokkos::view_alloc("v2",cprop), num_rows, num_cols);
2554 
2555  // Check dimensions are correct for v2
2556  success = true;
2557  TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
2558  TEUCHOS_TEST_EQUALITY(v2.extent(1), num_cols, out, success);
2559  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
2560 }
2561 
2562 #else
2563 
2565  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
2566 {
2567  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2568  typedef typename ViewType::size_type size_type;
2569 
2570  const size_type num_rows = global_num_rows;
2571  const size_type num_cols = global_num_cols;
2572 
2573  // Compute shared memory size for View
2574  const size_type shmem_size =
2575  ViewType::shmem_size(num_rows, num_cols);
2576 
2577  // Check
2578 #if !defined(KOKKOS_ENABLE_IMPL_VIEW_LEGACY)
2579  size_t scratch_value_alignment =
2580  Kokkos::max({sizeof(FadType),
2581  alignof(FadType),
2582  static_cast<size_t>(
2583  ViewType::execution_space::scratch_memory_space::ALIGN)});
2584  const size_type shmem_size_expected =
2585  sizeof(FadType) * global_num_rows * global_num_cols + scratch_value_alignment;
2586 #else
2587  static const size_type align = 8;
2588  static const size_type mask = align - 1;
2589  const size_type shmem_size_expected =
2590  (( sizeof(FadType) * global_num_rows * global_num_cols + mask ) & ~mask) + sizeof(typename ViewType::traits::value_type);
2591 #endif
2592  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
2593 }
2594 
2596  Kokkos_View_Fad, Unmanaged, FadType, Layout, Device ) {}
2597 
2599  Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device ) {}
2600 
2602  Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device ) {}
2603 
2605  Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device ) {}
2606 
2608  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device ) {}
2609 
2611  Kokkos_View_Fad, Partition, FadType, Layout, Device ) {}
2612 
2614  Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, FadType, Layout, Device ) {}
2615 
2617  Kokkos_View_Fad, CommonViewAllocMixedSpec, FadType, Layout, Device ) {}
2618 
2619 #endif
2620 
2621 #define VIEW_FAD_TESTS_FLD( F, L, D ) \
2622  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Size, F, L, D ) \
2623  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy, F, L, D ) \
2624  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantScalar, F, L, D ) \
2625  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantZero, F, L, D ) \
2626  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFad, F, L, D ) \
2627  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFadFull, F, L, D ) \
2628  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, LocalDeepCopy, F, L, D ) \
2629  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, LocalDeepCopyTeam, F, L, D ) \
2630  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ScalarAssign, F, L, D ) \
2631  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ValueAssign, F, L, D ) \
2632  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Resize, F, L, D ) \
2633  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged, F, L, D ) \
2634  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged2, F, L, D ) \
2635  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst, F, L, D ) \
2636  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst2, F, L, D ) \
2637  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Multiply, F, L, D ) \
2638  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyUpdate, F, L, D ) \
2639  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyConst, F, L, D ) \
2640  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyMixed, F, L, D ) \
2641  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Rank8, F, L, D ) \
2642  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Roger, F, L, D ) \
2643  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicAdd, F, L, D ) \
2644  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignDifferentStrides, F, L, D ) \
2645  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ScalarValue, F, L, D ) \
2646  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankDimensionScalar, F, L, D ) \
2647  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic0, F, L, D ) \
2648  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic1, F, L, D ) \
2649  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic2, F, L, D ) \
2650  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankMultiply, F, L, D ) \
2651  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewCol, F, L, D ) \
2652  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewRow, F, L, D ) \
2653  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewScalar, F, L, D ) \
2654  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Subview, F, L, D ) \
2655  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Subview2, F, L, D ) \
2656  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ShmemSize, F, L, D ) \
2657  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ConstViewAssign, F, L, D )
2658 
2659 #define VIEW_FAD_TESTS_SFLD( F, L, D ) \
2660  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SFadNoSizeArg, F, L, D )
2661 
2662 #define VIEW_FAD_TESTS_FDI( F, D ) \
2663  using Kokkos::LayoutLeft; \
2664  using Kokkos::LayoutRight; \
2665  VIEW_FAD_TESTS_FLD( F, LayoutLeft, D ) \
2666  VIEW_FAD_TESTS_FLD( F, LayoutRight, D ) \
2667  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, F, LayoutLeft, D ) \
2668  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, F, LayoutRight, D ) \
2669  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, CommonViewAllocMixedSpec, F, LayoutLeft, D ) \
2670  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, CommonViewAllocMixedSpec, F, LayoutRight, D )
2671 
2672 #define VIEW_FAD_TESTS_SFDI( F, D ) \
2673  using Kokkos::LayoutLeft; \
2674  using Kokkos::LayoutRight; \
2675  VIEW_FAD_TESTS_SFLD( F, LayoutLeft, D ) \
2676  VIEW_FAD_TESTS_SFLD( F, LayoutRight, D )
2677 
2678 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2681 
2682 #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
2683 #define VIEW_FAD_TESTS_FDC( F, D ) \
2684  VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \
2685  VIEW_FAD_TESTS_FLD( F, RightContiguous, D ) \
2686  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Partition, F, LeftContiguous, D ) \
2687  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Partition, F, RightContiguous, D )
2688 #else
2689 #define VIEW_FAD_TESTS_FDC( F, D ) \
2690  VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \
2691  VIEW_FAD_TESTS_FLD( F, RightContiguous, D )
2692 #endif
2693 
2694 #define VIEW_FAD_TESTS_SFDC( F, D ) \
2695  VIEW_FAD_TESTS_SFLD( F, LeftContiguous, D ) \
2696  VIEW_FAD_TESTS_SFLD( F, RightContiguous, D )
2697 #else
2698 #define VIEW_FAD_TESTS_FDC( F, D ) /* */
2699 #define VIEW_FAD_TESTS_SFDC( F, D ) /* */
2700 #endif
2701 
2702 #define VIEW_FAD_TESTS_FD( F, D ) \
2703  VIEW_FAD_TESTS_FDI( F, D ) \
2704  VIEW_FAD_TESTS_FDC( F, D )
2705 
2706 #define VIEW_FAD_TESTS_SFD( F, D ) \
2707  VIEW_FAD_TESTS_SFDI( F, D ) \
2708  VIEW_FAD_TESTS_SFDC( F, D )
2709 
2710 // We've unified the implementation for the different Fad variants, so
2711 // there is no reason to test ELRFad, CacheFad, and ELRCacheFad.
2715 
2716 /*
2717 typedef Sacado::ELRFad::DFad<double> ELRDFadType;
2718 typedef Sacado::ELRFad::SLFad<double,2*global_fad_size> ELRSLFadType;
2719 typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRSFadType;
2720 
2721 typedef Sacado::CacheFad::DFad<double> CacheDFadType;
2722 typedef Sacado::CacheFad::SLFad<double,2*global_fad_size> CacheSLFadType;
2723 typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheSFadType;
2724 
2725 typedef Sacado::ELRCacheFad::DFad<double> ELRCacheDFadType;
2726 typedef Sacado::ELRCacheFad::SLFad<double,2*global_fad_size> ELRCacheSLFadType;
2727 typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheSFadType;
2728 */
2729 
2730 // We can't use DFad unless we use the View specialization
2731 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) && SACADO_TEST_DFAD
2732 #define VIEW_FAD_TESTS_D( D ) \
2733  VIEW_FAD_TESTS_FD( SFadType, D ) \
2734  VIEW_FAD_TESTS_FD( SLFadType, D ) \
2735  VIEW_FAD_TESTS_FD( DFadType, D ) \
2736  VIEW_FAD_TESTS_SFD( SFadType, D )
2737 
2738 #if 0
2739  VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
2740  VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
2741  VIEW_FAD_TESTS_FD( ELRDFadType, D ) \
2742  VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
2743  VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
2744  VIEW_FAD_TESTS_FD( CacheDFadType, D ) \
2745  VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
2746  VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
2747  VIEW_FAD_TESTS_FD( ELRCacheDFadType, D ) \
2748  VIEW_FAD_TESTS_SFD( SFadType, D ) \
2749  VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
2750  VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
2751  VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
2752 #endif
2753 
2754 #else
2755 
2756 #define VIEW_FAD_TESTS_D( D ) \
2757  VIEW_FAD_TESTS_FD( SFadType, D ) \
2758  VIEW_FAD_TESTS_FD( SLFadType, D ) \
2759  VIEW_FAD_TESTS_SFD( SFadType, D )
2760 
2761 #if 0
2762  VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
2763  VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
2764  VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
2765  VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
2766  VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
2767  VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
2768  VIEW_FAD_TESTS_SFD( SFadType, D ) \
2769  VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
2770  VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
2771  VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
2772 #endif
2773 
2774 #endif
SACADO_INLINE_FUNCTION ScalarType< T >::type scalarValue(const T &x)
A simple template function for invoking ScalarValue&lt;&gt;
InputViewType::size_type size_type
team_policy_type::member_type team_handle
Kokkos::TeamPolicy< execution_space > team_policy_type
static const size_type stride
ViewType::value_type::value_type ScalarType
ViewType::execution_space execution_space
Kokkos::TeamPolicy< execution_space > team_policy_type
static const size_type stride
ViewType::execution_space execution_space
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
void f()
ViewType::size_type size_type
const ViewType m_v
Kokkos::LayoutContiguous< Kokkos::LayoutRight > RightContiguous
Kokkos::RangePolicy< execution_space > range_policy_type
ViewType::value_type ValueType
Kokkos::LayoutContiguous< Kokkos::LayoutLeft > LeftContiguous
static const size_type stride
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
static const bool value
const int global_fad_size
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
KOKKOS_INLINE_FUNCTION auto subview(const View< D, Kokkos::LayoutContiguous< LayoutSrc, StrideSrc >, P...> &src, Args...args)
const ScalarViewType m_s
#define VIEW_FAD_TESTS_SFD(F, D)
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
const InputViewType1 m_v1
static const size_type stride
ViewType::size_type size_type
InputViewType::execution_space execution_space
static void apply(const InputViewType v1, const OutputViewType v2, const size_type col)
team_policy_type::member_type team_handle
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
const ScalarViewType m_s
const int global_num_rows
Kokkos::RangePolicy< execution_space > range_policy_type
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
ViewType::execution_space execution_space
const ScalarType m_s
const ViewType m_v
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
expr val()
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
ValueAssignKernel(const ViewType &v, const ScalarViewType &s)
ViewType::size_type size_type
GeneralFad< DynamicStorage< T > > DFad
team_policy_type::member_type team_handle
const bool m_update
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
int value
Kokkos::TeamPolicy< execution_space > team_policy_type
static void apply(const ViewType &v, const ScalarViewType &s)
Sacado::Fad::SLFad< double, fad_dim > SLFadType
void g()
Sacado::Fad::DFad< double > DFadType
static void apply(const ViewType &v, const ScalarViewType &s)
Kokkos::TeamPolicy< execution_space > team_policy_type
ScalarAssignKernel(const ViewType &v, const ScalarType &s)
KOKKOS_INLINE_FUNCTION void operator()(const team_handle &team) const
static const bool value
AtomicAddKernel(const ViewType &v, const ScalarViewType &s)
KOKKOS_INLINE_FUNCTION auto subdynrankview(const DynRankView< T, LayoutContiguous< LayoutSrc, StrideSrc >, DRVArgs...> &drv, SubArg0 arg0=SubArg0{}, SubArg1 arg1=SubArg1{}, SubArg2 arg2=SubArg2{}, SubArg3 arg3=SubArg3{}, SubArg4 arg4=SubArg4{}, SubArg5 arg5=SubArg5{}, SubArg6 arg6=SubArg6{})
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
#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
Kokkos::ThreadLocalScalarType< ViewType >::type local_scalar_type
const double tol
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
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)
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
Kokkos::TeamPolicy< execution_space > team_policy_type
const OutputViewType m_v3