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 {
450 local_scalar_type x = m_v(i);
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
1056 num_rows, size_type(2), fad_size, size_type(0), size_type(0));
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_KOKKOS) && 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
1697 Kokkos_View_Fad, Subview2, FadType, Layout, Device )
1698{
1699 typedef Kokkos::View<FadType***,Layout,Device> ViewType;
1700 typedef typename ViewType::HostMirror host_view_type;
1701
1702 // Test various subview operations to check the resulting indexing is correct.
1703 // We only need to run these tests on the host because the indexing does
1704 // not depend on the device.
1705
1706 const int num_cell = 5;
1707 const int num_qp = 4;
1708 const int num_dim = 3;
1709 const int num_deriv = 2;
1710
1711 // Create and fill view
1712 host_view_type v;
1713#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1714 v = host_view_type ("view", num_cell, num_qp, num_dim);
1715#else
1716 v = host_view_type ("view", num_cell, num_qp, num_dim, num_deriv+1);
1717#endif
1718 for (int cell=0; cell < num_cell; ++cell) {
1719 for (int qp=0; qp < num_qp; ++qp) {
1720 for (int dim = 0; dim < num_dim; ++dim) {
1721 v(cell,qp,dim).val() = 100.*cell + 10.*qp + 1.*dim;
1722 for (int deriv = 0; deriv < num_deriv; ++deriv) {
1723 v(cell,qp,dim).fastAccessDx(deriv) = v(cell,qp,dim).val() + (1.0*deriv)/10.;
1724 }
1725 }
1726 }
1727 }
1728
1729 success = true;
1730
1731 out << "checking subview(v,ALL,*,*)..." << std::endl;
1732 for (int qp=0; qp < num_qp; ++qp) {
1733 for (int dim=0; dim < num_dim; ++dim) {
1734 auto v_tmp = subview(v,Kokkos::ALL(),qp,dim);
1735 for (int cell=0; cell < num_cell; ++cell) {
1736 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1737 success = success && checkFads(v(cell,qp,dim), v_tmp(cell), out);
1738 }
1739 }
1740 }
1741
1742 out << "checking subview(v,*,ALL,*)..." << std::endl;
1743 for (int cell=0; cell < num_cell; ++cell) {
1744 for (int dim=0; dim < num_dim; ++dim) {
1745 auto v_tmp = subview(v,cell,Kokkos::ALL(),dim);
1746 for (int qp=0; qp < num_qp; ++qp) {
1747 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1748 success = success && checkFads(v(cell,qp,dim), v_tmp(qp), out);
1749 }
1750 }
1751 }
1752
1753 out << "checking subview(v,*,*,ALL)..." << std::endl;
1754 for (int cell=0; cell < num_cell; ++cell) {
1755 for (int qp=0; qp < num_qp; ++qp) {
1756 auto v_tmp = subview(v,cell,qp,Kokkos::ALL());
1757 for (int dim=0; dim < num_dim; ++dim) {
1758 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1759 success = success && checkFads(v(cell,qp,dim), v_tmp(dim), out);
1760 }
1761 }
1762 }
1763
1764 out << "checking subview(v,ALL,ALL,*)..." << std::endl;
1765 for (int dim=0; dim < num_dim; ++dim) {
1766 auto v_tmp = subview(v,Kokkos::ALL(),Kokkos::ALL(),dim);
1767 for (int cell=0; cell < num_cell; ++cell) {
1768 for (int qp=0; qp < num_qp; ++qp) {
1769 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1770 success = success && checkFads(v(cell,qp,dim), v_tmp(cell,qp), out);
1771 }
1772 }
1773 }
1774
1775 out << "checking subview(v,*,ALL,ALL)..." << std::endl;
1776 for (int cell=0; cell < num_cell; ++cell) {
1777 auto v_tmp = subview(v,cell,Kokkos::ALL(),Kokkos::ALL());
1778 for (int qp=0; qp < num_qp; ++qp) {
1779 for (int dim=0; dim < num_dim; ++dim) {
1780 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1781 success = success && checkFads(v(cell,qp,dim), v_tmp(qp,dim), out);
1782 }
1783 }
1784 }
1785
1786 out << "checking subview(v,ALL,*,ALL)..." << std::endl;
1787 for (int qp=0; qp < num_qp; ++qp) {
1788 auto v_tmp = subview(v,Kokkos::ALL(),qp,Kokkos::ALL());
1789 for (int cell=0; cell < num_cell; ++cell) {
1790 for (int dim=0; dim < num_dim; ++dim) {
1791 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1792 success = success && checkFads(v(cell,qp,dim), v_tmp(cell,dim), out);
1793 }
1794 }
1795 }
1796
1797 out << "checking subview(v,range,range,range)..." << std::endl;
1798 auto v_tmp = subview(v,std::make_pair(1,5),std::make_pair(1,4),std::make_pair(1,3));
1799 for (int cell=1; cell < num_cell; ++cell) {
1800 for (int qp=1; qp < num_qp; ++qp) {
1801 for (int dim=1; dim < num_dim; ++dim) {
1802 out << "\tChecking (" << cell << "," << qp << "," << dim << ")" << std::endl;
1803 success = success && checkFads(v(cell,qp,dim), v_tmp(cell-1,qp-1,dim-1), out);
1804 }
1805 }
1806 }
1807}
1808
1809#ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
1811 Kokkos_View_Fad, ConstViewAssign, FadType, Layout, Device )
1812{
1813 typedef Kokkos::View<FadType*,Layout,Device> ViewType;
1814 typedef Kokkos::View<const FadType,Layout,Device> ConstViewType;
1815 typedef typename ViewType::size_type size_type;
1816 typedef typename ViewType::HostMirror host_view_type;
1817 typedef typename ViewType::execution_space exec_space;
1818
1819 const size_type num_rows = global_num_rows;
1820 const size_type fad_size = global_fad_size;
1821
1822 // Create and fill view
1823#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1824 ViewType v1("view1", num_rows);
1825#else
1826 ViewType v1("view1", num_rows, fad_size+1);
1827#endif
1828 host_view_type h_v1 = Kokkos::create_mirror_view(v1);
1829 for (size_type i=0; i<num_rows; ++i) {
1830 FadType f = generate_fad<FadType>(num_rows, size_type(1), fad_size, i,
1831 size_type(0));
1832 h_v1(i) = f;
1833 }
1834 Kokkos::deep_copy(v1, h_v1);
1835
1836#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1837 ViewType v2("view2", num_rows);
1838#else
1839 ViewType v2("view2", num_rows, fad_size+1);
1840#endif
1841
1842 static const size_type stride = Kokkos::ViewScalarStride<ViewType>::stride;
1843#if defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
1844 const bool use_team =
1845 std::is_same<exec_space, Kokkos::Cuda>::value &&
1846 ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
1847 Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
1848 ( stride > 1 );
1849#elif defined (KOKKOS_ENABLE_CUDA) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
1850 const bool use_team =
1851 std::is_same<exec_space, Kokkos::Cuda>::value &&
1852 ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
1853 Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
1855#elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL)
1856 const bool use_team =
1857 std::is_same<exec_space, Kokkos::Experimental::HIP>::value &&
1858 ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
1859 Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
1860 ( stride > 1 );
1861#elif defined (KOKKOS_ENABLE_HIP) && defined (SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
1862 const bool use_team =
1863 std::is_same<exec_space, Kokkos::Experimental::HIP>::value &&
1864 ( Kokkos::is_view_fad_contiguous<ViewType>::value ||
1865 Kokkos::is_dynrankview_fad_contiguous<ViewType>::value ) &&
1867#else
1868 const bool use_team = false;
1869#endif
1870
1871 if (use_team) {
1872 typedef Kokkos::TeamPolicy<exec_space> team_policy;
1873 Kokkos::parallel_for(team_policy(num_rows, 1, stride),
1874 KOKKOS_LAMBDA(typename team_policy::member_type team)
1875 {
1876 const int i = team.league_rank();
1877 typename ConstViewType::reference_type x = v1(i);
1878 v2(i) = x;
1879 });
1880 }
1881 else {
1882 Kokkos::parallel_for(Kokkos::RangePolicy<exec_space>(0,num_rows),
1883 KOKKOS_LAMBDA(const int i)
1884 {
1885 typename ConstViewType::reference_type x = v1(i);
1886 v2(i) = x;
1887 });
1888 }
1889
1890 // Copy back
1891 host_view_type h_v2 = Kokkos::create_mirror_view(v2);
1892 Kokkos::deep_copy(h_v2, v2);
1893
1894 // Check
1895 success = true;
1896 for (size_type i=0; i<num_rows; ++i) {
1897 FadType f = generate_fad<FadType>(num_rows, size_type(1), fad_size, i,
1898 size_type(0));
1899 success = success && checkFads(f, h_v2(i), out);
1900 }
1901}
1902#else
1904 Kokkos_View_Fad, ConstViewAssign, FadType, Layout, Device ) {}
1905#endif
1906
1907// Tests that require view spec
1908
1909#if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1911 Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
1912{
1913 typedef Kokkos::View<FadType**,Layout,Device> ViewType;
1914 typedef typename FadType::value_type value_type;
1915 typedef typename ViewType::size_type size_type;
1916
1917 const size_type num_rows = global_num_rows;
1918 const size_type num_cols = global_num_cols;
1919 const size_type fad_size = global_fad_size;
1920
1921 // Compute shared memory size for View
1922 const size_type shmem_size =
1923 ViewType::shmem_size(num_rows, num_cols, fad_size+1);
1924
1925 // Check
1926 const size_type align = 8;
1927 const size_type mask = align - 1;
1928 ViewType v;
1929#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1930 v = ViewType ("view", num_rows, num_cols);
1931#else
1932 v = ViewType ("view", num_rows, num_cols, fad_size+1);
1933#endif
1934 const size_type shmem_size_expected =
1935 (( sizeof(value_type) * global_num_rows * global_num_cols * (fad_size+1) + mask ) & ~mask) + sizeof(typename ViewType::traits::value_type);
1936 TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
1937}
1938
1940 Kokkos_View_Fad, Unmanaged, FadType, Layout, Device )
1941{
1942 // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
1943 typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
1944
1945 typedef typename FadType::value_type scalar_type;
1946 typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
1947 typedef Kokkos::View<FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> FadViewType;
1948 typedef typename ViewType::size_type size_type;
1949 typedef typename ViewType::HostMirror host_view_type;
1950 typedef typename FadViewType::HostMirror fad_host_view_type;
1951
1952 const size_type num_rows = global_num_rows;
1953 const size_type num_cols = global_num_cols;
1954 const size_type fad_size = global_fad_size;
1955
1956 // Create and fill view
1957 ViewType v;
1958 host_view_type h_v;
1959 if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
1960 std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
1961 v = ViewType ("view", fad_size+1, num_rows, num_cols);
1962 h_v = Kokkos::create_mirror_view(v);
1963 for (size_type i=0; i<num_rows; ++i) {
1964 for (size_type j=0; j<num_cols; ++j) {
1965 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1966 for (size_type k=0; k<fad_size; k++)
1967 h_v(k,i,j) = f.dx(k);
1968 h_v(fad_size,i,j) = f.val();
1969 }
1970 }
1971 }
1972 else {
1973 v = ViewType ("view", num_rows, num_cols, fad_size+1);
1974 h_v = Kokkos::create_mirror_view(v);
1975 for (size_type i=0; i<num_rows; ++i) {
1976 for (size_type j=0; j<num_cols; ++j) {
1977 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
1978 for (size_type k=0; k<fad_size; k++)
1979 h_v(i,j,k) = f.dx(k);
1980 h_v(i,j,fad_size) = f.val();
1981 }
1982 }
1983 }
1984 Kokkos::deep_copy(v, h_v);
1985
1986 // Create unmanaged view
1987 FadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
1988 fad_host_view_type h_v_fad;
1989#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
1990 v_fad = FadViewType ( v.data(), num_rows, num_cols);
1991 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
1992#else
1993 v_fad = FadViewType ( v.data(), num_rows, num_cols, fad_size+1);
1994 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
1995#endif
1996
1997 // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
1998 Kokkos::deep_copy(h_v_fad, v_fad);
1999
2000 // Check
2001 success = true;
2002 for (size_type i=0; i<num_rows; ++i) {
2003 for (size_type j=0; j<num_cols; ++j) {
2004 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2005 success = success && checkFads(f, h_v_fad(i,j), out);
2006 }
2007 }
2008}
2009
2011 Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device )
2012{
2013 // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2014 typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2015
2016 typedef typename FadType::value_type scalar_type;
2017 typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2018 typedef Kokkos::View<FadType**,TestLayout,Device> FadViewType;
2019 typedef typename ViewType::size_type size_type;
2020 typedef typename ViewType::HostMirror host_view_type;
2021 typedef typename FadViewType::HostMirror fad_host_view_type;
2022
2023 const size_type num_rows = global_num_rows;
2024 const size_type num_cols = global_num_cols;
2025 const size_type fad_size = global_fad_size;
2026
2027 // Create and fill view
2028 ViewType v;
2029 host_view_type h_v;
2030 if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
2031 std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
2032 v = ViewType ("view", fad_size+1, num_rows, num_cols);
2033 h_v = Kokkos::create_mirror_view(v);
2034 for (size_type i=0; i<num_rows; ++i) {
2035 for (size_type j=0; j<num_cols; ++j) {
2036 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2037 for (size_type k=0; k<fad_size; k++)
2038 h_v(k,i,j) = f.dx(k);
2039 h_v(fad_size,i,j) = f.val();
2040 }
2041 }
2042 }
2043 else {
2044 v = ViewType ("view", num_rows, num_cols, fad_size+1);
2045 h_v = Kokkos::create_mirror_view(v);
2046 for (size_type i=0; i<num_rows; ++i) {
2047 for (size_type j=0; j<num_cols; ++j) {
2048 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2049 for (size_type k=0; k<fad_size; k++)
2050 h_v(i,j,k) = f.dx(k);
2051 h_v(i,j,fad_size) = f.val();
2052 }
2053 }
2054 }
2055 Kokkos::deep_copy(v, h_v);
2056
2057 // Create unmanaged view
2058 FadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
2059 fad_host_view_type h_v_fad;
2060#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2061 v_fad = FadViewType ( v.data(), num_rows, num_cols);
2062 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2063#else
2064 v_fad = FadViewType ( v.data(), num_rows, num_cols, fad_size+1);
2065 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2066#endif
2067
2068 // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2069 Kokkos::deep_copy(h_v_fad, v_fad);
2070
2071 // Check
2072 success = true;
2073 for (size_type i=0; i<num_rows; ++i) {
2074 for (size_type j=0; j<num_cols; ++j) {
2075 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2076 success = success && checkFads(f, h_v_fad(i,j), out);
2077 }
2078 }
2079}
2080
2082 Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device )
2083{
2084 // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2085 typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2086
2087 typedef typename FadType::value_type scalar_type;
2088 typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2089 typedef Kokkos::View<const scalar_type***,TestLayout,Device> ConstViewType;
2090 typedef Kokkos::View<FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> FadViewType;
2091 typedef Kokkos::View<const FadType**,TestLayout,Device,Kokkos::MemoryUnmanaged> ConstFadViewType;
2092 typedef typename ViewType::size_type size_type;
2093 typedef typename ViewType::HostMirror host_view_type;
2094 typedef typename FadViewType::HostMirror fad_host_view_type;
2095
2096 const size_type num_rows = global_num_rows;
2097 const size_type num_cols = global_num_cols;
2098 const size_type fad_size = global_fad_size;
2099
2100 // Create and fill view
2101 ViewType v;
2102 host_view_type h_v;
2103 if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
2104 std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
2105 v = ViewType ("view", fad_size+1, num_rows, num_cols);
2106 h_v = Kokkos::create_mirror_view(v);
2107 for (size_type i=0; i<num_rows; ++i) {
2108 for (size_type j=0; j<num_cols; ++j) {
2109 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2110 for (size_type k=0; k<fad_size; k++)
2111 h_v(k,i,j) = f.dx(k);
2112 h_v(fad_size,i,j) = f.val();
2113 }
2114 }
2115 }
2116 else {
2117 v = ViewType ("view", num_rows, num_cols, fad_size+1);
2118 h_v = Kokkos::create_mirror_view(v);
2119 for (size_type i=0; i<num_rows; ++i) {
2120 for (size_type j=0; j<num_cols; ++j) {
2121 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2122 for (size_type k=0; k<fad_size; k++)
2123 h_v(i,j,k) = f.dx(k);
2124 h_v(i,j,fad_size) = f.val();
2125 }
2126 }
2127 }
2128 Kokkos::deep_copy(v, h_v);
2129 ConstViewType v_const = v;
2130
2131 // Create unmanaged view
2132
2133 ConstFadViewType v_fad;//( v.data(), num_rows, num_cols, fad_size+1);
2134 fad_host_view_type h_v_fad;
2135#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2136 v_fad = ConstFadViewType ( v_const.data(), num_rows, num_cols);
2137 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2138#else
2139 v_fad = ConstFadViewType ( v_const.data(), num_rows, num_cols, fad_size+1);
2140 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2141#endif
2142
2143 // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2144 Kokkos::deep_copy(h_v_fad, v_fad);
2145
2146 // Check
2147 success = true;
2148 for (size_type i=0; i<num_rows; ++i) {
2149 for (size_type j=0; j<num_cols; ++j) {
2150 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2151 success = success && checkFads(f, h_v_fad(i,j), out);
2152 }
2153 }
2154}
2155
2157 Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device )
2158{
2159 // For LayoutContiguous or LayoutNatural, strip out the layout they are templated on
2160 typedef typename Kokkos::inner_layout<Layout>::type TestLayout;
2161 typedef typename FadType::value_type scalar_type;
2162 typedef Kokkos::View<scalar_type***,TestLayout,Device> ViewType;
2163 typedef Kokkos::View<const scalar_type***,TestLayout,Device> ConstViewType;
2164 typedef Kokkos::View<FadType**,TestLayout,Device> FadViewType;
2165 typedef Kokkos::View<const FadType**,TestLayout,Device> ConstFadViewType;
2166 typedef typename ViewType::size_type size_type;
2167 typedef typename ViewType::HostMirror host_view_type;
2168 typedef typename FadViewType::HostMirror fad_host_view_type;
2169
2170 const size_type num_rows = global_num_rows;
2171 const size_type num_cols = global_num_cols;
2172 const size_type fad_size = global_fad_size;
2173
2174 // Create and fill view
2175 ViewType v;
2176 host_view_type h_v;
2177 if (Kokkos::is_view_fad_contiguous<FadViewType>::value &&
2178 std::is_same<TestLayout, Kokkos::LayoutLeft >::value) {
2179 v = ViewType ("view", fad_size+1, num_rows, num_cols);
2180 h_v = Kokkos::create_mirror_view(v);
2181 for (size_type i=0; i<num_rows; ++i) {
2182 for (size_type j=0; j<num_cols; ++j) {
2183 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2184 for (size_type k=0; k<fad_size; k++)
2185 h_v(k,i,j) = f.dx(k);
2186 h_v(fad_size,i,j) = f.val();
2187 }
2188 }
2189 }
2190 else {
2191 v = ViewType ("view", num_rows, num_cols, fad_size+1);
2192 h_v = Kokkos::create_mirror_view(v);
2193 for (size_type i=0; i<num_rows; ++i) {
2194 for (size_type j=0; j<num_cols; ++j) {
2195 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2196 for (size_type k=0; k<fad_size; k++)
2197 h_v(i,j,k) = f.dx(k);
2198 h_v(i,j,fad_size) = f.val();
2199 }
2200 }
2201 }
2202 Kokkos::deep_copy(v, h_v);
2203 ConstViewType v_const = v;
2204
2205 // Create unmanaged view
2206 ConstFadViewType v_fad;
2207 fad_host_view_type h_v_fad;
2208#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2209 v_fad = ConstFadViewType (v_const.data(), num_rows, num_cols);
2210 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols);
2211#else
2212 v_fad = ConstFadViewType (v_const.data(), num_rows, num_cols, fad_size+1);
2213 h_v_fad = fad_host_view_type ("host_view_fad", num_rows, num_cols, fad_size+1);
2214#endif
2215
2216 // Copy back -- can't use create_mirror_view() because v_fad is unmanaged
2217 Kokkos::deep_copy(h_v_fad, v_fad);
2218
2219 // Check
2220 success = true;
2221 for (size_type i=0; i<num_rows; ++i) {
2222 for (size_type j=0; j<num_cols; ++j) {
2223 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2224 success = success && checkFads(f, h_v_fad(i,j), out);
2225 }
2226 }
2227}
2228
2229// This test checks we can allocate a view
2230// with SFad without specifying the fad size in the constructor
2232 Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device )
2233{
2234 typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2235 typedef typename ViewType::size_type size_type;
2236 typedef typename ViewType::HostMirror host_view_type;
2237
2238 const size_type num_rows = global_num_rows;
2239 const size_type num_cols = global_num_cols;
2240 const size_type fad_size = global_fad_size;
2241
2242 // Create and fill view
2243 ViewType v("view", num_rows, num_cols);
2244 host_view_type h_v = Kokkos::create_mirror_view(v);
2245 for (size_type i=0; i<num_rows; ++i) {
2246 for (size_type j=0; j<num_cols; ++j) {
2247 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2248 h_v(i,j) = f;
2249 }
2250 }
2251 Kokkos::deep_copy(v, h_v);
2252
2253 // Copy back
2254 Kokkos::deep_copy(h_v, v);
2255
2256 // Check
2257 success = true;
2258 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v), fad_size+1, out, success);
2259 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v), 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_v(i,j), out);
2264 }
2265 }
2266}
2267
2269 Kokkos_View_Fad, Partition, FadType, Layout, Device )
2270{
2271#if !defined(SACADO_VIEW_CUDA_HIERARCHICAL) && !defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)
2272 typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2273 typedef typename ViewType::size_type size_type;
2274 typedef typename ViewType::HostMirror host_view_type;
2275
2276 const size_type num_rows = global_num_rows;
2277 const size_type num_cols = global_num_cols;
2278 const size_type fad_size = global_fad_size;
2279
2280 // Create and fill view
2281 ViewType v;
2282#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2283 v = ViewType ("view", num_rows, num_cols);
2284#else
2285 v = ViewType ("view", num_rows, num_cols, fad_size+1);
2286#endif
2287 host_view_type h_v = Kokkos::create_mirror_view(v);
2288
2289 for (size_type i=0; i<num_rows; ++i) {
2290 for (size_type j=0; j<num_cols; ++j) {
2291 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2292 h_v(i,j) = f;
2293 }
2294 }
2295 Kokkos::deep_copy(v, h_v);
2296
2297 // Copy back
2298 Kokkos::deep_copy(h_v, v);
2299
2300 // Partition derivative array of h_v into 2, first one starting at index 0,
2301 // the second at 1
2302 const size_type stride = 2;
2303 auto h_v1 = Kokkos::partition<2>(h_v, 0, stride);
2304 auto h_v2 = Kokkos::partition<2>(h_v, 1, stride);
2305
2306 // Check
2307 const size_type fad_size_1 = (fad_size + stride - 0 - 1) / stride;
2308 const size_type fad_size_2 = (fad_size + stride - 1 - 1) / stride;
2309 success = true;
2310 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v1), fad_size_1+1, out, success);
2311 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_v2), fad_size_2+1, out, success);
2312 for (size_type i=0; i<num_rows; ++i) {
2313 for (size_type j=0; j<num_cols; ++j) {
2314 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2315 Sacado::Fad::DFad<double> f1( fad_size_1, f.val() );
2316 Sacado::Fad::DFad<double> f2( fad_size_2, f.val() );
2317 for (unsigned int k=0; k<fad_size_1; ++k)
2318 if (2*k < fad_size) f1.fastAccessDx(k) = f.dx(2*k);
2319 for (unsigned int k=0; k<fad_size_2; ++k)
2320 if (2*k+1 < fad_size) f2.fastAccessDx(k) = f.dx(2*k+1);
2321 success = success && checkFads(f1, h_v1(i,j), out);
2322 success = success && checkFads(f2, h_v2(i,j), out);
2323 }
2324 }
2325#endif
2326}
2327
2329 Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, FadType, Layout, Device )
2330{
2331 typedef Kokkos::View<FadType**,Kokkos::LayoutContiguous<Layout>,Device> ContViewType;
2332 typedef Kokkos::View<FadType**,Kokkos::LayoutStride,Device> StrideViewType;
2333 typedef typename ContViewType::size_type size_type;
2334 typedef typename ContViewType::HostMirror cont_host_view_type;
2335 typedef typename StrideViewType::HostMirror stride_host_view_type;
2336
2337 const size_type num_rows = global_num_rows;
2338 const size_type num_cols = global_num_cols;
2339 const size_type fad_size = global_fad_size;
2340
2341 // Create and fill view
2342 ContViewType v;
2343#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2344 v = ContViewType ("view", num_rows, num_cols);
2345#else
2346 v = ContViewType ("view", num_rows, num_cols, fad_size+1);
2347#endif
2348 cont_host_view_type h_v = Kokkos::create_mirror_view(v);
2349
2350 for (size_type i=0; i<num_rows; ++i) {
2351 for (size_type j=0; j<num_cols; ++j) {
2352 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2353 h_v(i,j) = f;
2354 }
2355 }
2356 Kokkos::deep_copy(v, h_v);
2357
2358 // Assign to LayoutStride view
2359 StrideViewType vs = v;
2360
2361 // Copy back
2362 // Note: don't create h_vs through create_mirror_view and deep_copy
2363 // since Kokkos doesn't support deep_copy of non-contiguous views
2364 //stride_host_view_type h_vs = Kokkos::create_mirror_view(vs);
2365 //Kokkos::deep_copy(h_vs, vs);
2366 stride_host_view_type h_vs = h_v;
2367
2368 // Check
2369 success = true;
2370 TEUCHOS_TEST_EQUALITY(h_vs.extent(0), num_rows, out, success);
2371 TEUCHOS_TEST_EQUALITY(h_vs.extent(1), num_cols, out, success);
2372 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(h_vs), fad_size+1, out, success);
2373 for (size_type i=0; i<num_rows; ++i) {
2374 for (size_type j=0; j<num_cols; ++j) {
2375 FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j);
2376 success = success && checkFads(f, h_vs(i,j), out);
2377 }
2378 }
2379}
2380
2382 Kokkos_View_Fad, CommonViewAllocMixedSpec, FadType, Layout, Device )
2383{
2384 typedef Kokkos::View<FadType**,Kokkos::LayoutContiguous<Layout>,Device> ContViewType;
2385 typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2386 typedef typename ContViewType::size_type size_type;
2387
2388 const size_type num_rows = global_num_rows;
2389 const size_type num_cols = global_num_cols;
2390 const size_type fad_size = global_fad_size;
2391
2392 // Create contiguous view
2393 ContViewType v1;
2394#if defined (SACADO_DISABLE_FAD_VIEW_SPEC)
2395 v1 = ContViewType ("view", num_rows, num_cols);
2396#else
2397 v1 = ContViewType ("view", num_rows, num_cols, fad_size+1);
2398#endif
2399
2400 // Create non-contiguous view using commen_view_alloc_prop
2401 auto cprop = Kokkos::common_view_alloc_prop(v1);
2402 ViewType v2(Kokkos::view_alloc("v2",cprop), num_rows, num_cols);
2403
2404 // Check dimensions are correct for v2
2405 success = true;
2406 TEUCHOS_TEST_EQUALITY(v2.extent(0), num_rows, out, success);
2407 TEUCHOS_TEST_EQUALITY(v2.extent(1), num_cols, out, success);
2408 TEUCHOS_TEST_EQUALITY(Kokkos::dimension_scalar(v2), fad_size+1, out, success);
2409}
2410
2411#else
2412
2414 Kokkos_View_Fad, ShmemSize, FadType, Layout, Device )
2415{
2416 typedef Kokkos::View<FadType**,Layout,Device> ViewType;
2417 typedef typename ViewType::size_type size_type;
2418
2419 const size_type num_rows = global_num_rows;
2420 const size_type num_cols = global_num_cols;
2421
2422 // Compute shared memory size for View
2423 const size_type shmem_size =
2424 ViewType::shmem_size(num_rows, num_cols);
2425
2426 // Check
2427 static const size_type align = 8;
2428 static const size_type mask = align - 1;
2429 const size_type shmem_size_expected =
2430 (( sizeof(FadType) * global_num_rows * global_num_cols + mask ) & ~mask) + sizeof(typename ViewType::traits::value_type);
2431 TEUCHOS_TEST_EQUALITY(shmem_size, shmem_size_expected, out, success);
2432}
2433
2435 Kokkos_View_Fad, Unmanaged, FadType, Layout, Device ) {}
2436
2438 Kokkos_View_Fad, Unmanaged2, FadType, Layout, Device ) {}
2439
2441 Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device ) {}
2442
2444 Kokkos_View_Fad, UnmanagedConst2, FadType, Layout, Device ) {}
2445
2447 Kokkos_View_Fad, SFadNoSizeArg, FadType, Layout, Device ) {}
2448
2450 Kokkos_View_Fad, Partition, FadType, Layout, Device ) {}
2451
2453 Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, FadType, Layout, Device ) {}
2454
2456 Kokkos_View_Fad, CommonViewAllocMixedSpec, FadType, Layout, Device ) {}
2457
2458#endif
2459
2460#define VIEW_FAD_TESTS_FLD( F, L, D ) \
2461 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Size, F, L, D ) \
2462 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy, F, L, D ) \
2463 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantScalar, F, L, D ) \
2464 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantZero, F, L, D ) \
2465 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFad, F, L, D ) \
2466 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DeepCopy_ConstantFadFull, F, L, D ) \
2467 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ScalarAssign, F, L, D ) \
2468 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ValueAssign, F, L, D ) \
2469 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Resize, F, L, D ) \
2470 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged, F, L, D ) \
2471 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Unmanaged2, F, L, D ) \
2472 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst, F, L, D ) \
2473 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, UnmanagedConst2, F, L, D ) \
2474 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Multiply, F, L, D ) \
2475 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyUpdate, F, L, D ) \
2476 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyConst, F, L, D ) \
2477 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, MultiplyMixed, F, L, D ) \
2478 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Rank8, F, L, D ) \
2479 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Roger, F, L, D ) \
2480 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AtomicAdd, F, L, D ) \
2481 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignDifferentStrides, F, L, D ) \
2482 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ScalarValue, F, L, D ) \
2483 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankDimensionScalar, F, L, D ) \
2484 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic0, F, L, D ) \
2485 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic1, F, L, D ) \
2486 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankAssignStatic2, F, L, D ) \
2487 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, DynRankMultiply, F, L, D ) \
2488 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewCol, F, L, D ) \
2489 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewRow, F, L, D ) \
2490 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SubdynrankviewScalar, F, L, D ) \
2491 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Subview, F, L, D ) \
2492 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Subview2, F, L, D ) \
2493 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ShmemSize, F, L, D ) \
2494 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, ConstViewAssign, F, L, D )
2495
2496#define VIEW_FAD_TESTS_SFLD( F, L, D ) \
2497 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, SFadNoSizeArg, F, L, D )
2498
2499#define VIEW_FAD_TESTS_FDI( F, D ) \
2500 using Kokkos::LayoutLeft; \
2501 using Kokkos::LayoutRight; \
2502 VIEW_FAD_TESTS_FLD( F, LayoutLeft, D ) \
2503 VIEW_FAD_TESTS_FLD( F, LayoutRight, D ) \
2504 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, F, LayoutLeft, D ) \
2505 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, AssignLayoutContiguousToLayoutStride, F, LayoutRight, D ) \
2506 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, CommonViewAllocMixedSpec, F, LayoutLeft, D ) \
2507 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, CommonViewAllocMixedSpec, F, LayoutRight, D )
2508
2509#define VIEW_FAD_TESTS_SFDI( F, D ) \
2510 using Kokkos::LayoutLeft; \
2511 using Kokkos::LayoutRight; \
2512 VIEW_FAD_TESTS_SFLD( F, LayoutLeft, D ) \
2513 VIEW_FAD_TESTS_SFLD( F, LayoutRight, D )
2514
2515#if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2518#define VIEW_FAD_TESTS_FDC( F, D ) \
2519 VIEW_FAD_TESTS_FLD( F, LeftContiguous, D ) \
2520 VIEW_FAD_TESTS_FLD( F, RightContiguous, D ) \
2521 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Partition, F, LeftContiguous, D ) \
2522 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_Fad, Partition, F, RightContiguous, D )
2523
2524#define VIEW_FAD_TESTS_SFDC( F, D ) \
2525 VIEW_FAD_TESTS_SFLD( F, LeftContiguous, D ) \
2526 VIEW_FAD_TESTS_SFLD( F, RightContiguous, D )
2527#else
2528#define VIEW_FAD_TESTS_FDC( F, D ) /* */
2529#define VIEW_FAD_TESTS_SFDC( F, D ) /* */
2530#endif
2531
2532#define VIEW_FAD_TESTS_FD( F, D ) \
2533 VIEW_FAD_TESTS_FDI( F, D ) \
2534 VIEW_FAD_TESTS_FDC( F, D )
2535
2536#define VIEW_FAD_TESTS_SFD( F, D ) \
2537 VIEW_FAD_TESTS_SFDI( F, D ) \
2538 VIEW_FAD_TESTS_SFDC( F, D )
2539
2540// We've unified the implementation for the different Fad variants, so
2541// there is no reason to test ELRFad, CacheFad, and ELRCacheFad.
2545
2546/*
2547typedef Sacado::ELRFad::DFad<double> ELRDFadType;
2548typedef Sacado::ELRFad::SLFad<double,2*global_fad_size> ELRSLFadType;
2549typedef Sacado::ELRFad::SFad<double,global_fad_size> ELRSFadType;
2550
2551typedef Sacado::CacheFad::DFad<double> CacheDFadType;
2552typedef Sacado::CacheFad::SLFad<double,2*global_fad_size> CacheSLFadType;
2553typedef Sacado::CacheFad::SFad<double,global_fad_size> CacheSFadType;
2554
2555typedef Sacado::ELRCacheFad::DFad<double> ELRCacheDFadType;
2556typedef Sacado::ELRCacheFad::SLFad<double,2*global_fad_size> ELRCacheSLFadType;
2557typedef Sacado::ELRCacheFad::SFad<double,global_fad_size> ELRCacheSFadType;
2558*/
2559
2560// We can't use DFad unless we use the View specialization
2561#if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) && SACADO_TEST_DFAD
2562#define VIEW_FAD_TESTS_D( D ) \
2563 VIEW_FAD_TESTS_FD( SFadType, D ) \
2564 VIEW_FAD_TESTS_FD( SLFadType, D ) \
2565 VIEW_FAD_TESTS_FD( DFadType, D ) \
2566 VIEW_FAD_TESTS_SFD( SFadType, D )
2567
2568#if 0
2569 VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
2570 VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
2571 VIEW_FAD_TESTS_FD( ELRDFadType, D ) \
2572 VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
2573 VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
2574 VIEW_FAD_TESTS_FD( CacheDFadType, D ) \
2575 VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
2576 VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
2577 VIEW_FAD_TESTS_FD( ELRCacheDFadType, D ) \
2578 VIEW_FAD_TESTS_SFD( SFadType, D ) \
2579 VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
2580 VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
2581 VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
2582#endif
2583
2584#else
2585
2586#define VIEW_FAD_TESTS_D( D ) \
2587 VIEW_FAD_TESTS_FD( SFadType, D ) \
2588 VIEW_FAD_TESTS_FD( SLFadType, D ) \
2589 VIEW_FAD_TESTS_SFD( SFadType, D )
2590
2591#if 0
2592 VIEW_FAD_TESTS_FD( ELRSFadType, D ) \
2593 VIEW_FAD_TESTS_FD( ELRSLFadType, D ) \
2594 VIEW_FAD_TESTS_FD( CacheSFadType, D ) \
2595 VIEW_FAD_TESTS_FD( CacheSLFadType, D ) \
2596 VIEW_FAD_TESTS_FD( ELRCacheSFadType, D ) \
2597 VIEW_FAD_TESTS_FD( ELRCacheSLFadType, D ) \
2598 VIEW_FAD_TESTS_SFD( SFadType, D ) \
2599 VIEW_FAD_TESTS_SFD( ELRSFadType, D ) \
2600 VIEW_FAD_TESTS_SFD( CacheSFadType, D ) \
2601 VIEW_FAD_TESTS_SFD( ELRCacheSFadType, D )
2602#endif
2603
2604#endif
const int global_fad_size
const int global_num_rows
const int global_num_cols
Kokkos::LayoutContiguous< Kokkos::LayoutRight > RightContiguous
#define GLOBAL_FAD_SIZE
Kokkos::LayoutContiguous< Kokkos::LayoutLeft > LeftContiguous
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
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)
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Kokkos_View_Fad, Size, FadType, Layout, Device)
Sacado::Fad::DFad< double > DFadType
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::SFad< double, fad_dim > SFadType
Sacado::Fad::SLFad< double, fad_dim > SLFadType
Sacado::Fad::DFad< double > FadType
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