Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_KokkosViewUQPCEUnitTest.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
45 
50 
51 //
52 // Tests various View< Sacado::UQ::PCE<...>,...> operations work
53 // as expected
54 //
55 
56 // Helper functions
57 
58 template <typename kokkos_cijk_type, typename ordinal_type>
61 {
62  using Teuchos::RCP;
63  using Teuchos::rcp;
64  using Teuchos::Array;
65 
72 
73  // Create product basis
74  Array< RCP<const one_d_basis> > bases(stoch_dim);
75  for (ordinal_type i=0; i<stoch_dim; i++)
76  bases[i] = rcp(new legendre_basis(poly_ord, true));
77  RCP<const product_basis> basis = rcp(new product_basis(bases));
78 
79  // Triple product tensor
80  RCP<Cijk> cijk = basis->computeTripleProductTensor();
81 
82  // Kokkos triple product tensor
83  kokkos_cijk_type kokkos_cijk =
84  Stokhos::create_product_tensor<execution_space>(*basis, *cijk);
85 
86  return kokkos_cijk;
87 }
88 
89 template <typename scalar, typename ordinal>
90 inline
91 scalar generate_pce_coefficient( const ordinal nFEM,
92  const ordinal nStoch,
93  const ordinal iColFEM,
94  const ordinal iStoch )
95 {
96  const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
97  const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
98  return X_fem + X_stoch;
99  //return 1.0;
100 }
101 
102 template <typename ViewType>
103 bool
104 checkPCEView(const ViewType& v, Teuchos::FancyOStream& out) {
105  typedef ViewType view_type;
106  typedef typename view_type::size_type size_type;
107  typedef typename view_type::HostMirror host_view_type;
108  typedef typename host_view_type::array_type host_array_type;
109  typedef typename host_array_type::value_type scalar_type;
110 
111  // Copy to host
112  host_view_type h_v = Kokkos::create_mirror_view(v);
113  Kokkos::deep_copy(h_v, v);
114  host_array_type h_a = h_v;
115 
116  size_type num_rows, num_cols;
117 
118  // For layout left, sacado dimension becomes first dimension
119  // instead of last
120  bool is_right = std::is_same< typename ViewType::array_layout,
121  Kokkos::LayoutRight >::value;
122  if (is_right) {
123  num_rows = h_a.extent(0);
124  num_cols = h_a.extent(1);
125  }
126  else {
127  num_rows = h_a.extent(1);
128  num_cols = h_a.extent(0);
129  }
130  bool success = true;
131  if (is_right) {
132  for (size_type i=0; i<num_rows; ++i) {
133  for (size_type j=0; j<num_cols; ++j) {
134  scalar_type val = h_a(i,j);
135  scalar_type val_expected =
136  generate_pce_coefficient<scalar_type>(
137  num_rows, num_cols, i, j);
138  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
139  }
140  }
141  }
142  else {
143  for (size_type i=0; i<num_rows; ++i) {
144  for (size_type j=0; j<num_cols; ++j) {
145  scalar_type val = h_a(j,i);
146  scalar_type val_expected =
147  generate_pce_coefficient<scalar_type>(
148  num_rows, num_cols, i, j);
149  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
150  }
151  }
152  }
153 
154  return success;
155 }
156 
157 template <typename ViewType>
158 bool
159 checkConstantPCEView(const ViewType& v,
160  const typename ViewType::value_type& v_expected,
161  Teuchos::FancyOStream& out) {
162  typedef ViewType view_type;
163  typedef typename view_type::size_type size_type;
164  typedef typename view_type::HostMirror host_view_type;
166 
167  // Copy to host
168  host_view_type h_v = Kokkos::create_mirror_view(v);
169  Kokkos::deep_copy(h_v, v);
170 
171  const size_type num_rows = h_v.extent(0);
172  const size_type num_cols = Kokkos::dimension_scalar(h_v);
173 
174  bool success = true;
175  for (size_type i=0; i<num_rows; ++i) {
176  for (size_type j=0; j<num_cols; ++j) {
177  scalar_type val = h_v(i).coeff(j);
178  scalar_type val_expected = v_expected.coeff(j);
179  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
180  }
181  }
182 
183  return success;
184 }
185 
186 template <typename DataType, typename LayoutType, typename ExecutionSpace>
187 struct ApplyView {
188  typedef Kokkos::View<DataType,LayoutType,ExecutionSpace> type;
189 };
190 
191 struct NoLayout {};
192 template <typename DataType, typename ExecutionSpace>
193 struct ApplyView<DataType,NoLayout,ExecutionSpace> {
194  typedef Kokkos::View<DataType,ExecutionSpace> type;
195 };
196 
197 //
198 // Tests
199 //
200 
201 const int global_num_rows = 11;
202 const int global_num_cols = 9;
203 
204 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, Size, Storage, Layout )
205 {
206  typedef typename Storage::execution_space Device;
207  typedef Sacado::UQ::PCE<Storage> PCE;
208  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
209  typedef typename ViewType::size_type size_type;
210  //typedef size_t size_type;
211  typedef typename PCE::cijk_type Cijk;
212 
213  // Build Cijk tensor
214  const int stoch_dim = 2;
215  const int poly_ord = 3;
216  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
217 
218  const size_type num_rows = 11;
219  const size_type num_cols = cijk.dimension();
220  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
221  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
222 }
223 
224 
225 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy, Storage, Layout )
226 {
227  typedef typename Storage::execution_space Device;
228  typedef typename Storage::value_type Scalar;
229  typedef Sacado::UQ::PCE<Storage> PCE;
230  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
231  typedef typename ViewType::size_type size_type;
232  typedef typename ViewType::HostMirror host_view_type;
233  typedef typename host_view_type::array_type host_array_type;
234  typedef typename PCE::cijk_type Cijk;
235 
236  // Build Cijk tensor
237  const int stoch_dim = 2;
238  const int poly_ord = 3;
239  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
240 
241  const size_type num_rows = 11;
242  const size_type num_cols = cijk.dimension();
243  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
244  host_view_type h_v = Kokkos::create_mirror_view(v);
245  host_array_type h_a = h_v;
246 
247  bool is_right = std::is_same< typename ViewType::array_layout,
248  Kokkos::LayoutRight >::value;
249  if (is_right) {
250  for (size_type i=0; i<num_rows; ++i)
251  for (size_type j=0; j<num_cols; ++j)
252  h_a(i,j) = generate_pce_coefficient<Scalar>(
253  num_rows, num_cols, i, j);
254  }
255  else {
256  for (size_type i=0; i<num_rows; ++i)
257  for (size_type j=0; j<num_cols; ++j)
258  h_a(j,i) = generate_pce_coefficient<Scalar>(
259  num_rows, num_cols, i, j);
260  }
261  Kokkos::deep_copy(v, h_v);
262 
263  success = checkPCEView(v, out);
264 }
265 
266 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_NonContiguous, Storage, Layout )
267 {
268  typedef typename Storage::execution_space Device;
269  typedef typename Storage::value_type Scalar;
270  typedef Sacado::UQ::PCE<Storage> PCE;
271  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
272  typedef Kokkos::HostSpace HostDevice;
273  typedef Kokkos::View<PCE*,typename ViewType::array_layout,HostDevice,Kokkos::MemoryUnmanaged> HostViewType;
274  typedef typename ViewType::size_type size_type;
275  typedef typename PCE::cijk_type Cijk;
276 
277  // Build Cijk tensor
278  const int stoch_dim = 2;
279  const int poly_ord = 3;
280  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
281 
282  const size_type num_rows = 11;
283  const size_type num_cols = cijk.dimension();
284  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
285 
286  Teuchos::Array<PCE> a(num_rows);
287  for (size_type i=0; i<num_rows; ++i) {
288  a[i].reset(cijk);
289  for (size_type j=0; j<num_cols; ++j)
290  a[i].fastAccessCoeff(j) = generate_pce_coefficient<Scalar>(
291  num_rows, num_cols, i, j);
292  }
293  // HostViewType ha(a.getRawPtr(), cijk, num_rows, num_cols);
294  HostViewType ha =
295  Kokkos::make_view<HostViewType>(a.getRawPtr(), cijk, num_rows, num_cols);
296  Kokkos::deep_copy(v, ha);
297 
298  success = checkPCEView(v, out);
299 }
300 
301 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_ConstantScalar, Storage, Layout )
302 {
303  typedef typename Storage::execution_space Device;
304  typedef typename Storage::value_type Scalar;
305  typedef Sacado::UQ::PCE<Storage> PCE;
306  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
307  typedef typename ViewType::size_type size_type;
308  typedef typename PCE::cijk_type Cijk;
309 
310  // Build Cijk tensor
311  const int stoch_dim = 2;
312  const int poly_ord = 3;
313  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
314 
315  const size_type num_rows = 11;
316  const size_type num_cols = cijk.dimension();
317  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
318  Scalar val = 1.2345;
319 
320  Kokkos::deep_copy( v, val );
321 
322  PCE pce_val(cijk); pce_val.fastAccessCoeff(0) = val;
323  success = checkConstantPCEView(v, pce_val, out);
324 }
325 
326 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_ConstantPCE, Storage, Layout )
327 {
328  typedef typename Storage::execution_space Device;
329  typedef typename Storage::value_type Scalar;
330  typedef Sacado::UQ::PCE<Storage> PCE;
331  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
332  typedef typename ViewType::size_type size_type;
333  typedef typename PCE::cijk_type Cijk;
334 
335  // Build Cijk tensor
336  const int stoch_dim = 2;
337  const int poly_ord = 3;
338  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
339 
340  const size_type num_rows = 11;
341  const size_type num_cols = cijk.dimension();
342  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
343  Scalar val = 1.2345;
344 
345  Kokkos::deep_copy( v, PCE(val) );
346 
347  PCE pce_val(cijk); pce_val.fastAccessCoeff(0) = val;
348  success = checkConstantPCEView(v, pce_val, out);
349 }
350 
351 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_ConstantPCE2, Storage, Layout )
352 {
353  typedef typename Storage::execution_space Device;
354  typedef typename Storage::value_type Scalar;
355  typedef Sacado::UQ::PCE<Storage> PCE;
356  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
357  typedef typename ViewType::size_type size_type;
358  typedef typename PCE::cijk_type Cijk;
359 
360  // Build Cijk tensor
361  const int stoch_dim = 2;
362  const int poly_ord = 3;
363  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
364 
365  const size_type num_rows = 11;
366  const size_type num_cols = cijk.dimension();
367  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
368  PCE val(cijk);
369  for (size_type j=0; j<num_cols; ++j)
370  val.fastAccessCoeff(j) =
371  generate_pce_coefficient<Scalar>(num_rows, num_cols, size_type(0), j);
372 
373  Kokkos::deep_copy( v, val );
374 
375  success = checkConstantPCEView(v, val, out);
376 }
377 
378 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_View_PCE, DeepCopy_Subview_Range, Storage )
379 {
380  typedef typename Storage::execution_space Device;
381  typedef typename Storage::value_type Scalar;
382  typedef Sacado::UQ::PCE<Storage> PCE;
383  typedef typename ApplyView<PCE**,Kokkos::LayoutLeft,Device>::type ViewType;
384  typedef typename ViewType::size_type size_type;
385  typedef typename ViewType::HostMirror host_view_type;
386  typedef typename PCE::cijk_type Cijk;
387 
388  // Build Cijk tensor
389  const int stoch_dim = 2;
390  const int poly_ord = 3;
391  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
392 
393  const size_type num_rows1 = global_num_rows;
394  const size_type num_rows2 = global_num_rows*2;
395  const size_type num_cols = 5;
396  const size_type num_pce = cijk.dimension();
397  ViewType v1 = Kokkos::make_view<ViewType>("view1", cijk, num_rows1, num_cols);
398  ViewType v2 = Kokkos::make_view<ViewType>("view2", cijk, num_rows2, num_cols);
399 
400  for (size_type j=0; j<num_cols; ++j) {
401  std::pair<size_type,size_type> rows( 0, num_rows1 );
402  ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (j,j+1) );
403  ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (j,j+1) );
404  Kokkos::deep_copy( v1s, Scalar(j+1) );
405  Kokkos::deep_copy( v2s, v1s );
406  }
407 
408  // Check
409  success = true;
410  host_view_type hv2 = Kokkos::create_mirror_view( v2 );
411  Kokkos::deep_copy( hv2, v2 );
412  for (size_type j=0; j<num_cols; ++j) {
413  for (size_type i=0; i<num_rows1; ++i) {
414  for (size_type k=0; k<num_pce; ++k) {
415  Scalar val = hv2(i,j).fastAccessCoeff(k);
416  Scalar val_expected = k == 0 ? Scalar(j+1) : Scalar(0);
417  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
418  }
419  }
420  for (size_type i=num_rows1; i<num_rows2; ++i) {
421  for (size_type k=0; k<num_pce; ++k) {
422  Scalar val = hv2(i,j).fastAccessCoeff(k);
423  Scalar val_expected = 0;
424  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
425  }
426  }
427  }
428 }
429 
430 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_HostArray, Storage, Layout )
431 {
432  typedef typename Storage::execution_space Device;
433  typedef typename Storage::value_type Scalar;
434  typedef Sacado::UQ::PCE<Storage> PCE;
435  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
436  typedef typename ViewType::size_type size_type;
437  typedef typename ViewType::HostMirror host_view_type;
438  typedef typename host_view_type::array_type host_array_type;
439  typedef typename PCE::cijk_type Cijk;
440 
441  // Build Cijk tensor
442  const int stoch_dim = 2;
443  const int poly_ord = 3;
444  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
445 
446  const size_type num_rows = 11;
447  const size_type num_cols = cijk.dimension();
448  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
449  host_array_type h_a = Kokkos::create_mirror_view(v);
450 
451  bool is_right = std::is_same< typename ViewType::array_layout,
452  Kokkos::LayoutRight >::value;
453  if (is_right) {
454  for (size_type i=0; i<num_rows; ++i)
455  for (size_type j=0; j<num_cols; ++j)
456  h_a(i,j) = generate_pce_coefficient<Scalar>(
457  num_rows, num_cols, i, j);
458  }
459  else {
460  for (size_type i=0; i<num_rows; ++i)
461  for (size_type j=0; j<num_cols; ++j)
462  h_a(j,i) = generate_pce_coefficient<Scalar>(
463  num_rows, num_cols, i, j);
464  }
465  Kokkos::deep_copy(v, h_a);
466 
467  success = checkPCEView(v, out);
468 }
469 
470 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeepCopy_DeviceArray, Storage, Layout )
471 {
472  typedef typename Storage::execution_space Device;
473  typedef typename Storage::value_type Scalar;
474  typedef Sacado::UQ::PCE<Storage> PCE;
475  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
476  typedef typename ViewType::size_type size_type;
477  typedef typename ViewType::HostMirror host_view_type;
478  typedef typename host_view_type::array_type host_array_type;
479  typedef typename ViewType::array_type array_type;
480  typedef typename PCE::cijk_type Cijk;
481 
482  // Build Cijk tensor
483  const int stoch_dim = 2;
484  const int poly_ord = 3;
485  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
486 
487  const size_type num_rows = 11;
488  const size_type num_cols = cijk.dimension();
489  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
490  host_view_type h_v = Kokkos::create_mirror_view(v);
491  host_array_type h_a = h_v;
492  array_type a = v;
493 
494  for (size_type i=0; i<num_rows; ++i)
495  for (size_type j=0; j<num_cols; ++j)
496  h_a(i,j) = generate_pce_coefficient<Scalar>(
497  num_rows, num_cols, i, j);
498  Kokkos::deep_copy(a, h_v);
499 
500  success = checkPCEView(v, out);
501 }
502 
503 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, Unmanaged, Storage, Layout )
504 {
505  typedef typename Storage::execution_space Device;
506  typedef typename Storage::value_type Scalar;
507  typedef Sacado::UQ::PCE<Storage> PCE;
508  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
509  typedef typename ViewType::size_type size_type;
510  typedef typename ViewType::HostMirror host_view_type;
511  typedef typename host_view_type::array_type host_array_type;
512  typedef typename PCE::cijk_type Cijk;
513 
514  // Build Cijk tensor
515  const int stoch_dim = 2;
516  const int poly_ord = 3;
517  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
518 
519  const size_type num_rows = 11;
520  const size_type num_cols = cijk.dimension();
521  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
522  host_view_type h_v = Kokkos::create_mirror_view(v);
523  host_array_type h_a = h_v;
524 
525  bool is_right = std::is_same< typename ViewType::array_layout,
526  Kokkos::LayoutRight >::value;
527  if (is_right) {
528  for (size_type i=0; i<num_rows; ++i)
529  for (size_type j=0; j<num_cols; ++j)
530  h_a(i,j) = generate_pce_coefficient<Scalar>(
531  num_rows, num_cols, i, j);
532  }
533  else {
534  for (size_type i=0; i<num_rows; ++i)
535  for (size_type j=0; j<num_cols; ++j)
536  h_a(j,i) = generate_pce_coefficient<Scalar>(
537  num_rows, num_cols, i, j);
538  }
539  Kokkos::deep_copy(v, h_v);
540 
541  // Create unmanaged view
542  ViewType v2 =
543  Kokkos::make_view<ViewType>( v.data(), cijk, num_rows, num_cols );
544 
545  success = checkPCEView(v2, out);
546 }
547 
548 
549 namespace Test {
550 
551 template< class ViewType >
554 
555  typedef typename ViewType::value_type pce_type ;
557 
559  ViewType m_v ;
560 
561  PCEAtomicFunctor( const ViewType & v , const scalar_type & s ) :
562  m_v( v ), m_s( s )
563  {
564  Kokkos::parallel_for( m_v.extent(0) , *this );
565  }
566 
567  KOKKOS_INLINE_FUNCTION
568  void operator()( int i ) const
569  {
570  pce_type v( m_s );
571  atomic_assign( & m_v(i) , v );
572  }
573 };
574 
575 }
576 
577 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, DeviceAtomic, Storage, Layout )
578 {
579  typedef typename Storage::execution_space Device;
580  typedef typename Storage::value_type Scalar;
581  typedef Sacado::UQ::PCE<Storage> PCE;
582  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
583  typedef typename ViewType::size_type size_type;
584  typedef typename PCE::cijk_type Cijk;
585 
586  // Build Cijk tensor
587  const int stoch_dim = 2;
588  const int poly_ord = 3;
589  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
590 
591  const size_type num_rows = 11;
592  const size_type num_cols = cijk.dimension();
593  ViewType v = Kokkos::make_view<ViewType>("view", cijk, num_rows, num_cols);
594  Scalar val = 1.2345;
595 
596  (void) Test::PCEAtomicFunctor<ViewType>( v , val );
597 
598  success = checkConstantPCEView(v, val, out);
599 }
600 
601 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_PCE, AssignData, Storage, Layout )
602 {
603  typedef typename Storage::execution_space Device;
604  typedef typename Storage::value_type Scalar;
605  typedef Sacado::UQ::PCE<Storage> PCE;
606  typedef typename ApplyView<PCE*,Layout,Device>::type ViewType;
607  typedef typename ViewType::size_type size_type;
608  //typedef size_t size_type;
609  typedef typename PCE::cijk_type Cijk;
610 
611  // Build Cijk tensor
612  const int stoch_dim = 2;
613  const int poly_ord = 3;
614  Cijk cijk = build_cijk<Cijk>(stoch_dim, poly_ord);
615 
616  const size_type num_rows = 11;
617  const size_type num_cols = cijk.dimension();
618  ViewType v1 = Kokkos::make_view<ViewType>("view1", cijk, num_rows, num_cols);
619  ViewType v2 = Kokkos::make_view<ViewType>("view2", cijk, num_rows, num_cols);
620  Scalar val1 = 1.234;
621  Scalar val2 = 5.678;
622  Kokkos::deep_copy(v1, val1);
623  Kokkos::deep_copy(v2, val2);
624 
625  auto s1 = Kokkos::subview(v1, std::make_pair(0, 1));
626  auto s2 = Kokkos::subview(v2, std::make_pair(0, 1));
627 
628  s1.assign_data(s2.data());
629 
630  success = checkConstantPCEView(s1, val2, out);
631 }
632 
633 /*
634 */
635 
636 #define VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
637  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
638  Kokkos_View_PCE, Size, STORAGE, LAYOUT ) \
639  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
640  Kokkos_View_PCE, DeepCopy, STORAGE, LAYOUT ) \
641  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
642  Kokkos_View_PCE, DeepCopy_NonContiguous, STORAGE, LAYOUT ) \
643  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
644  Kokkos_View_PCE, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
645  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
646  Kokkos_View_PCE, DeepCopy_ConstantPCE, STORAGE, LAYOUT ) \
647  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
648  Kokkos_View_PCE, DeepCopy_ConstantPCE2, STORAGE, LAYOUT ) \
649  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
650  Kokkos_View_PCE, Unmanaged, STORAGE, LAYOUT ) \
651  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
652  Kokkos_View_PCE, AssignData, STORAGE, LAYOUT )
653 
654 // Some tests the fail, or fail to compile
655 
656  /*
657  // These don't compile as there are no deep_copy overloads between
658  // static view spec and its array_type. That could be done, but
659  // would require some additional work to ensure the shapes match.
660  // It is simple enough to create an array_type view, so deep copying
661  // between matching views isn't much more trouble.
662  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
663  Kokkos_View_PCE, DeepCopy_HostArray, STORAGE, LAYOUT ) \
664  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
665  Kokkos_View_PCE, DeepCopy_DeviceArray, STORAGE, LAYOUT )
666  */
667 
668 #define VIEW_UQ_PCE_TESTS_STORAGE( STORAGE ) \
669  using Kokkos::LayoutLeft; \
670  using Kokkos::LayoutRight; \
671  VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
672  VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
673  VIEW_UQ_PCE_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
674  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
675  Kokkos_View_PCE, DeepCopy_Subview_Range, STORAGE )
676 
677 #define VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
678  typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \
679  VIEW_UQ_PCE_TESTS_STORAGE( DS )
680 
681 #define VIEW_UQ_PCE_TESTS_DEVICE( DEVICE ) \
682  VIEW_UQ_PCE_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
bool checkConstantPCEView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_SG_SpMv, CrsProductTensorCijk, Scalar, Device)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
pce_type::storage_type::value_type scalar_type
KOKKOS_INLINE_FUNCTION void atomic_assign(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
scalar generate_pce_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
KOKKOS_INLINE_FUNCTION void operator()(int i) const
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
view_type::array_type::non_const_value_type type
kokkos_cijk_type build_cijk(ordinal_type stoch_dim, ordinal_type poly_ord)
ViewType::execution_space execution_space
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Legendre polynomial basis.
expr val()
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Abstract base class for 1-D orthogonal polynomials.
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Kokkos_CrsMatrix_MP, ReplaceValues, MatrixScalar)
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
Kokkos::View< DataType, LayoutType, ExecutionSpace > type
bool checkPCEView(const ViewType &v, Teuchos::FancyOStream &out)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
PCEAtomicFunctor(const ViewType &v, const scalar_type &s)