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
30 
31 #include "Sacado.hpp"
33 
34 template <typename FadType1, typename FadType2>
35 bool checkFads(const FadType1& x, const FadType2& x2,
36  Teuchos::FancyOStream& out, double tol = 1.0e-15)
37 {
38  bool success = true;
39 
40  // Check sizes match
41  TEUCHOS_TEST_EQUALITY(x.size(), x2.size(), out, success);
42 
43  // Check values match
44  TEUCHOS_TEST_EQUALITY(x.val(), x2.val(), out, success);
45 
46  // Check derivatives match
47  for (int i=0; i<x.size(); ++i)
48  TEUCHOS_TEST_FLOATING_EQUALITY(x.dx(i), x2.dx(i), tol, out, success);
49 
50  return success;
51 }
52 
53 template <typename fadtype, typename ordinal>
54 inline
55 fadtype generate_fad( const ordinal num_rows,
56  const ordinal num_cols,
57  const ordinal fad_size,
58  const ordinal row,
59  const ordinal col )
60 {
61  typedef typename fadtype::value_type scalar;
62  fadtype x(fad_size, scalar(0.0));
63 
64  const scalar x_row = 100.0 + scalar(num_rows) / scalar(row+1);
65  const scalar x_col = 10.0 + scalar(num_cols) / scalar(col+1);
66  x.val() = x_row + x_col;
67  for (ordinal i=0; i<fad_size; ++i) {
68  const scalar x_fad = 1.0 + scalar(fad_size) / scalar(i+1);
69  x.fastAccessDx(i) = x_row + x_col + x_fad;
70  }
71  return x;
72 }
73 
74 const int global_num_rows = 11;
75 const int global_num_cols = 7;
76 const int global_fad_size = 5;
77 
78 // Kernel to multiply two views
79 template <typename InputViewType1,
80  typename InputViewType2 = InputViewType1,
81  typename OutputViewType = InputViewType1>
83  typedef typename InputViewType1::execution_space execution_space;
84  typedef typename InputViewType1::size_type size_type;
85 
86  const InputViewType1 m_v1;
87  const InputViewType2 m_v2;
88  const OutputViewType m_v3;
89  const bool m_update;
90 
91  MultiplyKernel(const InputViewType1 v1,
92  const InputViewType2 v2,
93  const OutputViewType v3,
94  const bool update) :
95  m_v1(v1), m_v2(v2), m_v3(v3), m_update(update) {};
96 
97  // Multiply entries for row 'i' with a value
99  void operator() (const size_type i) const {
100  if (m_update)
101  m_v3(i) += m_v1(i)*m_v2(i);
102  else
103  m_v3(i) = m_v1(i)*m_v2(i);
104  }
105 
106  // Kernel launch
107  static void apply(const InputViewType1 v1,
108  const InputViewType2 v2,
109  const OutputViewType v3,
110  const bool update = false) {
111  const size_type nrow = v1.dimension_0();
112  Kokkos::parallel_for( nrow, MultiplyKernel(v1,v2,v3,update) );
113  }
114 };
115 
116 // Kernel to assign a constant to a view
117 template <typename ViewType, typename ScalarType>
119  typedef typename ViewType::execution_space execution_space;
120  typedef typename ViewType::size_type size_type;
121 
122  const ViewType m_v;
123  const ScalarType m_s;
124 
125  ScalarAssignKernel(const ViewType& v, const ScalarType& s) :
126  m_v(v), m_s(s) {};
127 
128  // Multiply entries for row 'i' with a value
130  void operator() (const size_type i) const {
131  m_v(i) = m_s;
132  }
133 
134  // Kernel launch
135  static void apply(const ViewType& v, const ScalarType& s) {
136  const size_type nrow = v.dimension_0();
137  Kokkos::parallel_for( nrow, ScalarAssignKernel(v,s) );
138  }
139 };
140 
141 // Kernel to assign a column of a rank-2 to a rank-1
142 template <typename InputViewType,
143  typename OutputViewType>
145  typedef typename InputViewType::execution_space execution_space;
146  typedef typename InputViewType::size_type size_type;
147 
148  const InputViewType m_v1;
149  const OutputViewType m_v2;
151 
152  AssignRank2Rank1Kernel(const InputViewType v1,
153  const OutputViewType v2,
154  const size_type col) :
155  m_v1(v1), m_v2(v2), m_col(col) {
156  static_assert( unsigned(InputViewType::Rank) == 2 ,
157  "Require rank-2 input view" );
158  static_assert( unsigned(OutputViewType::Rank) == 1 ,
159  "Require rank-1 output view" );
160  };
161 
162  // Multiply entries for row 'i' with a value
164  void operator() (const size_type i) const {
165  m_v2(i) = m_v1(i,m_col);
166  }
167 
168  // Kernel launch
169  static void apply(const InputViewType v1,
170  const OutputViewType v2,
171  const size_type col) {
172  const size_type nrow = v1.dimension_0();
173  Kokkos::parallel_for( nrow, AssignRank2Rank1Kernel(v1,v2,col) );
174  }
175 };
176 
178  Kokkos_View_Fad, Size, FadType, Layout, Device )
179 {
180  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
181  typedef typename ViewType::size_type size_type;
182 
183  const size_type num_rows = global_num_rows;
184  const size_type fad_size = global_fad_size;
185 
186  // Create and fill view
187  ViewType v("view", num_rows, fad_size+1);
188  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
189 }
190 
192  Kokkos_View_Fad, DeepCopy, FadType, Layout, Device )
193 {
194  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
195  typedef typename ViewType::size_type size_type;
196  typedef typename ViewType::HostMirror host_view_type;
197 
198  const size_type num_rows = global_num_rows;
199  const size_type num_cols = global_num_cols;
200  const size_type fad_size = global_fad_size;
201 
202  // Create and fill view
203  ViewType v("view", num_rows, num_cols, fad_size+1);
204  host_view_type h_v = Kokkos::create_mirror_view(v);
205  for (size_type i=0; i<num_rows; ++i)
206  for (size_type j=0; j<num_cols; ++j)
207  h_v(i,j) = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
208  Kokkos::deep_copy(v, h_v);
209 
210  // Copy back
211  host_view_type h_v2 = Kokkos::create_mirror_view(v);
212  Kokkos::deep_copy(h_v2, v);
213 
214  // Check
215  success = true;
216  for (size_type i=0; i<num_rows; ++i) {
217  for (size_type j=0; j<num_cols; ++j) {
218  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
219  success = success && checkFads(f, h_v2(i,j), out);
220  }
221  }
222 }
223 
225  Kokkos_View_Fad, DeepCopy_ConstantScalar, FadType, Layout, Device )
226 {
227  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
228  typedef typename ViewType::size_type size_type;
229  typedef typename ViewType::HostMirror host_view_type;
230  typedef typename FadType::value_type value_type;
231 
232  const size_type num_rows = global_num_rows;
233  const size_type num_cols = global_num_cols;
234  const size_type fad_size = global_fad_size;
235 
236  // Create and fill view
237  ViewType v("view", num_rows, num_cols, fad_size+1);
238  typename ViewType::array_type va = v;
239  Kokkos::deep_copy( va, 1.0 );
240 
241  // Deep copy a constant scalar
242  value_type a = 2.3456;
243  Kokkos::deep_copy( v, a );
244 
245  // Copy to host
246  host_view_type hv = Kokkos::create_mirror_view(v);
247  Kokkos::deep_copy(hv, v);
248 
249  // Check
250  success = true;
251  for (size_type i=0; i<num_rows; ++i) {
252  for (size_type j=0; j<num_cols; ++j) {
253 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
254  FadType f = FadType(fad_size, a);
255 #else
256  FadType f = a;
257 #endif
258  success = success && checkFads(f, hv(i,j), out);
259  }
260  }
261 }
262 
264  Kokkos_View_Fad, DeepCopy_ConstantZero, FadType, Layout, Device )
265 {
266  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
267  typedef typename ViewType::size_type size_type;
268  typedef typename ViewType::HostMirror host_view_type;
269  typedef typename FadType::value_type value_type;
270 
271  const size_type num_rows = global_num_rows;
272  const size_type num_cols = global_num_cols;
273  const size_type fad_size = global_fad_size;
274 
275  // Create and fill view
276  ViewType v("view", num_rows, num_cols, fad_size+1);
277  typename ViewType::array_type va = v;
278  Kokkos::deep_copy( va, 1.0 );
279 
280  // Deep copy a constant scalar
281  value_type a = 0.0;
282  Kokkos::deep_copy( v, a );
283 
284  // Copy to host
285  host_view_type hv = Kokkos::create_mirror_view(v);
286  Kokkos::deep_copy(hv, v);
287 
288  // Check
289  success = true;
290  for (size_type i=0; i<num_rows; ++i) {
291  for (size_type j=0; j<num_cols; ++j) {
292 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
293  FadType f = FadType(fad_size, a);
294 #else
295  FadType f = a;
296 #endif
297  success = success && checkFads(f, hv(i,j), out);
298  }
299  }
300 }
301 
303  Kokkos_View_Fad, DeepCopy_ConstantFad, FadType, Layout, Device )
304 {
305  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
306  typedef typename ViewType::size_type size_type;
307  typedef typename ViewType::HostMirror host_view_type;
308 
309  const size_type num_rows = global_num_rows;
310  const size_type num_cols = global_num_cols;
311  const size_type fad_size = global_fad_size;
312 
313  // Create and fill view
314  ViewType v("view", num_rows, num_cols, fad_size+1);
315  typename ViewType::array_type va = v;
316  Kokkos::deep_copy( va, 1.0 );
317 
318  // Deep copy a constant scalar
319  FadType a = 2.3456;
320  Kokkos::deep_copy( v, a );
321 
322  // Copy to host
323  host_view_type hv = Kokkos::create_mirror_view(v);
324  Kokkos::deep_copy(hv, v);
325 
326  // Check
327  success = true;
328  for (size_type i=0; i<num_rows; ++i) {
329  for (size_type j=0; j<num_cols; ++j) {
330 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
331  FadType f = FadType(fad_size, a.val());
332 #else
333  FadType f = a;
334 #endif
335  success = success && checkFads(f, hv(i,j), out);
336  }
337  }
338 }
339 
341  Kokkos_View_Fad, DeepCopy_ConstantFadFull, FadType, Layout, Device )
342 {
343  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
344  typedef typename ViewType::size_type size_type;
345  typedef typename ViewType::HostMirror host_view_type;
346 
347  const size_type num_rows = global_num_rows;
348  const size_type num_cols = global_num_cols;
349  const size_type fad_size = global_fad_size;
350 
351  // Create and fill view
352  ViewType v("view", num_rows, num_cols, fad_size+1);
353  typename ViewType::array_type va = v;
354  Kokkos::deep_copy( va, 1.0 );
355 
356  // Deep copy a constant Fad
357  FadType a(fad_size, 2.3456);
358  for (size_type i=0; i<fad_size; ++i)
359  a.fastAccessDx(i) = 7.89 + (i+1);
360  Kokkos::deep_copy( v, a );
361 
362  // Copy to host
363  host_view_type hv = Kokkos::create_mirror_view(v);
364  Kokkos::deep_copy(hv, v);
365 
366  // Check
367  success = true;
368  for (size_type i=0; i<num_rows; ++i) {
369  for (size_type j=0; j<num_cols; ++j) {
370  success = success && checkFads(a, hv(i,j), out);
371  }
372  }
373 }
374 
376  Kokkos_View_Fad, ScalarAssign, FadType, Layout, Device )
377 {
378  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
379  typedef typename ViewType::size_type size_type;
380  typedef typename ViewType::HostMirror host_view_type;
381  typedef typename FadType::value_type value_type;
382 
383  const size_type num_rows = global_num_rows;
384  const size_type fad_size = global_fad_size;
385 
386  // Create and fill view
387  ViewType v("view", num_rows, fad_size+1);
388  typename ViewType::array_type va = v;
389  Kokkos::deep_copy( va, 1.0 );
390 
391  // Deep copy a constant scalar
392  value_type a = 2.3456;
394 
395  // Copy to host
396  host_view_type hv = Kokkos::create_mirror_view(v);
397  Kokkos::deep_copy(hv, v);
398 
399  // Check
400  success = true;
401  for (size_type i=0; i<num_rows; ++i) {
402 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
403  FadType f = FadType(fad_size, a);
404 #else
405  FadType f = a;
406 #endif
407  success = success && checkFads(f, hv(i), out);
408  }
409 }
410 
412  Kokkos_View_Fad, Multiply, FadType, Layout, Device )
413 {
414  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
415  typedef typename ViewType::size_type size_type;
416  typedef typename ViewType::HostMirror host_view_type;
417 
418  const size_type num_rows = global_num_rows;
419  const size_type fad_size = global_fad_size;
420 
421  // Create and fill views
422  ViewType v1("view1", num_rows, fad_size+1), v2("view2", num_rows, fad_size+1);
423  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
424  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
425  for (size_type i=0; i<num_rows; ++i) {
426  h_v1(i) = generate_fad<FadType>(
427  num_rows, size_type(2), fad_size, i, size_type(0));
428  h_v2(i) = generate_fad<FadType>(
429  num_rows, size_type(2), fad_size, i, size_type(1));
430  }
431  Kokkos::deep_copy(v1, h_v1);
432  Kokkos::deep_copy(v2, h_v2);
433 
434  // Launch kernel
435  ViewType v3("view3", num_rows, fad_size+1);
437 
438  // Copy back
439  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
440  Kokkos::deep_copy(h_v3, v3);
441 
442  // Check
443  success = true;
444  for (size_type i=0; i<num_rows; ++i) {
445  FadType f1 =
446  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
447  FadType f2 =
448  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
449  FadType f3 = f1*f2;
450  success = success && checkFads(f3, h_v3(i), out);
451  }
452 }
453 
455  Kokkos_View_Fad, MultiplyUpdate, FadType, Layout, Device )
456 {
457  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
458  typedef typename ViewType::size_type size_type;
459  typedef typename ViewType::HostMirror host_view_type;
460 
461  const size_type num_rows = global_num_rows;
462  const size_type fad_size = global_fad_size;
463 
464  // Create and fill views
465  ViewType v1("view1", num_rows, fad_size+1), v2("view2", num_rows, fad_size+1);
466  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
467  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
468  for (size_type i=0; i<num_rows; ++i) {
469  h_v1(i) = generate_fad<FadType>(
470  num_rows, size_type(2), fad_size, i, size_type(0));
471  h_v2(i) = generate_fad<FadType>(
472  num_rows, size_type(2), fad_size, i, size_type(1));
473  }
474  Kokkos::deep_copy(v1, h_v1);
475  Kokkos::deep_copy(v2, h_v2);
476 
477  // Launch kernel
478  ViewType v3("view3", num_rows, fad_size+1);
479  Kokkos::deep_copy(v3, 1.0);
480  MultiplyKernel<ViewType>::apply(v1,v2,v3,true);
481 
482  // Copy back
483  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
484  Kokkos::deep_copy(h_v3, v3);
485 
486  // Check
487  success = true;
488  for (size_type i=0; i<num_rows; ++i) {
489  FadType f1 =
490  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
491  FadType f2 =
492  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
493  FadType f3 = 1.0 + f1*f2;
494  success = success && checkFads(f3, h_v3(i), out);
495  }
496 }
497 
499  Kokkos_View_Fad, MultiplyConst, FadType, Layout, Device )
500 {
501  typedef Kokkos::View<const FadType*,Layout,Device,Kokkos::MemoryUnmanaged> ConstViewType;
502  typedef Kokkos::View<FadType*,Layout,Device> ViewType;
503  typedef typename ViewType::size_type size_type;
504  typedef typename ViewType::HostMirror host_view_type;
505 
506  const size_type num_rows = global_num_rows;
507  const size_type fad_size = global_fad_size;
508 
509  // Create and fill views
510  ViewType v1("view1", num_rows, fad_size+1);
511  ViewType v2("view2", num_rows, fad_size+1);
512  host_view_type h_v1 = Kokkos::create_mirror_view(v1);
513  host_view_type h_v2 = Kokkos::create_mirror_view(v2);
514  for (size_type i=0; i<num_rows; ++i) {
515  h_v1(i) = generate_fad<FadType>(
516  num_rows, size_type(2), fad_size, i, size_type(0));
517  h_v2(i) = generate_fad<FadType>(
518  num_rows, size_type(2), fad_size, i, size_type(1));
519  }
520  Kokkos::deep_copy(v1, h_v1);
521  Kokkos::deep_copy(v2, h_v2);
522 
523  ConstViewType cv1 = v1;
524 
525  // Launch kernel
526  ViewType v3("view3", num_rows, fad_size+1);
528 
529  // Copy back
530  host_view_type h_v3 = Kokkos::create_mirror_view(v3);
531  Kokkos::deep_copy(h_v3, v3);
532 
533  // Check
534  success = true;
535  for (size_type i=0; i<num_rows; ++i) {
536  FadType f1 =
537  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
538  FadType f2 =
539  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
540  FadType f3 = f1*f2;
541  success = success && checkFads(f3, h_v3(i), out);
542  }
543 }
544 
546  Kokkos_View_Fad, MultiplyMixed, 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 
552  const size_type num_rows = 2;
553  const size_type fad_size = global_fad_size;
554 
555  // Create and fill views -- do everything on the host for this test
556  FadType f0 = generate_fad<FadType>(
557  num_rows, size_type(2), fad_size, size_type(0), size_type(0));
558  FadType f1 = generate_fad<FadType>(
559  num_rows, size_type(2), fad_size, size_type(1), size_type(0));
560  host_view_type h_v("view1", num_rows, fad_size+1);
561  h_v(0) = f0;
562  h_v(1) = f1;
563 
564  FadType f2 = f0 * h_v(1);
565 
566  // Check
567  FadType f3 = f0 * f1;
568  success = checkFads(f3, f2, out);
569 }
570 
572  Kokkos_View_Fad, Rank8, FadType, Layout, Device )
573 {
574  typedef Kokkos::View<FadType*******,Layout,Device> ViewType;
575  typedef typename ViewType::size_type size_type;
576  typedef typename ViewType::HostMirror host_view_type;
577 
578  const size_type fad_size = global_fad_size;
579 
580  // Create and fill view
581  ViewType v("view", 100, 1, 2, 3, 4, 5, 6, fad_size+1);
582  host_view_type h_v = Kokkos::create_mirror_view(v);
583  typename host_view_type::array_type h_a = h_v;
584  Kokkos::deep_copy(h_a, 1.0);
585 
586  FadType f1 = FadType(fad_size, 2.0);
587  h_v(99,0,1,2,3,4,5) = f1;
588  FadType f2 = h_v(99,0,1,2,3,4,5);
589 
590  // Check
591  success = checkFads(f1, f2, out);
592 }
593 
595  Kokkos_View_Fad, Roger, FadType, Layout, Device )
596 {
597  const unsigned fad_size = global_fad_size;
598 
599  Kokkos::View<FadType*,Layout,Device> a("a",4,fad_size+1);
600  Kokkos::View<FadType**,Layout,Device> b("b",4,4,fad_size+1);
601  Kokkos::View<FadType***,Layout,Device> c("c",4,4,4,fad_size+1);
602  Kokkos::View<FadType****,Layout,Device> d("d",4,4,4,4,fad_size+1);
603  Kokkos::View<FadType*****,Layout,Device> e("e",4,4,4,4,4,fad_size+1);
604  Kokkos::View<FadType******,Layout,Device> f("f",4,4,4,4,4,4,fad_size+1);
605  Kokkos::View<FadType*******,Layout,Device> g("g",4,4,4,4,4,4,4,fad_size+1);
606 
607  a(0) = FadType(1.0);
608  f(0,0,0,0,0,0) = FadType(1.0);
609  g(0,0,0,0,0,0,0) = FadType(1.0);
610 
611  // Check
612  success = true;
613 }
614 
616  Kokkos_View_Fad, AssignDifferentStrides, FadType, Layout, Device )
617 {
618  typedef Kokkos::View<FadType**,Layout,Device> ViewType1;
619  typedef Kokkos::View<FadType*,Layout,Device> ViewType2;
620  typedef typename ViewType1::size_type size_type;
621  typedef typename ViewType1::HostMirror host_view_type1;
622  typedef typename ViewType2::HostMirror host_view_type2;
623 
624  const size_type num_rows = global_num_rows;
625  const size_type num_cols = global_num_cols;
626  const size_type fad_size = global_fad_size;
627 
628  // Create and fill views
629  ViewType1 v1("view1", num_rows, num_cols, fad_size+1);
630  host_view_type1 h_v1 = Kokkos::create_mirror_view(v1);
631  for (size_type i=0; i<num_rows; ++i) {
632  for (size_type j=0; j<num_cols; ++j) {
633  h_v1(i,j) = generate_fad<FadType>(
634  num_rows, num_cols, fad_size, i, j);
635  }
636  }
637  Kokkos::deep_copy(v1, h_v1);
638 
639  // Launch kernel
640  ViewType2 v2("view2", num_rows, fad_size+1);
642 
643  // Copy back
644  host_view_type2 h_v2 = Kokkos::create_mirror_view(v2);
645  Kokkos::deep_copy(h_v2, v2);
646 
647  // Check
648  success = true;
649  for (size_type i=0; i<num_rows; ++i) {
650  FadType f =
651  generate_fad<FadType>(num_rows, num_cols, fad_size, i, size_type(1));
652  success = success && checkFads(f, h_v2(i), out);
653  }
654 }
655 
656 #if defined(HAVE_SACADO_KOKKOSCONTAINERS) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
657 
659  Kokkos_View_Fad, DynRankDimensionScalar, FadType, Layout, Device )
660 {
661  typedef Kokkos::DynRankView<double,Layout,Device> DoubleViewType;
662  typedef Kokkos::DynRankView<FadType,Layout,Device> FadViewType;
663  typedef typename FadViewType::size_type size_type;
664 
665  const size_type num_rows = global_num_rows;
666  const size_type fad_size = global_fad_size;
667 
668  // Create views
669  DoubleViewType v1("view", num_rows);
670  FadViewType v2("view", num_rows, fad_size+1);
671 
672  // Check dimension scalar works
673  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v1), 0, out, success);
674 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
675 }
676 
678  Kokkos_View_Fad, DynRankMultiply, FadType, Layout, Device )
679 {
680  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
681  typedef typename ViewType::size_type size_type;
682  typedef typename ViewType::HostMirror host_view_type;
683 
684  const size_type num_rows = global_num_rows;
685  const size_type fad_size = global_fad_size;
686 
687  // Create and fill views
688  ViewType v1("view1", num_rows, fad_size+1), v2("view2", num_rows, fad_size+1);
689  host_view_type h_v1 = Kokkos::Experimental::create_mirror_view(v1);
690  host_view_type h_v2 = Kokkos::Experimental::create_mirror_view(v2);
691  for (size_type i=0; i<num_rows; ++i) {
692  h_v1(i) = generate_fad<FadType>(
693  num_rows, size_type(2), fad_size, i, size_type(0));
694  h_v2(i) = generate_fad<FadType>(
695  num_rows, size_type(2), fad_size, i, size_type(1));
696  }
697  Kokkos::Experimental::deep_copy(v1, h_v1);
698  Kokkos::Experimental::deep_copy(v2, h_v2);
699 
700  // Launch kernel
701  ViewType v3("view3", num_rows, fad_size+1);
703 
704  // Copy back
705  host_view_type h_v3 = Kokkos::Experimental::create_mirror_view(v3);
706  Kokkos::Experimental::deep_copy(h_v3, v3);
707 
708  // Check
709  success = true;
710  TEUCHOS_TEST_EQUALITY(v3.rank(), 1, out, success);
711  for (size_type i=0; i<num_rows; ++i) {
712  FadType f1 =
713  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(0));
714  FadType f2 =
715  generate_fad<FadType>(num_rows, size_type(2), fad_size, i, size_type(1));
716  FadType f3 = f1*f2;
717  success = success && checkFads(f3, h_v3(i), out);
718  }
719 }
720 
722  Kokkos_View_Fad, SubdynrankviewCol, FadType, Layout, Device )
723 {
724  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
725  typedef typename ViewType::size_type size_type;
726  typedef typename ViewType::HostMirror host_view_type;
727 
728  const size_type num_rows = global_num_rows;
729  const size_type num_cols = global_num_cols;
730  const size_type fad_size = global_fad_size;
731 
732  // Create and fill view
733  ViewType v("view", num_rows, num_cols, fad_size+1);
734  host_view_type h_v = Kokkos::create_mirror_view(v);
735  for (size_type i=0; i<num_rows; ++i) {
736  for (size_type j=0; j<num_cols; ++j) {
737  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
738  h_v(i,j) = f;
739  }
740  }
741  Kokkos::deep_copy(v, h_v);
742 
743  // Create subview of first column
744  size_type col = 1;
745  auto s = Kokkos::subdynrankview(v, Kokkos::ALL(), col);
746 
747  // Copy back
748  typedef decltype(s) SubviewType;
749  typedef typename SubviewType::HostMirror HostSubviewType;
750  HostSubviewType h_s = Kokkos::create_mirror_view(s);
751  Kokkos::deep_copy(h_s, s);
752 
753  // Check
754  success = true;
755  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
756  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
757  for (size_type i=0; i<num_rows; ++i) {
758  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
759  success = success && checkFads(f, h_s(i), out);
760  }
761 }
762 
764  Kokkos_View_Fad, SubdynrankviewRow, FadType, Layout, Device )
765 {
766  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
767  typedef typename ViewType::size_type size_type;
768  typedef typename ViewType::HostMirror host_view_type;
769 
770  const size_type num_rows = global_num_rows;
771  const size_type num_cols = global_num_cols;
772  const size_type num_planes = 9;
773  const size_type fad_size = global_fad_size;
774 
775  // Create and fill view
776  ViewType v("view", num_rows, num_cols, num_planes, fad_size+1);
777  host_view_type h_v = Kokkos::create_mirror_view(v);
778  for (size_type i=0; i<num_rows; ++i) {
779  for (size_type j=0; j<num_cols; ++j) {
780  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
781  for (size_type k=0; k<num_planes; ++k) {
782  h_v(i,j,k) = (k+1)*f;
783  }
784  }
785  }
786  Kokkos::deep_copy(v, h_v);
787 
788  // Create subview of first column
789  size_type row = 2;
790  auto s = Kokkos::subdynrankview(v, row, Kokkos::ALL(), Kokkos::ALL());
791 
792  // Copy back
793  typedef decltype(s) SubviewType;
794  typedef typename SubviewType::HostMirror HostSubviewType;
795  HostSubviewType h_s = Kokkos::create_mirror_view(s);
796  Kokkos::deep_copy(h_s, s);
797 
798  // Check
799  success = true;
800  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
801  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
802  for (size_type j=0; j<num_cols; ++j) {
803  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, row, j);
804  for (size_type k=0; k<num_planes; ++k) {
805  FadType g = (k+1)*f;
806  success = success && checkFads(g, h_s(j,k), out);
807  }
808  }
809 }
810 
812  Kokkos_View_Fad, SubdynrankviewScalar, FadType, Layout, Device )
813 {
814  typedef Kokkos::DynRankView<FadType,Layout,Device> ViewType;
815  typedef typename ViewType::size_type size_type;
816  typedef typename ViewType::HostMirror host_view_type;
817 
818  const size_type num_rows = global_num_rows;
819  const size_type num_cols = global_num_cols;
820  const size_type fad_size = global_fad_size;
821 
822  // Create and fill view
823  ViewType v("view", num_rows, num_cols, fad_size+1);
824  host_view_type h_v = Kokkos::create_mirror_view(v);
825  for (size_type i=0; i<num_rows; ++i) {
826  for (size_type j=0; j<num_cols; ++j) {
827  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
828  h_v(i,j) = f;
829  }
830  }
831  Kokkos::deep_copy(v, h_v);
832 
833  // Create subview of first column
834  size_type row = 3;
835  size_type col = 1;
836  auto s = Kokkos::subdynrankview(v, row, col);
837 
838  // Copy back
839  typedef decltype(s) SubviewType;
840  typedef typename SubviewType::HostMirror HostSubviewType;
841  HostSubviewType h_s = Kokkos::create_mirror_view(s);
842  Kokkos::deep_copy(h_s, s);
843 
844  // Check
845  success = true;
846  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
847  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
848  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, row, col);
849  success = success && checkFads(f, h_s(), out);
850 }
851 
852 #else
853 
855  Kokkos_View_Fad, DynRankDimensionScalar, FadType, Layout, Device ) {}
857  Kokkos_View_Fad, DynRankMultiply, FadType, Layout, Device ) {}
859  Kokkos_View_Fad, SubdynrankviewCol, FadType, Layout, Device ) {}
861  Kokkos_View_Fad, SubdynrankviewRow, FadType, Layout, Device ) {}
863  Kokkos_View_Fad, SubdynrankviewScalar, FadType, Layout, Device ) {}
864 
865 #endif
866 
868  Kokkos_View_Fad, Subview, FadType, Layout, Device )
869 {
870  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
871  typedef typename ViewType::size_type size_type;
872  typedef typename ViewType::HostMirror host_view_type;
873 
874  const size_type num_rows = global_num_rows;
875  const size_type num_cols = global_num_cols;
876  const size_type fad_size = global_fad_size;
877 
878  // Create and fill view
879  ViewType v("view", num_rows, num_cols, fad_size+1);
880  host_view_type h_v = Kokkos::create_mirror_view(v);
881  for (size_type i=0; i<num_rows; ++i) {
882  for (size_type j=0; j<num_cols; ++j) {
883  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
884  h_v(i,j) = f;
885  }
886  }
887  Kokkos::deep_copy(v, h_v);
888 
889  // Create subview of first column
890  size_type col = 1;
891  auto s = Kokkos::subview(v, Kokkos::ALL(), col);
892 
893  // Copy back
894  typedef decltype(s) SubviewType;
895  typedef typename SubviewType::HostMirror HostSubviewType;
896  HostSubviewType h_s = Kokkos::create_mirror_view(s);
897  Kokkos::deep_copy(h_s, s);
898 
899  // Check
900  success = true;
901 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
902  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(s), fad_size+1, out, success);
903  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_s), fad_size+1, out, success);
904 #endif
905  for (size_type i=0; i<num_rows; ++i) {
906  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, col);
907  success = success && checkFads(f, h_s(i), out);
908  }
909 }
910 
911 // Tests that require view spec
912 
913 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
915  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
916 {
917  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
918  typedef typename FadType::value_type value_type;
919  typedef typename ViewType::size_type size_type;
920 
921  const size_type num_rows = global_num_rows;
922  const size_type num_cols = global_num_cols;
923  const size_type fad_size = global_fad_size;
924 
925  // Compute shared memory size for View
926  const size_type shmem_size =
927  ViewType::shmem_size(num_rows, num_cols, fad_size+1);
928 
929  // Check
930  static const size_type align = 8;
931  static const size_type mask = align - 1;
932  const size_type shmem_size_expected =
933  ( sizeof(value_type) * global_num_rows * global_num_cols * (fad_size+1) +
934  mask ) & ~mask;
935  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
936 }
937 
939  Kokkos_View_Fad, Unmanaged, FadType, Layout, Device )
940 {
941  typedef typename FadType::value_type scalar_type;
942  typedef Kokkos::View<scalar_type***,Layout,Device> ViewType;
943  typedef Kokkos::View<FadType**,Layout,Device,Kokkos::MemoryUnmanaged> FadViewType;
944  typedef typename ViewType::size_type size_type;
945  typedef typename ViewType::HostMirror host_view_type;
946  typedef typename FadViewType::HostMirror fad_host_view_type;
947 
948  const size_type num_rows = global_num_rows;
949  const size_type num_cols = global_num_cols;
950  const size_type fad_size = global_fad_size;
951 
952  // Create and fill view
953  ViewType v("view", num_rows, num_cols, fad_size+1);
954  host_view_type h_v = Kokkos::create_mirror_view(v);
955  for (size_type i=0; i<num_rows; ++i) {
956  for (size_type j=0; j<num_cols; ++j) {
957  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
958  for (size_type k=0; k<fad_size; k++)
959  h_v(i,j,k) = f.dx(k);
960  h_v(i,j,fad_size) = f.val();
961  }
962  }
963  Kokkos::deep_copy(v, h_v);
964 
965  // Create unmanaged view
966  FadViewType v_fad(v.ptr_on_device(), num_rows, num_cols, fad_size+1);
967 
968  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
969  fad_host_view_type h_v_fad("host_view_fad", num_rows, num_cols, fad_size+1);
970  Kokkos::deep_copy(h_v_fad, v_fad);
971 
972  // Check
973  success = true;
974  for (size_type i=0; i<num_rows; ++i) {
975  for (size_type j=0; j<num_cols; ++j) {
976  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
977  success = success && checkFads(f, h_v_fad(i,j), out);
978  }
979  }
980 }
981 
983  Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device )
984 {
985  typedef typename FadType::value_type scalar_type;
986  typedef Kokkos::View<scalar_type***,Layout,Device> ViewType;
987  typedef Kokkos::View<FadType**,Layout,Device> FadViewType;
988  typedef typename ViewType::size_type size_type;
989  typedef typename ViewType::HostMirror host_view_type;
990  typedef typename FadViewType::HostMirror fad_host_view_type;
991 
992  const size_type num_rows = global_num_rows;
993  const size_type num_cols = global_num_cols;
994  const size_type fad_size = global_fad_size;
995 
996  // Create and fill view
997  ViewType v("view", num_rows, num_cols, fad_size+1);
998  host_view_type h_v = Kokkos::create_mirror_view(v);
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  for (size_type k=0; k<fad_size; k++)
1003  h_v(i,j,k) = f.dx(k);
1004  h_v(i,j,fad_size) = f.val();
1005  }
1006  }
1007  Kokkos::deep_copy(v, h_v);
1008 
1009  // Create unmanaged view
1010  FadViewType v_fad( v.ptr_on_device(), num_rows, num_cols, fad_size+1);
1011 
1012  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1013  fad_host_view_type h_v_fad("host_view_fad", num_rows, num_cols, fad_size+1);
1014  Kokkos::deep_copy(h_v_fad, v_fad);
1015 
1016  // Check
1017  success = true;
1018  for (size_type i=0; i<num_rows; ++i) {
1019  for (size_type j=0; j<num_cols; ++j) {
1020  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1021  success = success && checkFads(f, h_v_fad(i,j), out);
1022  }
1023  }
1024 }
1025 
1027  Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device )
1028 {
1029  typedef typename FadType::value_type scalar_type;
1030  typedef Kokkos::View<scalar_type***,Layout,Device> ViewType;
1031  typedef Kokkos::View<const scalar_type***,Layout,Device> ConstViewType;
1032  typedef Kokkos::View<FadType**,Layout,Device,Kokkos::MemoryUnmanaged> FadViewType;
1033  typedef Kokkos::View<const FadType**,Layout,Device,Kokkos::MemoryUnmanaged> ConstFadViewType;
1034  typedef typename ViewType::size_type size_type;
1035  typedef typename ViewType::HostMirror host_view_type;
1036  typedef typename FadViewType::HostMirror fad_host_view_type;
1037 
1038  const size_type num_rows = global_num_rows;
1039  const size_type num_cols = global_num_cols;
1040  const size_type fad_size = global_fad_size;
1041 
1042  // Create and fill view
1043  ViewType v("view", num_rows, num_cols, fad_size+1);
1044  host_view_type h_v = Kokkos::create_mirror_view(v);
1045  for (size_type i=0; i<num_rows; ++i) {
1046  for (size_type j=0; j<num_cols; ++j) {
1047  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1048  for (size_type k=0; k<fad_size; k++)
1049  h_v(i,j,k) = f.dx(k);
1050  h_v(i,j,fad_size) = f.val();
1051  }
1052  }
1053  Kokkos::deep_copy(v, h_v);
1054  ConstViewType v_const = v;
1055 
1056  // Create unmanaged view
1057  ConstFadViewType v_fad(
1058  v_const.ptr_on_device(), num_rows, num_cols, fad_size+1);
1059 
1060  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1061  fad_host_view_type h_v_fad("host_view_fad", num_rows, num_cols, fad_size+1);
1062  Kokkos::deep_copy(h_v_fad, v_fad);
1063 
1064  // Check
1065  success = true;
1066  for (size_type i=0; i<num_rows; ++i) {
1067  for (size_type j=0; j<num_cols; ++j) {
1068  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1069  success = success && checkFads(f, h_v_fad(i,j), out);
1070  }
1071  }
1072 }
1073 
1075  Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device )
1076 {
1077  typedef typename FadType::value_type scalar_type;
1078  typedef Kokkos::View<scalar_type***,Layout,Device> ViewType;
1079  typedef Kokkos::View<const scalar_type***,Layout,Device> ConstViewType;
1080  typedef Kokkos::View<FadType**,Layout,Device> FadViewType;
1081  typedef Kokkos::View<const FadType**,Layout,Device> ConstFadViewType;
1082  typedef typename ViewType::size_type size_type;
1083  typedef typename ViewType::HostMirror host_view_type;
1084  typedef typename FadViewType::HostMirror fad_host_view_type;
1085 
1086  const size_type num_rows = global_num_rows;
1087  const size_type num_cols = global_num_cols;
1088  const size_type fad_size = global_fad_size;
1089 
1090  // Create and fill view
1091  ViewType v("view", num_rows, num_cols, fad_size+1);
1092  host_view_type h_v = Kokkos::create_mirror_view(v);
1093  for (size_type i=0; i<num_rows; ++i) {
1094  for (size_type j=0; j<num_cols; ++j) {
1095  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1096  for (size_type k=0; k<fad_size; k++)
1097  h_v(i,j,k) = f.dx(k);
1098  h_v(i,j,fad_size) = f.val();
1099  }
1100  }
1101  Kokkos::deep_copy(v, h_v);
1102  ConstViewType v_const = v;
1103 
1104  // Create unmanaged view
1105  ConstFadViewType v_fad(v_const.ptr_on_device(), num_rows, num_cols, fad_size+1);
1106 
1107  // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1108  fad_host_view_type h_v_fad("host_view_fad", num_rows, num_cols, fad_size+1);
1109  Kokkos::deep_copy(h_v_fad, v_fad);
1110 
1111  // Check
1112  success = true;
1113  for (size_type i=0; i<num_rows; ++i) {
1114  for (size_type j=0; j<num_cols; ++j) {
1115  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1116  success = success && checkFads(f, h_v_fad(i,j), out);
1117  }
1118  }
1119 }
1120 
1121 // This test checks we can allocate a view
1122 // with SFad without specifying the fad size in the constructor
1124  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device )
1125 {
1126  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1127  typedef typename ViewType::size_type size_type;
1128  typedef typename ViewType::HostMirror host_view_type;
1129 
1130  const size_type num_rows = global_num_rows;
1131  const size_type num_cols = global_num_cols;
1132  const size_type fad_size = global_fad_size;
1133 
1134  // Create and fill view
1135  ViewType v("view", num_rows, num_cols);
1136  host_view_type h_v = Kokkos::create_mirror_view(v);
1137  for (size_type i=0; i<num_rows; ++i) {
1138  for (size_type j=0; j<num_cols; ++j) {
1139  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1140  h_v(i,j) = f;
1141  }
1142  }
1143  Kokkos::deep_copy(v, h_v);
1144 
1145  // Copy back
1146  Kokkos::deep_copy(h_v, v);
1147 
1148  // Check
1149  success = true;
1150  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v), fad_size+1, out, success);
1151  TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v), fad_size+1, out, success);
1152  for (size_type i=0; i<num_rows; ++i) {
1153  for (size_type j=0; j<num_cols; ++j) {
1154  FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1155  success = success && checkFads(f, h_v(i,j), out);
1156  }
1157  }
1158 }
1159 
1160 #else
1161 
1163  Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
1164 {
1165  typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1166  typedef typename ViewType::size_type size_type;
1167 
1168  const size_type num_rows = global_num_rows;
1169  const size_type num_cols = global_num_cols;
1170 
1171  // Compute shared memory size for View
1172  const size_type shmem_size =
1173  ViewType::shmem_size(num_rows, num_cols);
1174 
1175  // Check
1176  static const size_type align = 8;
1177  static const size_type mask = align - 1;
1178  const size_type shmem_size_expected =
1179  ( sizeof(FadType) * global_num_rows * global_num_cols + mask ) & ~mask;
1180  TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
1181 }
1182 
1184  Kokkos_View_Fad, Unmanaged, FadType, Layout, Device ) {}
1185 
1187  Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device ) {}
1188 
1190  Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device ) {}
1191 
1193  Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device ) {}
1194 
1196  Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device ) {}
1197 
1198 #endif
1199 
1200 #define VIEW_FAD_TESTS_FLD( F, L, D ) \
1201  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Size, F, L, D ) \
1202  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy, F, L, D ) \
1203  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantScalar, F, L, D ) \
1204  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantZero, F, L, D ) \
1205  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFad, F, L, D ) \
1206  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFadFull, F, L, D ) \
1207  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ScalarAssign, F, L, D ) \
1208  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged, F, L, D ) \
1209  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged2, F, L, D ) \
1210  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst, F, L, D ) \
1211  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst2, F, L, D ) \
1212  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Multiply, F, L, D ) \
1213  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyUpdate, F, L, D ) \
1214  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyConst, F, L, D ) \
1215  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyMixed, F, L, D ) \
1216  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Rank8, F, L, D ) \
1217  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Roger, F, L, D ) \
1218  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignDifferentStrides, F, L, D ) \
1219  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankDimensionScalar, F, L, D ) \
1220  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankMultiply, F, L, D ) \
1221  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewCol, F, L, D ) \
1222  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewRow, F, L, D ) \
1223  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewScalar, F, L, D ) \
1224  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Subview, F, L, D ) \
1225  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ShmemSize, F, L, D )
1226 
1227 #define VIEW_FAD_TESTS_SFLD( F, L, D ) \
1228  TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SFadNoSizeArg, F, L, D )
1229 
1230 #define VIEW_FAD_TESTS_FD( F, D ) \
1231  using Kokkos::LayoutLeft; \
1232  using Kokkos::LayoutRight; \
1233  VIEW_FAD_TESTS_FLD( F, LayoutLeft, D) \
1234  VIEW_FAD_TESTS_FLD( F, LayoutRight, D)
1235 
1236 #define VIEW_FAD_TESTS_SFD( F, D ) \
1237  using Kokkos::LayoutLeft; \
1238  using Kokkos::LayoutRight; \
1239  VIEW_FAD_TESTS_SFLD( F, LayoutLeft, D) \
1240  VIEW_FAD_TESTS_SFLD( F, LayoutRight, D)
1241 
1242 // We've unified the implementation for the different Fad variants, so
1243 // there is no reason to test ELRFad, CacheFad, and ELRCacheFad.
1247 
1248 /*
1249 typedef Sacado::ELRFad::DFad<double> ELRDFadType;
1250 typedef Sacado::ELRFad::SLFad<double,2*global_fad_size> ELRSLFadType;
1251 typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRSFadType;
1252 
1253 typedef Sacado::CacheFad::DFad<double> CacheDFadType;
1254 typedef Sacado::CacheFad::SLFad<double,2*global_fad_size> CacheSLFadType;
1255 typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheSFadType;
1256 
1257 typedef Sacado::ELRCacheFad::DFad<double> ELRCacheDFadType;
1258 typedef Sacado::ELRCacheFad::SLFad<double,2*global_fad_size> ELRCacheSLFadType;
1259 typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheSFadType;
1260 */
1261 
1262 // We can't use DFad unless we use the View specialization
1263 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1264 #define VIEW_FAD_TESTS_D( D ) \
1265  VIEW_FAD_TESTS_FD( SFadType, D ) \
1266  VIEW_FAD_TESTS_FD( SLFadType, D ) \
1267  VIEW_FAD_TESTS_FD( DFadType, D )
1268 
1269 #if 0
1270  VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
1271  VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
1272  VIEW_FAD_TESTS_FD( ELRDFadType, D ) \
1273  VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
1274  VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
1275  VIEW_FAD_TESTS_FD( CacheDFadType, D ) \
1276  VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
1277  VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
1278  VIEW_FAD_TESTS_FD( ELRCacheDFadType, D ) \
1279  VIEW_FAD_TESTS_SFD( SFadType, D ) \
1280  VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
1281  VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
1282  VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
1283 #endif
1284 
1285 #else
1286 
1287 #define VIEW_FAD_TESTS_D( D ) \
1288  VIEW_FAD_TESTS_FD( SFadType, D ) \
1289  VIEW_FAD_TESTS_FD( SLFadType, D )
1290 
1291 #if 0
1292  VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
1293  VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
1294  VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
1295  VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
1296  VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
1297  VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
1298  VIEW_FAD_TESTS_SFD( SFadType, D ) \
1299  VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
1300  VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
1301  VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
1302 #endif
1303 
1304 #endif
void f()
const int global_fad_size
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
ViewType::size_type size_type
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)
Sacado::Fad::DFad< double > FadType
Sacado::Fad::SLFad< double, 2 *global_fad_size > SLFadType
#define VIEW_FAD_TESTS_FD(F, D)
const InputViewType1 m_v1
const OutputViewType m_v2
static void apply(const InputViewType v1, const OutputViewType v2, const size_type col)
#define KOKKOS_INLINE_FUNCTION
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
ScalarAssignKernel(const ViewType &v, const ScalarType &s)
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
Sacado::Fad::DFad< double > DFadType
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
void g()
static void apply(const ViewType &v, const ScalarType &s)
const int global_num_rows
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
AssignRank2Rank1Kernel(const InputViewType v1, const OutputViewType v2, const size_type col)
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
const ScalarType m_s
InputViewType::size_type size_type
InputViewType::execution_space execution_space
const double tol
const InputViewType m_v1
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Kokkos_View_Fad, Size, FadType, Layout, Device)
Sacado::Fad::SFad< double, global_fad_size > SFadType
MultiplyKernel(const InputViewType1 v1, const InputViewType2 v2, const OutputViewType v3, const bool update)
KOKKOS_INLINE_FUNCTION void operator()(const size_type i) const
InputViewType1::size_type size_type
const int global_num_cols
ViewType::execution_space execution_space
unsigned dimension_scalar(const View &v, const ViewPack &... views)
const InputViewType2 m_v2
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)