Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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#include "Stokhos_Ensemble_Sizes.hpp"
48
49// For computing DeviceConfig
50#include "Kokkos_Core.hpp"
51
52//
53// Tests various View< Sacado::MP::Vector<...>,...> operations work
54// as expected
55//
56
57// Helper functions
58
59template <typename scalar, typename ordinal>
60inline
61scalar generate_vector_coefficient( const ordinal nFEM,
62 const ordinal nStoch,
63 const ordinal iColFEM,
64 const ordinal iStoch )
65{
66 const scalar X_fem = 100.0 + scalar(iColFEM) / scalar(nFEM);
67 const scalar X_stoch = 1.0 + scalar(iStoch) / scalar(nStoch);
68 return X_fem + X_stoch;
69 //return 1.0;
70}
71
72template <typename ViewType>
73bool
74checkVectorView(const ViewType& v,
75 Teuchos::FancyOStream& out) {
76 typedef ViewType view_type;
77 typedef typename view_type::size_type size_type;
78 typedef typename view_type::HostMirror host_view_type;
79 typedef typename host_view_type::array_type host_array_type;
80 typedef typename host_array_type::value_type scalar_type;
81
82 // Copy to host
83 host_view_type h_v = Kokkos::create_mirror_view(v);
84 Kokkos::deep_copy(h_v, v);
85 host_array_type h_a = h_v;
86
87 size_type num_rows, num_cols;
88
89 // For static, layout left, sacado dimension becomes first dimension
90 // instead of last
91 bool is_right = std::is_same< typename ViewType::array_layout,
92 Kokkos::LayoutRight >::value;
93 if (is_right) {
94 num_rows = h_a.extent(0);
95 num_cols = h_a.extent(1);
96 }
97 else {
98 num_rows = h_a.extent(1);
99 num_cols = h_a.extent(0);
100 }
101 bool success = true;
102 if (is_right) {
103 for (size_type i=0; i<num_rows; ++i) {
104 for (size_type j=0; j<num_cols; ++j) {
105 scalar_type val = h_a(i,j);
106 scalar_type val_expected =
107 generate_vector_coefficient<scalar_type>(
108 num_rows, num_cols, i, j);
109 TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
110 }
111 }
112 }
113 else {
114 for (size_type i=0; i<num_rows; ++i) {
115 for (size_type j=0; j<num_cols; ++j) {
116 scalar_type val = h_a(j,i);
117 scalar_type val_expected =
118 generate_vector_coefficient<scalar_type>(
119 num_rows, num_cols, i, j);
120 TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
121 }
122 }
123 }
124
125 return success;
126}
127
128template <typename ViewType>
129bool
130checkConstantVectorView(const ViewType& v,
131 const typename ViewType::value_type& v_expected,
132 Teuchos::FancyOStream& out) {
133 typedef ViewType view_type;
134 typedef typename view_type::size_type size_type;
135 typedef typename view_type::HostMirror host_view_type;
136 typedef typename host_view_type::array_type::value_type scalar_type;
137
138 // Copy to host
139 host_view_type h_v = Kokkos::create_mirror_view(v);
140 Kokkos::deep_copy(h_v, v);
141
142 const size_type num_rows = h_v.extent(0);
143 const size_type num_cols = Kokkos::dimension_scalar(h_v);
144 bool success = true;
145 for (size_type i=0; i<num_rows; ++i) {
146 for (size_type j=0; j<num_cols; ++j) {
147 scalar_type val = h_v(i).coeff(j);
148 scalar_type val_expected = v_expected.coeff(j);
149 TEUCHOS_TEST_EQUALITY(val, val_expected, out, success);
150 }
151 }
152
153 return success;
154}
155
156template <typename DataType, typename LayoutType, typename ExecutionSpace>
157struct ApplyView {
158 typedef Kokkos::View<DataType,LayoutType,ExecutionSpace> type;
159};
160
161struct NoLayout {};
162template <typename DataType, typename ExecutionSpace>
163struct ApplyView<DataType,NoLayout,ExecutionSpace> {
164 typedef Kokkos::View<DataType,ExecutionSpace> type;
165};
166
167//
168// Tests
169//
170
171const int global_num_rows = 11;
172const int global_num_cols = STOKHOS_DEFAULT_ENSEMBLE_SIZE;
173
174TEUCHOS_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
187TEUCHOS_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 = std::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
222TEUCHOS_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
236
237 success = checkConstantVectorView(v, Vector(num_cols, val), out);
238}
239
240TEUCHOS_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
258TEUCHOS_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
275
276 success = checkConstantVectorView(v, val, out);
277}
278
279TEUCHOS_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;
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
326TEUCHOS_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 = std::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
360TEUCHOS_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
387TEUCHOS_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 = std::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.data(), num_rows, num_cols);
421
422 success = checkVectorView(v2, out);
423}
424
425TEUCHOS_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
458TEUCHOS_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
498TEUCHOS_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
524namespace Test {
525
526template< class ViewType >
528 typedef typename ViewType::execution_space execution_space ;
529
530 typedef typename ViewType::value_type vector_type ;
531 typedef typename vector_type::storage_type::value_type scalar_type ;
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.extent(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
551TEUCHOS_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
569TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( Kokkos_View_MP, AssignData, Storage, Layout )
570{
571 typedef typename Storage::execution_space Device;
572 typedef typename Storage::value_type Scalar;
573 typedef Sacado::MP::Vector<Storage> Vector;
574 typedef typename ApplyView<Vector*,Layout,Device>::type ViewType;
575 typedef typename ViewType::size_type size_type;
576
577 const size_type num_rows = global_num_rows;
578 const size_type num_cols = Storage::is_static ? Storage::static_size : global_num_cols;
579 ViewType v1("view1", num_rows, num_cols);
580 ViewType v2("view2", num_rows, num_cols);
581 Scalar val1 = 1.234;
582 Scalar val2 = 5.678;
583 Kokkos::deep_copy(v1, val1);
584 Kokkos::deep_copy(v2, val2);
585
586 auto s1 = Kokkos::subview(v1, std::make_pair(0, 1));
587 auto s2 = Kokkos::subview(v2, std::make_pair(0, 1));
588
589 s1.assign_data(s2.data());
590
591 success = checkConstantVectorView(s1, val2, out);
592}
593
594
595#define VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT( STORAGE, LAYOUT ) \
596 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
597 Kokkos_View_MP, Size, STORAGE, LAYOUT ) \
598 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
599 Kokkos_View_MP, DeepCopy, STORAGE, LAYOUT ) \
600 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
601 Kokkos_View_MP, DeepCopy_ConstantScalar, STORAGE, LAYOUT ) \
602 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
603 Kokkos_View_MP, DeepCopy_ConstantVector, STORAGE, LAYOUT ) \
604 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
605 Kokkos_View_MP, DeepCopy_ConstantVector2, STORAGE, LAYOUT ) \
606 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
607 Kokkos_View_MP, Unmanaged, STORAGE, LAYOUT ) \
608 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
609 Kokkos_View_MP, Flatten, STORAGE, LAYOUT ) \
610 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
611 Kokkos_View_MP, AssignData, STORAGE, LAYOUT )
612
613// Some tests the fail, or fail to compile
614
615 /*
616 // These don't compile as there are no deep_copy overloads between
617 // static view spec and its array_type. That could be done, but
618 // would require some additional work to ensure the shapes match.
619 // It is simple enough to create an array_type view, so deep copying
620 // between matching views isn't much more trouble.
621 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
622 Kokkos_View_MP, DeepCopy_HostArray, STORAGE, LAYOUT ) \
623 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
624 Kokkos_View_MP, DeepCopy_DeviceArray, STORAGE, LAYOUT )
625 */
626
627#define VIEW_MP_VECTOR_TESTS_STORAGE( STORAGE ) \
628 using Kokkos::LayoutLeft; \
629 using Kokkos::LayoutRight; \
630 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, NoLayout) \
631 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutLeft) \
632 VIEW_MP_VECTOR_TESTS_STORAGE_LAYOUT(STORAGE, LayoutRight) \
633 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( \
634 Kokkos_View_MP, DeepCopy_Subview_Range, STORAGE )
635
636// Removing the DynamicStorage tests since we don't use it for anything real,
637// and it doesn't necessarily work without UVM
638#define VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( ORDINAL, SCALAR, DEVICE ) \
639 typedef Stokhos::StaticFixedStorage<ORDINAL,SCALAR,global_num_cols,DEVICE> SFS; \
640 VIEW_MP_VECTOR_TESTS_STORAGE( SFS ) \
641 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
642 Kokkos_View_MP, PartitionHost, SFS, NoLayout ) \
643 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
644 Kokkos_View_MP, PartitionHost, SFS, LayoutLeft ) \
645 TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( \
646 Kokkos_View_MP, PartitionHost, SFS, LayoutRight )
647
648#define VIEW_MP_VECTOR_TESTS_DEVICE( DEVICE ) \
649 VIEW_MP_VECTOR_TESTS_ORDINAL_SCALAR_DEVICE( int, double, DEVICE )
expr val()
bool checkVectorView(const ViewType &v, Teuchos::FancyOStream &out)
bool checkConstantVectorView(const ViewType &v, const typename ViewType::value_type &v_expected, Teuchos::FancyOStream &out)
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)
scalar generate_vector_coefficient(const ordinal nFEM, const ordinal nStoch, const ordinal iColFEM, const ordinal iStoch)
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)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
Kokkos::View< DataType, LayoutType, ExecutionSpace > type
KOKKOS_INLINE_FUNCTION void operator()(int i) const
MPVectorAtomicFunctor(const ViewType &v, const scalar_type &s)
vector_type::storage_type::value_type scalar_type