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