Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_KokkosViewMPVectorUnitTest.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 
42 #include "Teuchos_TestingHelpers.hpp"
43 #include "Teuchos_UnitTestHelpers.hpp"
45 
47 
48 // For computing DeviceConfig
49 #include "Kokkos_Core.hpp"
50 
51 //
52 // Tests various View< Sacado::MP::Vector<...>,...> operations work
53 // as expected
54 //
55 
56 // Helper functions
57 
58 template <typename scalar, typename ordinal>
59 inline
60 scalar generate_vector_coefficient( const ordinal nFEM,
61  const ordinal nStoch,
62  const ordinal iColFEM,
63  const ordinal iStoch )
64 {
65  const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
66  const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
67  return X_fem + X_stoch;
68  //return 1.0;
69 }
70 
71 template <typename ViewType>
72 bool
73 checkVectorView(const ViewType& v,
74  Teuchos::FancyOStream& out) {
75  typedef ViewType view_type;
76  typedef typename view_type::size_type size_type;
77  typedef typename view_type::HostMirror host_view_type;
78  typedef typename host_view_type::array_type host_array_type;
80 
81  // Copy to host
82  host_view_type h_v = Kokkos::create_mirror_view(v);
83  Kokkos::deep_copy(h_v, v);
84  host_array_type h_a = h_v;
85 
86  size_type num_rows, num_cols;
87 
88  // For static, layout left, sacado dimension becomes first dimension
89  // instead of last
90  bool is_right = Kokkos::Impl::is_same< typename ViewType::array_layout,
91  Kokkos::LayoutRight >::value;
92  if (is_right) {
93  num_rows = h_a.dimension_0();
94  num_cols = h_a.dimension_1();
95  }
96  else {
97  num_rows = h_a.dimension_1();
98  num_cols = h_a.dimension_0();
99  }
100  bool success = true;
101  if (is_right) {
102  for (size_type i=0; i<num_rows; ++i) {
103  for (size_type j=0; j<num_cols; ++j) {
104  scalar_type val = h_a(i,j);
105  scalar_type val_expected =
106  generate_vector_coefficient<scalar_type>(
107  num_rows, num_cols, i, j);
108  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
109  }
110  }
111  }
112  else {
113  for (size_type i=0; i<num_rows; ++i) {
114  for (size_type j=0; j<num_cols; ++j) {
115  scalar_type val = h_a(j,i);
116  scalar_type val_expected =
117  generate_vector_coefficient<scalar_type>(
118  num_rows, num_cols, i, j);
119  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
120  }
121  }
122  }
123 
124  return success;
125 }
126 
127 template <typename ViewType>
128 bool
129 checkConstantVectorView(const ViewType& v,
130  const typename ViewType::value_type& v_expected,
131  Teuchos::FancyOStream& out) {
132  typedef ViewType view_type;
133  typedef typename view_type::size_type size_type;
134  typedef typename view_type::HostMirror host_view_type;
136 
137  // Copy to host
138  host_view_type h_v = Kokkos::create_mirror_view(v);
139  Kokkos::deep_copy(h_v, v);
140 
141  const size_type num_rows = h_v.dimension_0();
142  const size_type num_cols = Kokkos::dimension_scalar(h_v);
143  bool success = true;
144  for (size_type i=0; i<num_rows; ++i) {
145  for (size_type j=0; j<num_cols; ++j) {
146  scalar_type val = h_v(i).fastAccessCoeff(j);
147  scalar_type val_expected = v_expected.fastAccessCoeff(j);
148  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
149  }
150  }
151 
152  return success;
153 }
154 
155 template <typename DataType, typename LayoutType, typename ExecutionSpace>
156 struct ApplyView {
157  typedef Kokkos::View<DataType,LayoutType,ExecutionSpace> type;
158 };
159 
160 struct NoLayout {};
161 template <typename DataType, typename ExecutionSpace>
162 struct ApplyView<DataType,NoLayout,ExecutionSpace> {
163  typedef Kokkos::View<DataType,ExecutionSpace> type;
164 };
165 
166 //
167 // Tests
168 //
169 
170 const int global_num_rows = 11;
171 const int global_num_cols = 8; // Currently must be a multiple of 8 based on
172  // alignment assumptions for SFS
173 
174 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, Size, Storage, Layout )
175 {
176  typedef typename Storage::execution_space Device;
177  typedef Sacado::MP::Vector<Storage> Vector;
178  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
179  typedef typename ViewType::size_type size_type;
180 
181  const size_type num_rows = global_num_rows;
182  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
183  ViewType v("view", num_rows, num_cols);
184  TEUCHOS_TEST_EQUALITY(v.size(), num_rows, out, success);
185 }
186 
187 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeepCopy, Storage, Layout )
188 {
189  typedef typename Storage::execution_space Device;
190  typedef typename Storage::value_type Scalar;
191  typedef Sacado::MP::Vector<Storage> Vector;
192  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
193  typedef typename ViewType::size_type size_type;
194  typedef typename ViewType::HostMirror host_view_type;
195  typedef typename host_view_type::array_type host_array_type;
196 
197  const size_type num_rows = global_num_rows;
198  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
199  ViewType v("view", num_rows, num_cols);
200  host_view_type h_v = Kokkos::create_mirror_view(v);
201  host_array_type h_a = h_v;
202 
203  bool is_right = Kokkos::Impl::is_same< typename ViewType::array_layout,
204  Kokkos::LayoutRight >::value;
205  if (is_right) {
206  for (size_type i=0; i<num_rows; ++i)
207  for (size_type j=0; j<num_cols; ++j)
208  h_a(i,j) = generate_vector_coefficient<Scalar>(
209  num_rows, num_cols, i, j);
210  }
211  else {
212  for (size_type i=0; i<num_rows; ++i)
213  for (size_type j=0; j<num_cols; ++j)
214  h_a(j,i) = generate_vector_coefficient<Scalar>(
215  num_rows, num_cols, i, j);
216  }
217  Kokkos::deep_copy(v, h_v);
218 
219  success = checkVectorView(v, out);
220 }
221 
222 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeepCopy_ConstantScalar, Storage, Layout )
223 {
224  typedef typename Storage::execution_space Device;
225  typedef typename Storage::value_type Scalar;
226  typedef Sacado::MP::Vector<Storage> Vector;
227  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
228  typedef typename ViewType::size_type size_type;
229 
230  const size_type num_rows = global_num_rows;
231  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
232  ViewType v("view", num_rows, num_cols);
233  Scalar val = 1.2345;
234 
235  Kokkos::deep_copy( v, val );
236 
237  success = checkConstantVectorView(v, Vector(num_cols, val), out);
238 }
239 
240 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeepCopy_ConstantVector, Storage, Layout )
241 {
242  typedef typename Storage::execution_space Device;
243  typedef typename Storage::value_type Scalar;
244  typedef Sacado::MP::Vector<Storage> Vector;
245  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
246  typedef typename ViewType::size_type size_type;
247 
248  const size_type num_rows = global_num_rows;
249  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
250  ViewType v("view", num_rows, num_cols);
251  Scalar val = 1.2345;
252 
253  Kokkos::deep_copy( v, Vector(val) );
254 
255  success = checkConstantVectorView(v, Vector(num_cols, val), out);
256 }
257 
258 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeepCopy_ConstantVector2, Storage, Layout )
259 {
260  typedef typename Storage::execution_space Device;
261  typedef typename Storage::value_type Scalar;
262  typedef Sacado::MP::Vector<Storage> Vector;
263  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
264  typedef typename ViewType::size_type size_type;
265 
266  const size_type num_rows = global_num_rows;
267  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
268  ViewType v("view", num_rows, num_cols);
269  Vector val(num_cols, 0.0);
270  for (size_type j=0; j<num_cols; ++j)
271  val.fastAccessCoeff(j) =
272  generate_vector_coefficient<Scalar>(num_rows, num_cols, size_type(0), j);
273 
274  Kokkos::deep_copy( v, val );
275 
276  success = checkConstantVectorView(v, val, out);
277 }
278 
279 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Kokkos_View_MP, DeepCopy_Subview_Range, Storage )
280 {
281  typedef typename Storage::execution_space Device;
282  typedef typename Storage::value_type Scalar;
283  typedef Sacado::MP::Vector<Storage> Vector;
284  typedef typename ApplyView<Vector**,Kokkos::LayoutLeft,Device>::type ViewType;
285  typedef typename ViewType::size_type size_type;
286  typedef typename ViewType::HostMirror host_view_type;
287 
288  const size_type num_rows1 = global_num_rows;
289  const size_type num_rows2 = global_num_rows*2;
290  const size_type num_cols = 5;
291  const size_type num_vec =
292  Storage::is_static ? Storage::static_size : global_num_cols;
293  ViewType v1("view1", num_rows1, num_cols, num_vec);
294  ViewType v2("view2", num_rows2, num_cols, num_vec);
295 
296  for (size_type j=0; j<num_cols; ++j) {
297  std::pair<size_type,size_type> rows( 0, num_rows1 );
298  ViewType v1s = Kokkos::subview( v1, rows, std::pair<size_t,size_t> (j,j+1) );
299  ViewType v2s = Kokkos::subview( v2, rows, std::pair<size_t,size_t> (j,j+1) );
300  Kokkos::deep_copy( v1s, Scalar(j+1) );
301  Kokkos::deep_copy( v2s, v1s );
302  }
303 
304  // Check
305  success = true;
306  host_view_type hv2 = Kokkos::create_mirror_view( v2 );
307  Kokkos::deep_copy( hv2, v2 );
308  for (size_type j=0; j<num_cols; ++j) {
309  for (size_type i=0; i<num_rows1; ++i) {
310  for (size_type k=0; k<num_vec; ++k) {
311  Scalar val = hv2(i,j).fastAccessCoeff(k);
312  Scalar val_expected = j+1;
313  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
314  }
315  }
316  for (size_type i=num_rows1; i<num_rows2; ++i) {
317  for (size_type k=0; k<num_vec; ++k) {
318  Scalar val = hv2(i,j).fastAccessCoeff(k);
319  Scalar val_expected = 0;
320  TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
321  }
322  }
323  }
324 }
325 
326 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeepCopy_HostArray, Storage, Layout )
327 {
328  typedef typename Storage::execution_space Device;
329  typedef typename Storage::value_type Scalar;
330  typedef Sacado::MP::Vector<Storage> Vector;
331  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
332  typedef typename ViewType::size_type size_type;
333  typedef typename ViewType::HostMirror host_view_type;
334  typedef typename host_view_type::array_type host_array_type;
335 
336  const size_type num_rows = global_num_rows;
337  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
338  ViewType v("view", num_rows, num_cols);
339  host_array_type h_a = Kokkos::create_mirror_view(v);
340 
341  bool is_right = Kokkos::Impl::is_same< typename ViewType::array_layout,
342  Kokkos::LayoutRight >::value;
343  if (is_right) {
344  for (size_type i=0; i<num_rows; ++i)
345  for (size_type j=0; j<num_cols; ++j)
346  h_a(i,j) = generate_vector_coefficient<Scalar>(
347  num_rows, num_cols, i, j);
348  }
349  else {
350  for (size_type i=0; i<num_rows; ++i)
351  for (size_type j=0; j<num_cols; ++j)
352  h_a(j,i) = generate_vector_coefficient<Scalar>(
353  num_rows, num_cols, i, j);
354  }
355  Kokkos::deep_copy(v, h_a);
356 
357  success = checkVectorView(v, out);
358 }
359 
360 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeepCopy_DeviceArray, Storage, Layout )
361 {
362  typedef typename Storage::execution_space Device;
363  typedef typename Storage::value_type Scalar;
364  typedef Sacado::MP::Vector<Storage> Vector;
365  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
366  typedef typename ViewType::size_type size_type;
367  typedef typename ViewType::HostMirror host_view_type;
368  typedef typename host_view_type::array_type host_array_type;
369  typedef typename ViewType::array_type array_type;
370 
371  const size_type num_rows = global_num_rows;
372  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
373  ViewType v("view", num_rows, num_cols);
374  host_view_type h_v = Kokkos::create_mirror_view(v);
375  host_array_type h_a = h_v;
376  array_type a = v;
377 
378  for (size_type i=0; i<num_rows; ++i)
379  for (size_type j=0; j<num_cols; ++j)
380  h_a(i,j) = generate_vector_coefficient<Scalar>(
381  num_rows, num_cols, i, j);
382  Kokkos::deep_copy(a, h_v);
383 
384  success = checkVectorView(v, out);
385 }
386 
387 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, Unmanaged, Storage, Layout )
388 {
389  typedef typename Storage::execution_space Device;
390  typedef typename Storage::value_type Scalar;
391  typedef Sacado::MP::Vector<Storage> Vector;
392  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
393  typedef typename ViewType::size_type size_type;
394  typedef typename ViewType::HostMirror host_view_type;
395  typedef typename host_view_type::array_type host_array_type;
396 
397  const size_type num_rows = global_num_rows;
398  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
399  ViewType v("view", num_rows, num_cols);
400  host_view_type h_v = Kokkos::create_mirror_view(v);
401  host_array_type h_a = h_v;
402 
403  bool is_right = Kokkos::Impl::is_same< typename ViewType::array_layout,
404  Kokkos::LayoutRight >::value;
405  if (is_right) {
406  for (size_type i=0; i<num_rows; ++i)
407  for (size_type j=0; j<num_cols; ++j)
408  h_a(i,j) = generate_vector_coefficient<Scalar>(
409  num_rows, num_cols, i, j);
410  }
411  else {
412  for (size_type i=0; i<num_rows; ++i)
413  for (size_type j=0; j<num_cols; ++j)
414  h_a(j,i) = generate_vector_coefficient<Scalar>(
415  num_rows, num_cols, i, j);
416  }
417  Kokkos::deep_copy(v, h_v);
418 
419  // Create unmanaged view
420  ViewType v2(v.ptr_on_device(), num_rows, num_cols);
421 
422  success = checkVectorView(v2, out);
423 }
424 
425 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, PartitionHost, Storage, Layout )
426 {
427  typedef typename Storage::execution_space Device;
428  typedef typename Storage::value_type Scalar;
429  typedef Sacado::MP::Vector<Storage> Vector;
430  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
431  typedef typename ViewType::size_type size_type;
432  typedef typename ViewType::HostMirror host_view_type;
433 
434  const size_type num_rows = global_num_rows;
435  const size_type num_cols = Storage::static_size;
436  ViewType v("view", num_rows, num_cols);
437  host_view_type h_v = Kokkos::create_mirror_view(v);
438 
439  const size_type num_cols_part = num_cols/2;
440  auto h_v1 = Kokkos::partition<num_cols_part>(h_v, 0);
441  auto h_v2 = Kokkos::partition<num_cols_part>(h_v, num_cols_part);
442 
443  for (size_type i=0; i<num_rows; ++i) {
444  for (size_type j=0; j<num_cols_part; ++j) {
445  h_v1(i).fastAccessCoeff(j) = generate_vector_coefficient<Scalar>(
446  num_rows, num_cols, i, j);
447  h_v2(i).fastAccessCoeff(j) = generate_vector_coefficient<Scalar>(
448  num_rows, num_cols, i, j+num_cols_part);
449  }
450  }
451  Kokkos::deep_copy(v, h_v);
452 
453  success = checkVectorView(v, out);
454 }
455 
456 /*
457 // This test does not work because we can't call deep_copy on partitioned views
458 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, PartitionDevice, Storage, Layout )
459 {
460  typedef typename Storage::execution_space Device;
461  typedef typename Storage::value_type Scalar;
462  typedef Sacado::MP::Vector<Storage> Vector;
463  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
464  typedef typename ViewType::size_type size_type;
465 
466  // This test requires static storage, so it always passes if it isn't
467  if (!Storage::is_static) {
468  success = true;
469  return;
470  }
471 
472  const size_type num_rows = global_num_rows;
473  const size_type num_cols = Storage::static_size;
474  ViewType v("view", num_rows, num_cols);
475 
476  const size_type num_cols_part = num_cols/2;
477  auto v1 = Kokkos::partition<num_cols_part>(v, 0);
478  auto v2 = Kokkos::partition<num_cols_part>(v, num_cols_part);
479 
480  typename decltype(v1)::HostMirror h_v1 = Kokkos::create_mirror_view(v1);
481  typename decltype(v2)::HostMirror h_v2 = Kokkos::create_mirror_view(v2);
482 
483  for (size_type i=0; i<num_rows; ++i) {
484  for (size_type j=0; j<num_cols_part; ++j) {
485  h_v1(i).fastAccessCoeff(j) = generate_vector_coefficient<Scalar>(
486  num_rows, num_cols, i, j);
487  h_v2(i).fastAccessCoeff(j) = generate_vector_coefficient<Scalar>(
488  num_rows, num_cols, i, j+num_cols_part);
489  }
490  }
491  Kokkos::deep_copy(v1, h_v1);
492  Kokkos::deep_copy(v2, h_v2);
493 
494  success = checkVectorView(v, out);
495 }
496 */
497 
498 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, Flatten, Storage, Layout )
499 {
500  typedef typename Storage::execution_space Device;
501  typedef typename Storage::value_type Scalar;
502  typedef Sacado::MP::Vector<Storage> Vector;
503  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
504  typedef typename ViewType::size_type size_type;
505  typedef typename Kokkos::FlatArrayType<ViewType>::type flat_view_type;
506  typedef typename flat_view_type::HostMirror host_flat_view_type;
507 
508  const size_type num_rows = global_num_rows;
509  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
510  ViewType v("view", num_rows, num_cols);
511 
512  // Create flattened view
513  flat_view_type flat_v = v;
514  host_flat_view_type h_flat_v = Kokkos::create_mirror_view(flat_v);
515  for (size_type i=0; i<num_rows; ++i)
516  for (size_type j=0; j<num_cols; ++j)
517  h_flat_v(i*num_cols+j) = generate_vector_coefficient<Scalar>(
518  num_rows, num_cols, i, j);
519  Kokkos::deep_copy(flat_v, h_flat_v);
520 
521  success = checkVectorView(v, out);
522 }
523 
524 namespace Test {
525 
526 template< class ViewType >
529 
532 
534  ViewType m_v ;
535 
536  MPVectorAtomicFunctor( const ViewType & v , const scalar_type & s ) : m_v( v ), m_s( s )
537  {
538  Kokkos::parallel_for( m_v.dimension_0() , *this );
539  }
540 
541  KOKKOS_INLINE_FUNCTION
542  void operator()( int i ) const
543  {
544  vector_type v( m_s );
545  atomic_assign( & m_v(i) , v );
546  }
547 };
548 
549 }
550 
551 TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, DeviceAtomic, Storage, Layout )
552 {
553  typedef typename Storage::execution_space Device;
554  typedef typename Storage::value_type Scalar;
555  typedef Sacado::MP::Vector<Storage> Vector;
556  typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
557  typedef typename ViewType::size_type size_type;
558 
559  const size_type num_rows = global_num_rows;
560  const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
561  ViewType v("view", num_rows, num_cols);
562  Scalar val = 1.2345;
563 
565 
566  success = checkConstantVectorView(v, val, out);
567 }
568 
569 
570 #define VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
571  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
572  Kokkos_View_MP, Size, STORAGE, LAYOUT ) \
573  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
574  Kokkos_View_MP, DeepCopy, STORAGE, LAYOUT ) \
575  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
576  Kokkos_View_MP, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
577  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
578  Kokkos_View_MP, DeepCopy_ConstantVector, STORAGE, LAYOUT ) \
579  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
580  Kokkos_View_MP, DeepCopy_ConstantVector2, STORAGE, LAYOUT ) \
581  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
582  Kokkos_View_MP, Unmanaged, STORAGE, LAYOUT ) \
583  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
584  Kokkos_View_MP, Flatten, STORAGE, LAYOUT )
585 
586 // Some tests the fail, or fail to compile
587 
588  /*
589  // These don't compile as there are no deep_copy overloads between
590  // static view spec and its array_type. That could be done, but
591  // would require some additional work to ensure the shapes match.
592  // It is simple enough to create an array_type view, so deep copying
593  // between matching views isn't much more trouble.
594  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
595  Kokkos_View_MP, DeepCopy_HostArray, STORAGE, LAYOUT ) \
596  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
597  Kokkos_View_MP, DeepCopy_DeviceArray, STORAGE, LAYOUT )
598  */
599 
600 #define VIEW_MP_VECTOR_TESTS_STORAGE( STORAGE ) \
601  using Kokkos::LayoutLeft; \
602  using Kokkos::LayoutRight; \
603  VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
604  VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
605  VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
606  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
607  Kokkos_View_MP, DeepCopy_Subview_Range, STORAGE )
608 
609 #define VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
610  typedef Stokhos::StaticFixedStorage<ORDINAL,SCALAR,global_num_cols,DEVICE> SFS; \
611  typedef Stokhos::DynamicStorage<ORDINAL,SCALAR,DEVICE> DS; \
612  VIEW_MP_VECTOR_TESTS_STORAGE( SFS ) \
613  VIEW_MP_VECTOR_TESTS_STORAGE( DS ) \
614  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
615  Kokkos_View_MP, PartitionHost, SFS, NoLayout ) \
616  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
617  Kokkos_View_MP, PartitionHost, SFS, LayoutLeft ) \
618  TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
619  Kokkos_View_MP, PartitionHost, SFS, LayoutRight )
620 
621 #define VIEW_MP_VECTOR_TESTS_DEVICE( DEVICE ) \
622  VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
expr val()
bool checkConstantVectorView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
Kokkos::DefaultExecutionSpace execution_space
bool checkVectorView(const ViewType &v, Teuchos::FancyOStream &out)
vector_type::storage_type::value_type scalar_type
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Kokkos_View_MP, DeepCopy_Subview_Range, Storage)
TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(Kokkos_View_MP, Size, Storage, Layout)
KOKKOS_INLINE_FUNCTION void atomic_assign(volatile Sacado::UQ::PCE< Storage > *const dest, const Sacado::UQ::PCE< Storage > &src)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P... > >::value, unsigned >::type dimension_scalar(const View< T, P... > &view)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
expr expr expr expr j
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
pce_type Scalar
Kokkos::View< DataType, LayoutType, ExecutionSpace > type
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
MPVectorAtomicFunctor(const ViewType &v, const scalar_type &s)
KOKKOS_INLINE_FUNCTION void operator()(int i) const