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