1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 3.0
6 // Copyright (2020) National Technology & Engineering
7 // Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44 #ifndef TESTVIEWSUBVIEW_HPP_
45 #define TESTVIEWSUBVIEW_HPP_
46 #include <gtest/gtest.h>
47
48 #include <Kokkos_Core.hpp>
49 #include <stdexcept>
50 #include <sstream>
51 #include <iostream>
52 #include <type_traits>
53
54 // TODO @refactoring move this to somewhere common
55
56 //------------------------------------------------------------------------------
57
58 template <class...>
59 struct _kokkos____________________static_test_failure_____;
60
61 template <class...>
62 struct static_predicate_message {};
63
64 //------------------------------------------------------------------------------
65
66 template <class, template <class...> class, class...>
67 struct static_assert_predicate_true_impl;
68
69 template <template <class...> class predicate, class... message, class... args>
70 struct static_assert_predicate_true_impl<
71 typename std::enable_if<predicate<args...>::type::value>::type, predicate,
72 static_predicate_message<message...>, args...> {
73 using type = int;
74 };
75
76 template <template <class...> class predicate, class... message, class... args>
77 struct static_assert_predicate_true_impl<
78 typename std::enable_if<!predicate<args...>::type::value>::type, predicate,
79 static_predicate_message<message...>, args...> {
80 using type = typename _kokkos____________________static_test_failure_____<
81 message...>::type;
82 };
83
84 template <template <class...> class predicate, class... args>
85 struct static_assert_predicate_true
86 : static_assert_predicate_true_impl<void, predicate,
87 static_predicate_message<>, args...> {};
88
89 template <template <class...> class predicate, class... message, class... args>
90 struct static_assert_predicate_true<
91 predicate, static_predicate_message<message...>, args...>
92 : static_assert_predicate_true_impl<
93 void, predicate, static_predicate_message<message...>, args...> {};
94
95 //------------------------------------------------------------------------------
96
97 // error "messages"
98 struct _kokkos__________types_should_be_the_same_____expected_type__ {};
99 struct _kokkos__________actual_type_was__ {};
100 template <class Expected, class Actual>
101 struct static_expect_same {
102 using type = typename static_assert_predicate_true<
103 std::is_same,
104 static_predicate_message<
105 _kokkos__________types_should_be_the_same_____expected_type__,
106 Expected, _kokkos__________actual_type_was__, Actual>,
107 Expected, Actual>::type;
108 };
109
110 //------------------------------------------------------------------------------
111
112 namespace TestViewSubview {
113
114 template <class Layout, class Space>
115 struct getView {
getTestViewSubview::getView116 static Kokkos::View<double**, Layout, Space> get(int n, int m) {
117 return Kokkos::View<double**, Layout, Space>("G", n, m);
118 }
119 };
120
121 template <class Space>
122 struct getView<Kokkos::LayoutStride, Space> {
getTestViewSubview::getView123 static Kokkos::View<double**, Kokkos::LayoutStride, Space> get(int n, int m) {
124 const int rank = 2;
125 const int order[] = {0, 1};
126 const unsigned dim[] = {unsigned(n), unsigned(m)};
127 Kokkos::LayoutStride stride =
128 Kokkos::LayoutStride::order_dimensions(rank, order, dim);
129
130 return Kokkos::View<double**, Kokkos::LayoutStride, Space>("G", stride);
131 }
132 };
133
134 template <class ViewType, class Space>
135 struct fill_1D {
136 using execution_space = typename Space::execution_space;
137 using size_type = typename ViewType::size_type;
138
139 ViewType a;
140 double val;
141
fill_1DTestViewSubview::fill_1D142 fill_1D(ViewType a_, double val_) : a(a_), val(val_) {}
143
144 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::fill_1D145 void operator()(const int i) const { a(i) = val; }
146 };
147
148 template <class ViewType, class Space>
149 struct fill_2D {
150 using execution_space = typename Space::execution_space;
151 using size_type = typename ViewType::size_type;
152
153 ViewType a;
154 double val;
155
fill_2DTestViewSubview::fill_2D156 fill_2D(ViewType a_, double val_) : a(a_), val(val_) {}
157
158 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::fill_2D159 void operator()(const int i) const {
160 for (int j = 0; j < static_cast<int>(a.extent(1)); j++) {
161 a(i, j) = val;
162 }
163 }
164 };
165
166 template <class Layout, class Space>
test_auto_1d()167 void test_auto_1d() {
168 using mv_type = Kokkos::View<double**, Layout, Space>;
169 using size_type = typename mv_type::size_type;
170
171 const double ZERO = 0.0;
172 const double ONE = 1.0;
173 const double TWO = 2.0;
174
175 const size_type numRows = 10;
176 const size_type numCols = 3;
177
178 mv_type X = getView<Layout, Space>::get(numRows, numCols);
179 typename mv_type::HostMirror X_h = Kokkos::create_mirror_view(X);
180
181 fill_2D<mv_type, Space> f1(X, ONE);
182 Kokkos::parallel_for(X.extent(0), f1);
183 Kokkos::fence();
184 Kokkos::deep_copy(X_h, X);
185 for (size_type j = 0; j < numCols; ++j) {
186 for (size_type i = 0; i < numRows; ++i) {
187 ASSERT_TRUE(X_h(i, j) == ONE);
188 }
189 }
190
191 fill_2D<mv_type, Space> f2(X, 0.0);
192 Kokkos::parallel_for(X.extent(0), f2);
193 Kokkos::fence();
194 Kokkos::deep_copy(X_h, X);
195 for (size_type j = 0; j < numCols; ++j) {
196 for (size_type i = 0; i < numRows; ++i) {
197 ASSERT_TRUE(X_h(i, j) == ZERO);
198 }
199 }
200
201 fill_2D<mv_type, Space> f3(X, TWO);
202 Kokkos::parallel_for(X.extent(0), f3);
203 Kokkos::fence();
204 Kokkos::deep_copy(X_h, X);
205 for (size_type j = 0; j < numCols; ++j) {
206 for (size_type i = 0; i < numRows; ++i) {
207 ASSERT_TRUE(X_h(i, j) == TWO);
208 }
209 }
210
211 for (size_type j = 0; j < numCols; ++j) {
212 auto X_j = Kokkos::subview(X, Kokkos::ALL, j);
213
214 fill_1D<decltype(X_j), Space> f4(X_j, ZERO);
215 Kokkos::parallel_for(X_j.extent(0), f4);
216 Kokkos::fence();
217 Kokkos::deep_copy(X_h, X);
218 for (size_type i = 0; i < numRows; ++i) {
219 ASSERT_TRUE(X_h(i, j) == ZERO);
220 }
221
222 for (size_type jj = 0; jj < numCols; ++jj) {
223 auto X_jj = Kokkos::subview(X, Kokkos::ALL, jj);
224 fill_1D<decltype(X_jj), Space> f5(X_jj, ONE);
225 Kokkos::parallel_for(X_jj.extent(0), f5);
226 Kokkos::fence();
227 Kokkos::deep_copy(X_h, X);
228 for (size_type i = 0; i < numRows; ++i) {
229 ASSERT_TRUE(X_h(i, jj) == ONE);
230 }
231 }
232 }
233 }
234
235 template <class LD, class LS, class Space>
test_1d_strided_assignment_impl(bool a,bool b,bool c,bool d,int n,int m)236 void test_1d_strided_assignment_impl(bool a, bool b, bool c, bool d, int n,
237 int m) {
238 Kokkos::View<double**, LS, Space> l2d("l2d", n, m);
239
240 int col = n > 2 ? 2 : 0;
241 int row = m > 2 ? 2 : 0;
242
243 if (Kokkos::Impl::SpaceAccessibility<
244 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
245 if (a) {
246 Kokkos::View<double*, LD, Space> l1da =
247 Kokkos::subview(l2d, Kokkos::ALL, row);
248 ASSERT_TRUE(&l1da(0) == &l2d(0, row));
249 if (n > 1) {
250 ASSERT_TRUE(&l1da(1) == &l2d(1, row));
251 }
252 }
253
254 if (b && n > 13) {
255 Kokkos::View<double*, LD, Space> l1db =
256 Kokkos::subview(l2d, std::pair<unsigned, unsigned>(2, 13), row);
257 ASSERT_TRUE(&l1db(0) == &l2d(2, row));
258 ASSERT_TRUE(&l1db(1) == &l2d(3, row));
259 }
260
261 if (c) {
262 Kokkos::View<double*, LD, Space> l1dc =
263 Kokkos::subview(l2d, col, Kokkos::ALL);
264 ASSERT_TRUE(&l1dc(0) == &l2d(col, 0));
265 if (m > 1) {
266 ASSERT_TRUE(&l1dc(1) == &l2d(col, 1));
267 }
268 }
269
270 if (d && m > 13) {
271 Kokkos::View<double*, LD, Space> l1dd =
272 Kokkos::subview(l2d, col, std::pair<unsigned, unsigned>(2, 13));
273 ASSERT_TRUE(&l1dd(0) == &l2d(col, 2));
274 ASSERT_TRUE(&l1dd(1) == &l2d(col, 3));
275 }
276 }
277 }
278
279 template <class Space>
test_1d_strided_assignment()280 void test_1d_strided_assignment() {
281 test_1d_strided_assignment_impl<Kokkos::LayoutStride, Kokkos::LayoutLeft,
282 Space>(true, true, true, true, 17, 3);
283 test_1d_strided_assignment_impl<Kokkos::LayoutStride, Kokkos::LayoutRight,
284 Space>(true, true, true, true, 17, 3);
285
286 test_1d_strided_assignment_impl<Kokkos::LayoutLeft, Kokkos::LayoutLeft,
287 Space>(true, true, false, false, 17, 3);
288 test_1d_strided_assignment_impl<Kokkos::LayoutRight, Kokkos::LayoutLeft,
289 Space>(true, true, false, false, 17, 3);
290 test_1d_strided_assignment_impl<Kokkos::LayoutLeft, Kokkos::LayoutRight,
291 Space>(false, false, true, true, 17, 3);
292 test_1d_strided_assignment_impl<Kokkos::LayoutRight, Kokkos::LayoutRight,
293 Space>(false, false, true, true, 17, 3);
294
295 test_1d_strided_assignment_impl<Kokkos::LayoutLeft, Kokkos::LayoutLeft,
296 Space>(true, true, false, false, 17, 1);
297 test_1d_strided_assignment_impl<Kokkos::LayoutLeft, Kokkos::LayoutLeft,
298 Space>(true, true, true, true, 1, 17);
299 test_1d_strided_assignment_impl<Kokkos::LayoutRight, Kokkos::LayoutLeft,
300 Space>(true, true, true, true, 1, 17);
301 test_1d_strided_assignment_impl<Kokkos::LayoutRight, Kokkos::LayoutLeft,
302 Space>(true, true, false, false, 17, 1);
303
304 test_1d_strided_assignment_impl<Kokkos::LayoutLeft, Kokkos::LayoutRight,
305 Space>(true, true, true, true, 17, 1);
306 test_1d_strided_assignment_impl<Kokkos::LayoutLeft, Kokkos::LayoutRight,
307 Space>(false, false, true, true, 1, 17);
308 test_1d_strided_assignment_impl<Kokkos::LayoutRight, Kokkos::LayoutRight,
309 Space>(false, false, true, true, 1, 17);
310 test_1d_strided_assignment_impl<Kokkos::LayoutRight, Kokkos::LayoutRight,
311 Space>(true, true, true, true, 17, 1);
312 }
313
314 template <class NewView, class OrigView, class... Args>
make_subview(bool use_constructor,NewView & v,OrigView org,Args...args)315 void make_subview(bool use_constructor, NewView& v, OrigView org,
316 Args... args) {
317 if (use_constructor) {
318 v = NewView(org, args...);
319 } else {
320 v = Kokkos::subview(org, args...);
321 }
322 }
323
324 template <class Space>
test_left_0(bool constr)325 void test_left_0(bool constr) {
326 using view_static_8_type =
327 Kokkos::View<int[2][3][4][5][2][3][4][5], Kokkos::LayoutLeft, Space>;
328
329 if (Kokkos::Impl::SpaceAccessibility<
330 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
331 view_static_8_type x_static_8("x_static_left_8");
332
333 ASSERT_TRUE(x_static_8.span_is_contiguous());
334
335 Kokkos::View<int, Kokkos::LayoutLeft, Space> x0;
336 make_subview(constr, x0, x_static_8, 0, 0, 0, 0, 0, 0, 0, 0);
337
338 ASSERT_TRUE(x0.span_is_contiguous());
339 ASSERT_EQ(x0.span(), 1);
340 ASSERT_TRUE(&x0() == &x_static_8(0, 0, 0, 0, 0, 0, 0, 0));
341
342 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x1;
343 make_subview(constr, x1, x_static_8, Kokkos::pair<int, int>(0, 2), 1, 2, 3,
344 0, 1, 2, 3);
345
346 ASSERT_TRUE(x1.span_is_contiguous());
347 ASSERT_EQ(x1.span(), 2);
348 ASSERT_TRUE(&x1(0) == &x_static_8(0, 1, 2, 3, 0, 1, 2, 3));
349 ASSERT_TRUE(&x1(1) == &x_static_8(1, 1, 2, 3, 0, 1, 2, 3));
350
351 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x_deg1;
352 make_subview(constr, x_deg1, x_static_8, Kokkos::pair<int, int>(0, 0), 1, 2,
353 3, 0, 1, 2, 3);
354
355 ASSERT_TRUE(x_deg1.span_is_contiguous());
356 ASSERT_EQ(x_deg1.span(), 0);
357 ASSERT_EQ(x_deg1.data(), &x_static_8(0, 1, 2, 3, 0, 1, 2, 3));
358
359 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x_deg2;
360 make_subview(constr, x_deg2, x_static_8, Kokkos::pair<int, int>(2, 2), 2, 3,
361 4, 1, 2, 3, 4);
362
363 ASSERT_TRUE(x_deg2.span_is_contiguous());
364 ASSERT_EQ(x_deg2.span(), 0);
365 ASSERT_EQ(x_deg2.data(), x_static_8.data() + x_static_8.span());
366
367 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2;
368 make_subview(constr, x2, x_static_8, Kokkos::pair<int, int>(0, 2), 1, 2, 3,
369 Kokkos::pair<int, int>(0, 2), 1, 2, 3);
370
371 ASSERT_TRUE(!x2.span_is_contiguous());
372 ASSERT_TRUE(&x2(0, 0) == &x_static_8(0, 1, 2, 3, 0, 1, 2, 3));
373 ASSERT_TRUE(&x2(1, 0) == &x_static_8(1, 1, 2, 3, 0, 1, 2, 3));
374 ASSERT_TRUE(&x2(0, 1) == &x_static_8(0, 1, 2, 3, 1, 1, 2, 3));
375 ASSERT_TRUE(&x2(1, 1) == &x_static_8(1, 1, 2, 3, 1, 1, 2, 3));
376
377 // Kokkos::View< int**, Kokkos::LayoutLeft, Space > error_2 =
378 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2;
379 make_subview(constr, sx2, x_static_8, 1, Kokkos::pair<int, int>(0, 2), 2, 3,
380 Kokkos::pair<int, int>(0, 2), 1, 2, 3);
381
382 ASSERT_TRUE(!sx2.span_is_contiguous());
383 ASSERT_TRUE(&sx2(0, 0) == &x_static_8(1, 0, 2, 3, 0, 1, 2, 3));
384 ASSERT_TRUE(&sx2(1, 0) == &x_static_8(1, 1, 2, 3, 0, 1, 2, 3));
385 ASSERT_TRUE(&sx2(0, 1) == &x_static_8(1, 0, 2, 3, 1, 1, 2, 3));
386 ASSERT_TRUE(&sx2(1, 1) == &x_static_8(1, 1, 2, 3, 1, 1, 2, 3));
387
388 Kokkos::View<int****, Kokkos::LayoutStride, Space> sx4;
389 make_subview(constr, sx4, x_static_8, 0,
390 Kokkos::pair<int, int>(0, 2) /* of [3] */
391 ,
392 1, Kokkos::pair<int, int>(1, 3) /* of [5] */
393 ,
394 1, Kokkos::pair<int, int>(0, 2) /* of [3] */
395 ,
396 2, Kokkos::pair<int, int>(2, 4) /* of [5] */
397 );
398
399 ASSERT_TRUE(!sx4.span_is_contiguous());
400
401 for (int i0 = 0; i0 < (int)sx4.extent(0); ++i0)
402 for (int i1 = 0; i1 < (int)sx4.extent(1); ++i1)
403 for (int i2 = 0; i2 < (int)sx4.extent(2); ++i2)
404 for (int i3 = 0; i3 < (int)sx4.extent(3); ++i3) {
405 ASSERT_TRUE(&sx4(i0, i1, i2, i3) == &x_static_8(0, 0 + i0, 1,
406 1 + i1, 1, 0 + i2,
407 2, 2 + i3));
408 }
409 }
410 }
411
412 template <class Space>
test_left_0()413 void test_left_0() {
414 test_left_0<Space>(true);
415 test_left_0<Space>(false);
416 }
417
418 template <class Space>
test_left_1(bool use_constr)419 void test_left_1(bool use_constr) {
420 using view_type =
421 Kokkos::View<int*** * [2][3][4][5], Kokkos::LayoutLeft, Space>;
422
423 if (Kokkos::Impl::SpaceAccessibility<
424 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
425 view_type x8("x_left_8", 2, 3, 4, 5);
426
427 ASSERT_TRUE(x8.span_is_contiguous());
428
429 Kokkos::View<int, Kokkos::LayoutLeft, Space> x0;
430 make_subview(use_constr, x0, x8, 0, 0, 0, 0, 0, 0, 0, 0);
431
432 ASSERT_TRUE(x0.span_is_contiguous());
433 ASSERT_TRUE(&x0() == &x8(0, 0, 0, 0, 0, 0, 0, 0));
434
435 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x1;
436 make_subview(use_constr, x1, x8, Kokkos::pair<int, int>(0, 2), 1, 2, 3, 0,
437 1, 2, 3);
438
439 ASSERT_TRUE(x1.span_is_contiguous());
440 ASSERT_TRUE(&x1(0) == &x8(0, 1, 2, 3, 0, 1, 2, 3));
441 ASSERT_TRUE(&x1(1) == &x8(1, 1, 2, 3, 0, 1, 2, 3));
442
443 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x1_deg1;
444 make_subview(use_constr, x1_deg1, x8, Kokkos::pair<int, int>(0, 0), 1, 2, 3,
445 0, 1, 2, 3);
446
447 ASSERT_TRUE(x1_deg1.span_is_contiguous());
448 ASSERT_EQ(0, x1_deg1.span());
449 ASSERT_EQ(x1_deg1.data(), &x8(0, 1, 2, 3, 0, 1, 2, 3));
450
451 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x1_deg2;
452 make_subview(use_constr, x1_deg2, x8, Kokkos::pair<int, int>(2, 2), 2, 3, 4,
453 1, 2, 3, 4);
454
455 ASSERT_EQ(0, x1_deg2.span());
456 ASSERT_TRUE(x1_deg2.span_is_contiguous());
457 ASSERT_EQ(x1_deg2.data(), x8.data() + x8.span());
458
459 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2;
460 make_subview(use_constr, x2, x8, Kokkos::pair<int, int>(0, 2), 1, 2, 3,
461 Kokkos::pair<int, int>(0, 2), 1, 2, 3);
462
463 ASSERT_TRUE(!x2.span_is_contiguous());
464 ASSERT_TRUE(&x2(0, 0) == &x8(0, 1, 2, 3, 0, 1, 2, 3));
465 ASSERT_TRUE(&x2(1, 0) == &x8(1, 1, 2, 3, 0, 1, 2, 3));
466 ASSERT_TRUE(&x2(0, 1) == &x8(0, 1, 2, 3, 1, 1, 2, 3));
467 ASSERT_TRUE(&x2(1, 1) == &x8(1, 1, 2, 3, 1, 1, 2, 3));
468
469 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2_deg2;
470 make_subview(use_constr, x2_deg2, x8, Kokkos::pair<int, int>(2, 2), 2, 3, 4,
471 1, 2, Kokkos::pair<int, int>(2, 3), 4);
472 ASSERT_EQ(0, x2_deg2.span());
473
474 // Kokkos::View< int**, Kokkos::LayoutLeft, Space > error_2 =
475 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2;
476 make_subview(use_constr, sx2, x8, 1, Kokkos::pair<int, int>(0, 2), 2, 3,
477 Kokkos::pair<int, int>(0, 2), 1, 2, 3);
478
479 ASSERT_TRUE(!sx2.span_is_contiguous());
480 ASSERT_TRUE(&sx2(0, 0) == &x8(1, 0, 2, 3, 0, 1, 2, 3));
481 ASSERT_TRUE(&sx2(1, 0) == &x8(1, 1, 2, 3, 0, 1, 2, 3));
482 ASSERT_TRUE(&sx2(0, 1) == &x8(1, 0, 2, 3, 1, 1, 2, 3));
483 ASSERT_TRUE(&sx2(1, 1) == &x8(1, 1, 2, 3, 1, 1, 2, 3));
484
485 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2_deg;
486 make_subview(use_constr, sx2, x8, 1, Kokkos::pair<int, int>(0, 0), 2, 3,
487 Kokkos::pair<int, int>(0, 2), 1, 2, 3);
488 ASSERT_EQ(0, sx2_deg.span());
489
490 Kokkos::View<int****, Kokkos::LayoutStride, Space> sx4;
491 make_subview(use_constr, sx4, x8, 0,
492 Kokkos::pair<int, int>(0, 2) /* of [3] */
493 ,
494 1, Kokkos::pair<int, int>(1, 3) /* of [5] */
495 ,
496 1, Kokkos::pair<int, int>(0, 2) /* of [3] */
497 ,
498 2, Kokkos::pair<int, int>(2, 4) /* of [5] */
499 );
500
501 ASSERT_TRUE(!sx4.span_is_contiguous());
502
503 for (int i0 = 0; i0 < (int)sx4.extent(0); ++i0)
504 for (int i1 = 0; i1 < (int)sx4.extent(1); ++i1)
505 for (int i2 = 0; i2 < (int)sx4.extent(2); ++i2)
506 for (int i3 = 0; i3 < (int)sx4.extent(3); ++i3) {
507 ASSERT_TRUE(&sx4(i0, i1, i2, i3) ==
508 &x8(0, 0 + i0, 1, 1 + i1, 1, 0 + i2, 2, 2 + i3));
509 }
510 }
511 }
512
513 template <class Space>
test_left_1()514 void test_left_1() {
515 test_left_1<Space>(true);
516 test_left_1<Space>(false);
517 }
518
519 template <class Space>
test_left_2()520 void test_left_2() {
521 using view_type = Kokkos::View<int****, Kokkos::LayoutLeft, Space>;
522
523 if (Kokkos::Impl::SpaceAccessibility<
524 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
525 view_type x4("x4", 2, 3, 4, 5);
526
527 ASSERT_TRUE(x4.span_is_contiguous());
528
529 Kokkos::View<int, Kokkos::LayoutLeft, Space> x0 =
530 Kokkos::subview(x4, 0, 0, 0, 0);
531
532 ASSERT_TRUE(x0.span_is_contiguous());
533 ASSERT_TRUE(&x0() == &x4(0, 0, 0, 0));
534
535 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x1 =
536 Kokkos::subview(x4, Kokkos::pair<int, int>(0, 2), 1, 2, 3);
537
538 ASSERT_TRUE(x1.span_is_contiguous());
539 ASSERT_TRUE(&x1(0) == &x4(0, 1, 2, 3));
540 ASSERT_TRUE(&x1(1) == &x4(1, 1, 2, 3));
541
542 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2 = Kokkos::subview(
543 x4, Kokkos::pair<int, int>(0, 2), 1, Kokkos::pair<int, int>(1, 3), 2);
544
545 ASSERT_TRUE(!x2.span_is_contiguous());
546 ASSERT_TRUE(&x2(0, 0) == &x4(0, 1, 1, 2));
547 ASSERT_TRUE(&x2(1, 0) == &x4(1, 1, 1, 2));
548 ASSERT_TRUE(&x2(0, 1) == &x4(0, 1, 2, 2));
549 ASSERT_TRUE(&x2(1, 1) == &x4(1, 1, 2, 2));
550
551 // Kokkos::View< int**, Kokkos::LayoutLeft, Space > error_2 =
552 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2 = Kokkos::subview(
553 x4, 1, Kokkos::pair<int, int>(0, 2), 2, Kokkos::pair<int, int>(1, 4));
554
555 ASSERT_TRUE(!sx2.span_is_contiguous());
556 ASSERT_TRUE(&sx2(0, 0) == &x4(1, 0, 2, 1));
557 ASSERT_TRUE(&sx2(1, 0) == &x4(1, 1, 2, 1));
558 ASSERT_TRUE(&sx2(0, 1) == &x4(1, 0, 2, 2));
559 ASSERT_TRUE(&sx2(1, 1) == &x4(1, 1, 2, 2));
560 ASSERT_TRUE(&sx2(0, 2) == &x4(1, 0, 2, 3));
561 ASSERT_TRUE(&sx2(1, 2) == &x4(1, 1, 2, 3));
562
563 Kokkos::View<int****, Kokkos::LayoutStride, Space> sx4 =
564 Kokkos::subview(x4, Kokkos::pair<int, int>(1, 2) /* of [2] */
565 ,
566 Kokkos::pair<int, int>(1, 3) /* of [3] */
567 ,
568 Kokkos::pair<int, int>(0, 4) /* of [4] */
569 ,
570 Kokkos::pair<int, int>(2, 4) /* of [5] */
571 );
572
573 ASSERT_TRUE(!sx4.span_is_contiguous());
574
575 for (int i0 = 0; i0 < (int)sx4.extent(0); ++i0)
576 for (int i1 = 0; i1 < (int)sx4.extent(1); ++i1)
577 for (int i2 = 0; i2 < (int)sx4.extent(2); ++i2)
578 for (int i3 = 0; i3 < (int)sx4.extent(3); ++i3) {
579 ASSERT_TRUE(&sx4(i0, i1, i2, i3) ==
580 &x4(1 + i0, 1 + i1, 0 + i2, 2 + i3));
581 }
582 }
583 }
584
585 template <class Space>
test_left_3()586 void test_left_3() {
587 using view_type = Kokkos::View<int**, Kokkos::LayoutLeft, Space>;
588
589 if (Kokkos::Impl::SpaceAccessibility<
590 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
591 view_type xm("x4", 10, 5);
592
593 ASSERT_TRUE(xm.span_is_contiguous());
594
595 Kokkos::View<int, Kokkos::LayoutLeft, Space> x0 = Kokkos::subview(xm, 5, 3);
596
597 ASSERT_TRUE(x0.span_is_contiguous());
598 ASSERT_TRUE(&x0() == &xm(5, 3));
599
600 Kokkos::View<int*, Kokkos::LayoutLeft, Space> x1 =
601 Kokkos::subview(xm, Kokkos::ALL, 3);
602
603 ASSERT_TRUE(x1.span_is_contiguous());
604 for (int i = 0; i < int(xm.extent(0)); ++i) {
605 ASSERT_TRUE(&x1(i) == &xm(i, 3));
606 }
607
608 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2 =
609 Kokkos::subview(xm, Kokkos::pair<int, int>(1, 9), Kokkos::ALL);
610
611 ASSERT_TRUE(!x2.span_is_contiguous());
612 for (int j = 0; j < int(x2.extent(1)); ++j)
613 for (int i = 0; i < int(x2.extent(0)); ++i) {
614 ASSERT_TRUE(&x2(i, j) == &xm(1 + i, j));
615 }
616
617 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2c =
618 Kokkos::subview(xm, Kokkos::ALL, std::pair<int, int>(2, 4));
619
620 ASSERT_TRUE(x2c.span_is_contiguous());
621 for (int j = 0; j < int(x2c.extent(1)); ++j)
622 for (int i = 0; i < int(x2c.extent(0)); ++i) {
623 ASSERT_TRUE(&x2c(i, j) == &xm(i, 2 + j));
624 }
625
626 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2_n1 =
627 Kokkos::subview(xm, std::pair<int, int>(1, 1), Kokkos::ALL);
628
629 ASSERT_TRUE(x2_n1.extent(0) == 0);
630 ASSERT_TRUE(x2_n1.extent(1) == xm.extent(1));
631
632 Kokkos::View<int**, Kokkos::LayoutLeft, Space> x2_n2 =
633 Kokkos::subview(xm, Kokkos::ALL, std::pair<int, int>(1, 1));
634
635 ASSERT_TRUE(x2_n2.extent(0) == xm.extent(0));
636 ASSERT_TRUE(x2_n2.extent(1) == 0);
637 }
638 }
639
640 //----------------------------------------------------------------------------
641
642 template <class Space>
test_right_0(bool use_constr)643 void test_right_0(bool use_constr) {
644 using view_static_8_type =
645 Kokkos::View<int[2][3][4][5][2][3][4][5], Kokkos::LayoutRight, Space>;
646
647 if (Kokkos::Impl::SpaceAccessibility<
648 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
649 view_static_8_type x_static_8("x_static_right_8");
650
651 Kokkos::View<int, Kokkos::LayoutRight, Space> x0;
652 make_subview(use_constr, x0, x_static_8, 0, 0, 0, 0, 0, 0, 0, 0);
653
654 ASSERT_TRUE(&x0() == &x_static_8(0, 0, 0, 0, 0, 0, 0, 0));
655
656 Kokkos::View<int*, Kokkos::LayoutRight, Space> x1;
657 make_subview(use_constr, x1, x_static_8, 0, 1, 2, 3, 0, 1, 2,
658 Kokkos::pair<int, int>(1, 3));
659
660 ASSERT_TRUE(x1.extent(0) == 2);
661 ASSERT_TRUE(&x1(0) == &x_static_8(0, 1, 2, 3, 0, 1, 2, 1));
662 ASSERT_TRUE(&x1(1) == &x_static_8(0, 1, 2, 3, 0, 1, 2, 2));
663
664 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2;
665 make_subview(use_constr, x2, x_static_8, 0, 1, 2,
666 Kokkos::pair<int, int>(1, 3), 0, 1, 2,
667 Kokkos::pair<int, int>(1, 3));
668
669 ASSERT_TRUE(x2.extent(0) == 2);
670 ASSERT_TRUE(x2.extent(1) == 2);
671 ASSERT_TRUE(&x2(0, 0) == &x_static_8(0, 1, 2, 1, 0, 1, 2, 1));
672 ASSERT_TRUE(&x2(1, 0) == &x_static_8(0, 1, 2, 2, 0, 1, 2, 1));
673 ASSERT_TRUE(&x2(0, 1) == &x_static_8(0, 1, 2, 1, 0, 1, 2, 2));
674 ASSERT_TRUE(&x2(1, 1) == &x_static_8(0, 1, 2, 2, 0, 1, 2, 2));
675
676 // Kokkos::View< int**, Kokkos::LayoutRight, Space > error_2 =
677 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2;
678 make_subview(use_constr, sx2, x_static_8, 1, Kokkos::pair<int, int>(0, 2),
679 2, 3, Kokkos::pair<int, int>(0, 2), 1, 2, 3);
680
681 ASSERT_TRUE(sx2.extent(0) == 2);
682 ASSERT_TRUE(sx2.extent(1) == 2);
683 ASSERT_TRUE(&sx2(0, 0) == &x_static_8(1, 0, 2, 3, 0, 1, 2, 3));
684 ASSERT_TRUE(&sx2(1, 0) == &x_static_8(1, 1, 2, 3, 0, 1, 2, 3));
685 ASSERT_TRUE(&sx2(0, 1) == &x_static_8(1, 0, 2, 3, 1, 1, 2, 3));
686 ASSERT_TRUE(&sx2(1, 1) == &x_static_8(1, 1, 2, 3, 1, 1, 2, 3));
687
688 Kokkos::View<int****, Kokkos::LayoutStride, Space> sx4;
689 make_subview(use_constr, sx4, x_static_8, 0,
690 Kokkos::pair<int, int>(0, 2) /* of [3] */
691 ,
692 1, Kokkos::pair<int, int>(1, 3) /* of [5] */
693 ,
694 1, Kokkos::pair<int, int>(0, 2) /* of [3] */
695 ,
696 2, Kokkos::pair<int, int>(2, 4) /* of [5] */
697 );
698
699 ASSERT_TRUE(sx4.extent(0) == 2);
700 ASSERT_TRUE(sx4.extent(1) == 2);
701 ASSERT_TRUE(sx4.extent(2) == 2);
702 ASSERT_TRUE(sx4.extent(3) == 2);
703 for (int i0 = 0; i0 < (int)sx4.extent(0); ++i0)
704 for (int i1 = 0; i1 < (int)sx4.extent(1); ++i1)
705 for (int i2 = 0; i2 < (int)sx4.extent(2); ++i2)
706 for (int i3 = 0; i3 < (int)sx4.extent(3); ++i3) {
707 ASSERT_TRUE(&sx4(i0, i1, i2, i3) == &x_static_8(0, 0 + i0, 1,
708 1 + i1, 1, 0 + i2,
709 2, 2 + i3));
710 }
711 }
712 }
713
714 template <class Space>
test_right_0()715 void test_right_0() {
716 test_right_0<Space>(true);
717 test_right_0<Space>(false);
718 }
719
720 template <class Space>
test_right_1(bool use_constr)721 void test_right_1(bool use_constr) {
722 using view_type =
723 Kokkos::View<int*** * [2][3][4][5], Kokkos::LayoutRight, Space>;
724
725 if (Kokkos::Impl::SpaceAccessibility<
726 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
727 view_type x8("x_right_8", 2, 3, 4, 5);
728
729 Kokkos::View<int, Kokkos::LayoutRight, Space> x0;
730 make_subview(use_constr, x0, x8, 0, 0, 0, 0, 0, 0, 0, 0);
731
732 ASSERT_TRUE(&x0() == &x8(0, 0, 0, 0, 0, 0, 0, 0));
733
734 Kokkos::View<int*, Kokkos::LayoutRight, Space> x1;
735 make_subview(use_constr, x1, x8, 0, 1, 2, 3, 0, 1, 2,
736 Kokkos::pair<int, int>(1, 3));
737
738 ASSERT_TRUE(&x1(0) == &x8(0, 1, 2, 3, 0, 1, 2, 1));
739 ASSERT_TRUE(&x1(1) == &x8(0, 1, 2, 3, 0, 1, 2, 2));
740
741 Kokkos::View<int*, Kokkos::LayoutRight, Space> x1_deg1;
742 make_subview(use_constr, x1_deg1, x8, 0, 1, 2, 3, 0, 1, 2,
743 Kokkos::pair<int, int>(3, 3));
744 ASSERT_EQ(0, x1_deg1.span());
745
746 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2;
747 make_subview(use_constr, x2, x8, 0, 1, 2, Kokkos::pair<int, int>(1, 3), 0,
748 1, 2, Kokkos::pair<int, int>(1, 3));
749
750 ASSERT_TRUE(&x2(0, 0) == &x8(0, 1, 2, 1, 0, 1, 2, 1));
751 ASSERT_TRUE(&x2(1, 0) == &x8(0, 1, 2, 2, 0, 1, 2, 1));
752 ASSERT_TRUE(&x2(0, 1) == &x8(0, 1, 2, 1, 0, 1, 2, 2));
753 ASSERT_TRUE(&x2(1, 1) == &x8(0, 1, 2, 2, 0, 1, 2, 2));
754
755 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2_deg2;
756 make_subview(use_constr, x2_deg2, x8, 0, 1, 2, Kokkos::pair<int, int>(1, 3),
757 0, 1, 2, Kokkos::pair<int, int>(3, 3));
758 ASSERT_EQ(0, x2_deg2.span());
759
760 // Kokkos::View< int**, Kokkos::LayoutRight, Space > error_2 =
761 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2;
762 make_subview(use_constr, sx2, x8, 1, Kokkos::pair<int, int>(0, 2), 2, 3,
763 Kokkos::pair<int, int>(0, 2), 1, 2, 3);
764
765 ASSERT_TRUE(&sx2(0, 0) == &x8(1, 0, 2, 3, 0, 1, 2, 3));
766 ASSERT_TRUE(&sx2(1, 0) == &x8(1, 1, 2, 3, 0, 1, 2, 3));
767 ASSERT_TRUE(&sx2(0, 1) == &x8(1, 0, 2, 3, 1, 1, 2, 3));
768 ASSERT_TRUE(&sx2(1, 1) == &x8(1, 1, 2, 3, 1, 1, 2, 3));
769
770 Kokkos::View<int**, Kokkos::LayoutStride, Space> sx2_deg;
771 make_subview(use_constr, sx2_deg, x8, 1, Kokkos::pair<int, int>(0, 2), 2, 3,
772 1, 1, 2, Kokkos::pair<int, int>(3, 3));
773 ASSERT_EQ(0, sx2_deg.span());
774
775 Kokkos::View<int****, Kokkos::LayoutStride, Space> sx4;
776 make_subview(use_constr, sx4, x8, 0,
777 Kokkos::pair<int, int>(0, 2) /* of [3] */
778 ,
779 1, Kokkos::pair<int, int>(1, 3) /* of [5] */
780 ,
781 1, Kokkos::pair<int, int>(0, 2) /* of [3] */
782 ,
783 2, Kokkos::pair<int, int>(2, 4) /* of [5] */
784 );
785
786 for (int i0 = 0; i0 < (int)sx4.extent(0); ++i0)
787 for (int i1 = 0; i1 < (int)sx4.extent(1); ++i1)
788 for (int i2 = 0; i2 < (int)sx4.extent(2); ++i2)
789 for (int i3 = 0; i3 < (int)sx4.extent(3); ++i3) {
790 ASSERT_TRUE(&sx4(i0, i1, i2, i3) ==
791 &x8(0, 0 + i0, 1, 1 + i1, 1, 0 + i2, 2, 2 + i3));
792 }
793 }
794 }
795
796 template <class Space>
test_right_1()797 void test_right_1() {
798 test_right_1<Space>(true);
799 test_right_1<Space>(false);
800 }
801
802 template <class Space>
test_right_3()803 void test_right_3() {
804 using view_type = Kokkos::View<int**, Kokkos::LayoutRight, Space>;
805
806 if (Kokkos::Impl::SpaceAccessibility<
807 Kokkos::HostSpace, typename Space::memory_space>::accessible) {
808 view_type xm("x4", 10, 5);
809
810 ASSERT_TRUE(xm.span_is_contiguous());
811
812 Kokkos::View<int, Kokkos::LayoutRight, Space> x0 =
813 Kokkos::subview(xm, 5, 3);
814
815 ASSERT_TRUE(x0.span_is_contiguous());
816 ASSERT_TRUE(&x0() == &xm(5, 3));
817
818 Kokkos::View<int*, Kokkos::LayoutRight, Space> x1 =
819 Kokkos::subview(xm, 3, Kokkos::ALL);
820
821 ASSERT_TRUE(x1.span_is_contiguous());
822 for (int i = 0; i < int(xm.extent(1)); ++i) {
823 ASSERT_TRUE(&x1(i) == &xm(3, i));
824 }
825
826 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2c =
827 Kokkos::subview(xm, Kokkos::pair<int, int>(1, 9), Kokkos::ALL);
828
829 ASSERT_TRUE(x2c.span_is_contiguous());
830 for (int j = 0; j < int(x2c.extent(1)); ++j)
831 for (int i = 0; i < int(x2c.extent(0)); ++i) {
832 ASSERT_TRUE(&x2c(i, j) == &xm(1 + i, j));
833 }
834
835 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2 =
836 Kokkos::subview(xm, Kokkos::ALL, std::pair<int, int>(2, 4));
837
838 ASSERT_TRUE(!x2.span_is_contiguous());
839 for (int j = 0; j < int(x2.extent(1)); ++j)
840 for (int i = 0; i < int(x2.extent(0)); ++i) {
841 ASSERT_TRUE(&x2(i, j) == &xm(i, 2 + j));
842 }
843
844 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2_n1 =
845 Kokkos::subview(xm, std::pair<int, int>(1, 1), Kokkos::ALL);
846
847 ASSERT_TRUE(x2_n1.extent(0) == 0);
848 ASSERT_TRUE(x2_n1.extent(1) == xm.extent(1));
849
850 Kokkos::View<int**, Kokkos::LayoutRight, Space> x2_n2 =
851 Kokkos::subview(xm, Kokkos::ALL, std::pair<int, int>(1, 1));
852
853 ASSERT_TRUE(x2_n2.extent(0) == xm.extent(0));
854 ASSERT_TRUE(x2_n2.extent(1) == 0);
855 }
856 }
857
858 namespace Impl {
859
860 constexpr int N0 = 113;
861 constexpr int N1 = 11;
862 constexpr int N2 = 17;
863 constexpr int N3 = 5;
864 constexpr int N4 = 7;
865
866 template <class Layout, class Space>
867 struct FillView_1D {
868 using view_t = Kokkos::View<int*, Layout, Space>;
869 view_t a;
870 using policy_t = Kokkos::RangePolicy<typename Space::execution_space>;
871
FillView_1DTestViewSubview::Impl::FillView_1D872 FillView_1D(view_t a_) : a(a_) {}
873
runTestViewSubview::Impl::FillView_1D874 void run() {
875 Kokkos::parallel_for("FillView_1D", policy_t(0, a.extent(0)), *this);
876 }
877 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::FillView_1D878 void operator()(int i) const { a(i) = i; }
879 };
880
881 template <class Layout, class Space>
882 struct FillView_3D {
883 using exec_t = typename Space::execution_space;
884 using view_t = Kokkos::View<int***, Layout, Space>;
885 using rank_t = Kokkos::Rank<
886 view_t::Rank,
887 std::is_same<Layout, Kokkos::LayoutLeft>::value ? Kokkos::Iterate::Left
888 : Kokkos::Iterate::Right,
889 std::is_same<Layout, Kokkos::LayoutLeft>::value ? Kokkos::Iterate::Left
890 : Kokkos::Iterate::Right>;
891 using policy_t = Kokkos::MDRangePolicy<exec_t, rank_t>;
892
893 view_t a;
894
FillView_3DTestViewSubview::Impl::FillView_3D895 FillView_3D(view_t a_) : a(a_) {}
896
runTestViewSubview::Impl::FillView_3D897 void run() {
898 Kokkos::parallel_for(
899 "FillView_3D",
900 policy_t({0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}), *this);
901 }
902
903 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::FillView_3D904 void operator()(int i0, int i1, int i2) const {
905 a(i0, i1, i2) = 1000000 * i0 + 1000 * i1 + i2;
906 }
907 };
908
909 template <class Layout, class Space>
910 struct FillView_4D {
911 using exec_t = typename Space::execution_space;
912 using view_t = Kokkos::View<int****, Layout, Space>;
913 using rank_t = Kokkos::Rank<
914 view_t::Rank,
915 std::is_same<Layout, Kokkos::LayoutLeft>::value ? Kokkos::Iterate::Left
916 : Kokkos::Iterate::Right,
917 std::is_same<Layout, Kokkos::LayoutLeft>::value ? Kokkos::Iterate::Left
918 : Kokkos::Iterate::Right>;
919 using policy_t = Kokkos::MDRangePolicy<exec_t, rank_t>;
920
921 view_t a;
922
FillView_4DTestViewSubview::Impl::FillView_4D923 FillView_4D(view_t a_) : a(a_) {}
924
runTestViewSubview::Impl::FillView_4D925 void run() {
926 Kokkos::parallel_for("FillView_4D",
927 policy_t({0, 0, 0, 0}, {a.extent(0), a.extent(1),
928 a.extent(2), a.extent(3)}),
929 *this);
930 }
931
932 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::FillView_4D933 void operator()(int i0, int i1, int i2, int i3) const {
934 a(i0, i1, i2, i3) = 1000000 * i0 + 10000 * i1 + 100 * i2 + i3;
935 }
936 };
937
938 template <class Layout, class Space>
939 struct FillView_5D {
940 using exec_t = typename Space::execution_space;
941 using view_t = Kokkos::View<int*****, Layout, Space>;
942 using rank_t = Kokkos::Rank<
943 view_t::Rank,
944 std::is_same<Layout, Kokkos::LayoutLeft>::value ? Kokkos::Iterate::Left
945 : Kokkos::Iterate::Right,
946 std::is_same<Layout, Kokkos::LayoutLeft>::value ? Kokkos::Iterate::Left
947 : Kokkos::Iterate::Right>;
948 using policy_t = Kokkos::MDRangePolicy<exec_t, rank_t>;
949
950 view_t a;
951
FillView_5DTestViewSubview::Impl::FillView_5D952 FillView_5D(view_t a_) : a(a_) {}
953
runTestViewSubview::Impl::FillView_5D954 void run() {
955 Kokkos::parallel_for(
956 "FillView_5D",
957 policy_t({0, 0, 0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2),
958 a.extent(3), a.extent(4)}),
959 *this);
960 }
961
962 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::FillView_5D963 void operator()(int i0, int i1, int i2, int i3, int i4) const {
964 a(i0, i1, i2, i3, i4) = 1000000 * i0 + 10000 * i1 + 100 * i2 + 10 * i3 + i4;
965 }
966 };
967
968 template <class View, class SubView>
969 struct CheckSubviewCorrectness_1D_1D {
970 using policy_t = Kokkos::RangePolicy<typename View::execution_space>;
971 View a;
972 SubView b;
973 int offset;
974
CheckSubviewCorrectness_1D_1DTestViewSubview::Impl::CheckSubviewCorrectness_1D_1D975 CheckSubviewCorrectness_1D_1D(View a_, SubView b_, int o)
976 : a(a_), b(b_), offset(o) {}
977
runTestViewSubview::Impl::CheckSubviewCorrectness_1D_1D978 void run() {
979 int errors = 0;
980 Kokkos::parallel_reduce("CheckSubView_1D_1D", policy_t(0, b.size()), *this,
981 errors);
982 ASSERT_TRUE(errors == 0);
983 }
984
985 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::CheckSubviewCorrectness_1D_1D986 void operator()(const int& i, int& e) const {
987 if (a(i + offset) != b(i)) {
988 e++;
989 }
990 }
991 };
992
993 template <class View, class SubView>
994 struct CheckSubviewCorrectness_1D_2D {
995 using policy_t = Kokkos::RangePolicy<typename View::execution_space>;
996 View a;
997 SubView b;
998 int i0;
999 int offset;
1000
CheckSubviewCorrectness_1D_2DTestViewSubview::Impl::CheckSubviewCorrectness_1D_2D1001 CheckSubviewCorrectness_1D_2D(View a_, SubView b_, int i0_, int o)
1002 : a(a_), b(b_), i0(i0_), offset(o) {}
1003
runTestViewSubview::Impl::CheckSubviewCorrectness_1D_2D1004 void run() {
1005 int errors = 0;
1006 Kokkos::parallel_reduce("CheckSubView_1D_2D", policy_t(0, b.size()), *this,
1007 errors);
1008 ASSERT_TRUE(errors == 0);
1009 }
1010
1011 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::CheckSubviewCorrectness_1D_2D1012 void operator()(const int& i1, int& e) const {
1013 if (a(i0, i1 + offset) != b(i1)) {
1014 e++;
1015 }
1016 }
1017 };
1018
1019 template <class View, class SubView>
1020 struct CheckSubviewCorrectness_2D_3D {
1021 using policy_t = Kokkos::RangePolicy<typename View::execution_space>;
1022 using layout = typename View::array_layout;
1023 View a;
1024 SubView b;
1025 int i0;
1026 int offset_1;
1027 int offset_2;
1028
CheckSubviewCorrectness_2D_3DTestViewSubview::Impl::CheckSubviewCorrectness_2D_3D1029 CheckSubviewCorrectness_2D_3D(View a_, SubView b_, int i0_, int o1, int o2)
1030 : a(a_), b(b_), i0(i0_), offset_1(o1), offset_2(o2) {}
1031
runTestViewSubview::Impl::CheckSubviewCorrectness_2D_3D1032 void run() {
1033 int errors = 0;
1034 Kokkos::parallel_reduce("CheckSubView_2D_3D", policy_t(0, b.size()), *this,
1035 errors);
1036 ASSERT_TRUE(errors == 0);
1037 }
1038
1039 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::CheckSubviewCorrectness_2D_3D1040 void operator()(const int& ii, int& e) const {
1041 const int i1 = std::is_same<layout, Kokkos::LayoutLeft>::value
1042 ? ii % b.extent(0)
1043 : ii / b.extent(1);
1044
1045 const int i2 = std::is_same<layout, Kokkos::LayoutLeft>::value
1046 ? ii / b.extent(0)
1047 : ii % b.extent(1);
1048
1049 if (a(i0, i1 + offset_1, i2 + offset_2) != b(i1, i2)) {
1050 e++;
1051 }
1052 }
1053 };
1054
1055 template <class View, class SubView>
1056 struct CheckSubviewCorrectness_3D_3D {
1057 using policy_t = Kokkos::RangePolicy<typename View::execution_space>;
1058 using layout = typename View::array_layout;
1059 View a;
1060 SubView b;
1061 int offset_0;
1062 int offset_2;
1063
CheckSubviewCorrectness_3D_3DTestViewSubview::Impl::CheckSubviewCorrectness_3D_3D1064 CheckSubviewCorrectness_3D_3D(View a_, SubView b_, int o0, int o2)
1065 : a(a_), b(b_), offset_0(o0), offset_2(o2) {}
1066
runTestViewSubview::Impl::CheckSubviewCorrectness_3D_3D1067 void run() {
1068 int errors = 0;
1069 Kokkos::parallel_reduce("CheckSubView_3D_3D", policy_t(0, b.size()), *this,
1070 errors);
1071 ASSERT_TRUE(errors == 0);
1072 }
1073
1074 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::CheckSubviewCorrectness_3D_3D1075 void operator()(const int& ii, int& e) const {
1076 const int i0 = std::is_same<layout, Kokkos::LayoutLeft>::value
1077 ? ii % b.extent(0)
1078 : ii / (b.extent(1) * b.extent(2));
1079
1080 const int i1 = std::is_same<layout, Kokkos::LayoutLeft>::value
1081 ? (ii / b.extent(0)) % b.extent(1)
1082 : (ii / b.extent(2)) % b.extent(1);
1083
1084 const int i2 = std::is_same<layout, Kokkos::LayoutLeft>::value
1085 ? ii / (b.extent(0) * b.extent(1))
1086 : ii % b.extent(2);
1087
1088 if (a(i0 + offset_0, i1, i2 + offset_2) != b(i0, i1, i2)) {
1089 e++;
1090 }
1091 }
1092 };
1093
1094 template <class View, class SubView>
1095 struct CheckSubviewCorrectness_3D_4D {
1096 using policy_t = Kokkos::RangePolicy<typename View::execution_space>;
1097 using layout = typename View::array_layout;
1098 View a;
1099 SubView b;
1100 int index;
1101 int offset_0, offset_2;
1102
CheckSubviewCorrectness_3D_4DTestViewSubview::Impl::CheckSubviewCorrectness_3D_4D1103 CheckSubviewCorrectness_3D_4D(View a_, SubView b_, int index_, int o0, int o2)
1104 : a(a_), b(b_), index(index_), offset_0(o0), offset_2(o2) {}
1105
runTestViewSubview::Impl::CheckSubviewCorrectness_3D_4D1106 void run() {
1107 int errors = 0;
1108 Kokkos::parallel_reduce("CheckSubView_3D_4D", policy_t(0, b.size()), *this,
1109 errors);
1110 ASSERT_TRUE(errors == 0);
1111 }
1112
1113 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::CheckSubviewCorrectness_3D_4D1114 void operator()(const int& ii, int& e) const {
1115 const int i = std::is_same<layout, Kokkos::LayoutLeft>::value
1116 ? ii % b.extent(0)
1117 : ii / (b.extent(1) * b.extent(2));
1118
1119 const int j = std::is_same<layout, Kokkos::LayoutLeft>::value
1120 ? (ii / b.extent(0)) % b.extent(1)
1121 : (ii / b.extent(2)) % b.extent(1);
1122
1123 const int k = std::is_same<layout, Kokkos::LayoutLeft>::value
1124 ? ii / (b.extent(0) * b.extent(1))
1125 : ii % b.extent(2);
1126
1127 int i0, i1, i2, i3;
1128
1129 if (std::is_same<layout, Kokkos::LayoutLeft>::value) {
1130 i0 = i + offset_0;
1131 i1 = j;
1132 i2 = k + offset_2;
1133 i3 = index;
1134 } else {
1135 i0 = index;
1136 i1 = i + offset_0;
1137 i2 = j;
1138 i3 = k + offset_2;
1139 }
1140
1141 if (a(i0, i1, i2, i3) != b(i, j, k)) e++;
1142 }
1143 };
1144
1145 template <class View, class SubView>
1146 struct CheckSubviewCorrectness_3D_5D {
1147 using policy_t = Kokkos::RangePolicy<typename View::execution_space>;
1148 using layout = typename View::array_layout;
1149 View a;
1150 SubView b;
1151 int i0, i1;
1152 int offset_2, offset_3, offset_4;
1153
CheckSubviewCorrectness_3D_5DTestViewSubview::Impl::CheckSubviewCorrectness_3D_5D1154 CheckSubviewCorrectness_3D_5D(View a_, SubView b_, int i0_, int i1_, int o2,
1155 int o3, int o4)
1156 : a(a_),
1157 b(b_),
1158 i0(i0_),
1159 i1(i1_),
1160 offset_2(o2),
1161 offset_3(o3),
1162 offset_4(o4) {}
1163
runTestViewSubview::Impl::CheckSubviewCorrectness_3D_5D1164 void run() {
1165 int errors = 0;
1166 Kokkos::parallel_reduce("CheckSubView_3D_5D", policy_t(0, b.size()), *this,
1167 errors);
1168 ASSERT_TRUE(errors == 0);
1169 }
1170
1171 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::Impl::CheckSubviewCorrectness_3D_5D1172 void operator()(const int& ii, int& e) const {
1173 const int i2 = std::is_same<layout, Kokkos::LayoutLeft>::value
1174 ? ii % b.extent(0)
1175 : ii / (b.extent(1) * b.extent(2));
1176
1177 const int i3 = std::is_same<layout, Kokkos::LayoutLeft>::value
1178 ? (ii / b.extent(0)) % b.extent(1)
1179 : (ii / b.extent(2)) % b.extent(1);
1180
1181 const int i4 = std::is_same<layout, Kokkos::LayoutLeft>::value
1182 ? ii / (b.extent(0) * b.extent(1))
1183 : ii % b.extent(2);
1184
1185 if (a(i0, i1, i2 + offset_2, i3 + offset_3, i4 + offset_4) !=
1186 b(i2, i3, i4)) {
1187 e++;
1188 }
1189 }
1190 };
1191
1192 template <class SubView, class View>
test_Check1D(SubView a,View b,Kokkos::pair<int,int> range)1193 void test_Check1D(SubView a, View b, Kokkos::pair<int, int> range) {
1194 CheckSubviewCorrectness_1D_1D<View, SubView> check(b, a, range.first);
1195 check.run();
1196 }
1197
1198 template <class SubView, class View>
test_Check1D2D(SubView a,View b,int i0,std::pair<int,int> range)1199 void test_Check1D2D(SubView a, View b, int i0, std::pair<int, int> range) {
1200 CheckSubviewCorrectness_1D_2D<View, SubView> check(b, a, i0, range.first);
1201 check.run();
1202 }
1203
1204 template <class SubView, class View>
test_Check2D3D(SubView a,View b,int i0,std::pair<int,int> range1,std::pair<int,int> range2)1205 void test_Check2D3D(SubView a, View b, int i0, std::pair<int, int> range1,
1206 std::pair<int, int> range2) {
1207 CheckSubviewCorrectness_2D_3D<View, SubView> check(b, a, i0, range1.first,
1208 range2.first);
1209 check.run();
1210 }
1211
1212 template <class SubView, class View>
test_Check3D5D(SubView a,View b,int i0,int i1,Kokkos::pair<int,int> range2,Kokkos::pair<int,int> range3,Kokkos::pair<int,int> range4)1213 void test_Check3D5D(SubView a, View b, int i0, int i1,
1214 Kokkos::pair<int, int> range2,
1215 Kokkos::pair<int, int> range3,
1216 Kokkos::pair<int, int> range4) {
1217 CheckSubviewCorrectness_3D_5D<View, SubView> check(
1218 b, a, i0, i1, range2.first, range3.first, range4.first);
1219 check.run();
1220 }
1221
1222 template <class Space, class LayoutSub, class Layout, class LayoutOrg,
1223 class MemTraits>
test_1d_assign_impl()1224 void test_1d_assign_impl() {
1225 { // Breaks.
1226 Kokkos::View<int*, LayoutOrg, Space> a_org("A", N0);
1227 Kokkos::View<int*, LayoutOrg, Space, MemTraits> a(a_org);
1228 Kokkos::fence();
1229
1230 Impl::FillView_1D<LayoutOrg, Space> fill(a_org);
1231 fill.run();
1232
1233 Kokkos::View<int[N0], Layout, Space, MemTraits> a1(a);
1234 Kokkos::fence();
1235 test_Check1D(a1, a, std::pair<int, int>(0, N0));
1236
1237 Kokkos::View<int[N0], LayoutSub, Space, MemTraits> a2(a1);
1238 Kokkos::fence();
1239 test_Check1D(a2, a, std::pair<int, int>(0, N0));
1240 a1 = a;
1241 test_Check1D(a1, a, std::pair<int, int>(0, N0));
1242
1243 // Runtime Fail expected.
1244 // Kokkos::View< int[N1] > afail1( a );
1245
1246 // Compile Time Fail expected.
1247 // Kokkos::View< int[N1] > afail2( a1 );
1248 }
1249
1250 { // Works.
1251 Kokkos::View<int[N0], LayoutOrg, Space, MemTraits> a("A");
1252 Kokkos::View<int*, Layout, Space, MemTraits> a1(a);
1253 Kokkos::fence();
1254 test_Check1D(a1, a, std::pair<int, int>(0, N0));
1255 a1 = a;
1256 Kokkos::fence();
1257 test_Check1D(a1, a, std::pair<int, int>(0, N0));
1258 }
1259 }
1260
1261 template <class Space, class Type, class TypeSub, class LayoutSub, class Layout,
1262 class LayoutOrg, class MemTraits>
test_2d_subview_3d_impl_type()1263 void test_2d_subview_3d_impl_type() {
1264 Kokkos::View<int***, LayoutOrg, Space> a_org("A", N0, N1, N2);
1265 Kokkos::View<Type, Layout, Space, MemTraits> a(a_org);
1266
1267 Impl::FillView_3D<LayoutOrg, Space> fill(a_org);
1268 fill.run();
1269
1270 Kokkos::View<TypeSub, LayoutSub, Space, MemTraits> a1;
1271 a1 = Kokkos::subview(a, 3, Kokkos::ALL, Kokkos::ALL);
1272 Kokkos::fence();
1273 test_Check2D3D(a1, a, 3, std::pair<int, int>(0, N1),
1274 std::pair<int, int>(0, N2));
1275
1276 Kokkos::View<TypeSub, LayoutSub, Space, MemTraits> a2(a, 3, Kokkos::ALL,
1277 Kokkos::ALL);
1278 Kokkos::fence();
1279 test_Check2D3D(a2, a, 3, std::pair<int, int>(0, N1),
1280 std::pair<int, int>(0, N2));
1281 }
1282
1283 template <class Space, class LayoutSub, class Layout, class LayoutOrg,
1284 class MemTraits>
test_2d_subview_3d_impl_layout()1285 void test_2d_subview_3d_impl_layout() {
1286 test_2d_subview_3d_impl_type<Space, int[N0][N1][N2], int[N1][N2], LayoutSub,
1287 Layout, LayoutOrg, MemTraits>();
1288 test_2d_subview_3d_impl_type<Space, int[N0][N1][N2], int * [N2], LayoutSub,
1289 Layout, LayoutOrg, MemTraits>();
1290 test_2d_subview_3d_impl_type<Space, int[N0][N1][N2], int**, LayoutSub, Layout,
1291 LayoutOrg, MemTraits>();
1292
1293 test_2d_subview_3d_impl_type<Space, int * [N1][N2], int[N1][N2], LayoutSub,
1294 Layout, LayoutOrg, MemTraits>();
1295 test_2d_subview_3d_impl_type<Space, int * [N1][N2], int * [N2], LayoutSub,
1296 Layout, LayoutOrg, MemTraits>();
1297 test_2d_subview_3d_impl_type<Space, int * [N1][N2], int**, LayoutSub, Layout,
1298 LayoutOrg, MemTraits>();
1299
1300 test_2d_subview_3d_impl_type<Space, int* * [N2], int[N1][N2], LayoutSub,
1301 Layout, LayoutOrg, MemTraits>();
1302 test_2d_subview_3d_impl_type<Space, int* * [N2], int * [N2], LayoutSub,
1303 Layout, LayoutOrg, MemTraits>();
1304 test_2d_subview_3d_impl_type<Space, int* * [N2], int**, LayoutSub, Layout,
1305 LayoutOrg, MemTraits>();
1306
1307 test_2d_subview_3d_impl_type<Space, int***, int[N1][N2], LayoutSub, Layout,
1308 LayoutOrg, MemTraits>();
1309 test_2d_subview_3d_impl_type<Space, int***, int * [N2], LayoutSub, Layout,
1310 LayoutOrg, MemTraits>();
1311 test_2d_subview_3d_impl_type<Space, int***, int**, LayoutSub, Layout,
1312 LayoutOrg, MemTraits>();
1313
1314 test_2d_subview_3d_impl_type<Space, const int[N0][N1][N2], const int[N1][N2],
1315 LayoutSub, Layout, LayoutOrg, MemTraits>();
1316 test_2d_subview_3d_impl_type<Space, const int[N0][N1][N2], const int * [N2],
1317 LayoutSub, Layout, LayoutOrg, MemTraits>();
1318 test_2d_subview_3d_impl_type<Space, const int[N0][N1][N2], const int**,
1319 LayoutSub, Layout, LayoutOrg, MemTraits>();
1320
1321 test_2d_subview_3d_impl_type<Space, const int * [N1][N2], const int[N1][N2],
1322 LayoutSub, Layout, LayoutOrg, MemTraits>();
1323 test_2d_subview_3d_impl_type<Space, const int * [N1][N2], const int * [N2],
1324 LayoutSub, Layout, LayoutOrg, MemTraits>();
1325 test_2d_subview_3d_impl_type<Space, const int * [N1][N2], const int**,
1326 LayoutSub, Layout, LayoutOrg, MemTraits>();
1327
1328 test_2d_subview_3d_impl_type<Space, const int* * [N2], const int[N1][N2],
1329 LayoutSub, Layout, LayoutOrg, MemTraits>();
1330 test_2d_subview_3d_impl_type<Space, const int* * [N2], const int * [N2],
1331 LayoutSub, Layout, LayoutOrg, MemTraits>();
1332 test_2d_subview_3d_impl_type<Space, const int* * [N2], const int**, LayoutSub,
1333 Layout, LayoutOrg, MemTraits>();
1334
1335 test_2d_subview_3d_impl_type<Space, const int***, const int[N1][N2],
1336 LayoutSub, Layout, LayoutOrg, MemTraits>();
1337 test_2d_subview_3d_impl_type<Space, const int***, const int * [N2], LayoutSub,
1338 Layout, LayoutOrg, MemTraits>();
1339 test_2d_subview_3d_impl_type<Space, const int***, const int**, LayoutSub,
1340 Layout, LayoutOrg, MemTraits>();
1341 }
1342
1343 template <class Space, class Type, class TypeSub, class LayoutSub, class Layout,
1344 class LayoutOrg, class MemTraits>
test_3d_subview_5d_impl_type()1345 void test_3d_subview_5d_impl_type() {
1346 Kokkos::View<int*****, LayoutOrg, Space> a_org("A", N0, N1, N2, N3, N4);
1347 Kokkos::View<Type, Layout, Space, MemTraits> a(a_org);
1348
1349 Impl::FillView_5D<LayoutOrg, Space> fill(a_org);
1350 fill.run();
1351
1352 Kokkos::View<TypeSub, LayoutSub, Space, MemTraits> a1;
1353 a1 = Kokkos::subview(a, 3, 5, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL);
1354 Kokkos::fence();
1355 test_Check3D5D(a1, a, 3, 5, std::pair<int, int>(0, N2),
1356 std::pair<int, int>(0, N3), std::pair<int, int>(0, N4));
1357
1358 Kokkos::View<TypeSub, LayoutSub, Space, MemTraits> a2(
1359 a, 3, 5, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL);
1360 Kokkos::fence();
1361 test_Check3D5D(a2, a, 3, 5, std::pair<int, int>(0, N2),
1362 std::pair<int, int>(0, N3), std::pair<int, int>(0, N4));
1363 }
1364
1365 template <class Space, class LayoutSub, class Layout, class LayoutOrg,
1366 class MemTraits>
test_3d_subview_5d_impl_layout()1367 void test_3d_subview_5d_impl_layout() {
1368 test_3d_subview_5d_impl_type<Space, int[N0][N1][N2][N3][N4], int[N2][N3][N4],
1369 LayoutSub, Layout, LayoutOrg, MemTraits>();
1370 test_3d_subview_5d_impl_type<Space, int[N0][N1][N2][N3][N4], int * [N3][N4],
1371 LayoutSub, Layout, LayoutOrg, MemTraits>();
1372 test_3d_subview_5d_impl_type<Space, int[N0][N1][N2][N3][N4], int* * [N4],
1373 LayoutSub, Layout, LayoutOrg, MemTraits>();
1374 test_3d_subview_5d_impl_type<Space, int[N0][N1][N2][N3][N4], int***,
1375 LayoutSub, Layout, LayoutOrg, MemTraits>();
1376
1377 test_3d_subview_5d_impl_type<Space, int * [N1][N2][N3][N4], int[N2][N3][N4],
1378 LayoutSub, Layout, LayoutOrg, MemTraits>();
1379 test_3d_subview_5d_impl_type<Space, int * [N1][N2][N3][N4], int * [N3][N4],
1380 LayoutSub, Layout, LayoutOrg, MemTraits>();
1381 test_3d_subview_5d_impl_type<Space, int * [N1][N2][N3][N4], int* * [N4],
1382 LayoutSub, Layout, LayoutOrg, MemTraits>();
1383 test_3d_subview_5d_impl_type<Space, int * [N1][N2][N3][N4], int***, LayoutSub,
1384 Layout, LayoutOrg, MemTraits>();
1385
1386 test_3d_subview_5d_impl_type<Space, int* * [N2][N3][N4], int[N2][N3][N4],
1387 LayoutSub, Layout, LayoutOrg, MemTraits>();
1388 test_3d_subview_5d_impl_type<Space, int* * [N2][N3][N4], int * [N3][N4],
1389 LayoutSub, Layout, LayoutOrg, MemTraits>();
1390 test_3d_subview_5d_impl_type<Space, int* * [N2][N3][N4], int* * [N4],
1391 LayoutSub, Layout, LayoutOrg, MemTraits>();
1392 test_3d_subview_5d_impl_type<Space, int* * [N2][N3][N4], int***, LayoutSub,
1393 Layout, LayoutOrg, MemTraits>();
1394
1395 test_3d_subview_5d_impl_type<Space, int** * [N3][N4], int[N2][N3][N4],
1396 LayoutSub, Layout, LayoutOrg, MemTraits>();
1397 test_3d_subview_5d_impl_type<Space, int** * [N3][N4], int * [N3][N4],
1398 LayoutSub, Layout, LayoutOrg, MemTraits>();
1399 test_3d_subview_5d_impl_type<Space, int** * [N3][N4], int* * [N4], LayoutSub,
1400 Layout, LayoutOrg, MemTraits>();
1401 test_3d_subview_5d_impl_type<Space, int** * [N3][N4], int***, LayoutSub,
1402 Layout, LayoutOrg, MemTraits>();
1403
1404 test_3d_subview_5d_impl_type<Space, int*** * [N4], int[N2][N3][N4], LayoutSub,
1405 Layout, LayoutOrg, MemTraits>();
1406 test_3d_subview_5d_impl_type<Space, int*** * [N4], int * [N3][N4], LayoutSub,
1407 Layout, LayoutOrg, MemTraits>();
1408 test_3d_subview_5d_impl_type<Space, int*** * [N4], int* * [N4], LayoutSub,
1409 Layout, LayoutOrg, MemTraits>();
1410 test_3d_subview_5d_impl_type<Space, int*** * [N4], int***, LayoutSub, Layout,
1411 LayoutOrg, MemTraits>();
1412
1413 test_3d_subview_5d_impl_type<Space, int*****, int[N2][N3][N4], LayoutSub,
1414 Layout, LayoutOrg, MemTraits>();
1415 test_3d_subview_5d_impl_type<Space, int*****, int * [N3][N4], LayoutSub,
1416 Layout, LayoutOrg, MemTraits>();
1417 test_3d_subview_5d_impl_type<Space, int*****, int* * [N4], LayoutSub, Layout,
1418 LayoutOrg, MemTraits>();
1419 test_3d_subview_5d_impl_type<Space, int*****, int***, LayoutSub, Layout,
1420 LayoutOrg, MemTraits>();
1421
1422 test_3d_subview_5d_impl_type<Space, const int[N0][N1][N2][N3][N4],
1423 const int[N2][N3][N4], LayoutSub, Layout,
1424 LayoutOrg, MemTraits>();
1425 test_3d_subview_5d_impl_type<Space, const int[N0][N1][N2][N3][N4],
1426 const int * [N3][N4], LayoutSub, Layout,
1427 LayoutOrg, MemTraits>();
1428 test_3d_subview_5d_impl_type<Space, const int[N0][N1][N2][N3][N4],
1429 const int* * [N4], LayoutSub, Layout, LayoutOrg,
1430 MemTraits>();
1431 test_3d_subview_5d_impl_type<Space, const int[N0][N1][N2][N3][N4],
1432 const int***, LayoutSub, Layout, LayoutOrg,
1433 MemTraits>();
1434
1435 test_3d_subview_5d_impl_type<Space, const int * [N1][N2][N3][N4],
1436 const int[N2][N3][N4], LayoutSub, Layout,
1437 LayoutOrg, MemTraits>();
1438 test_3d_subview_5d_impl_type<Space, const int * [N1][N2][N3][N4],
1439 const int * [N3][N4], LayoutSub, Layout,
1440 LayoutOrg, MemTraits>();
1441 test_3d_subview_5d_impl_type<Space, const int * [N1][N2][N3][N4],
1442 const int* * [N4], LayoutSub, Layout, LayoutOrg,
1443 MemTraits>();
1444 test_3d_subview_5d_impl_type<Space, const int * [N1][N2][N3][N4],
1445 const int***, LayoutSub, Layout, LayoutOrg,
1446 MemTraits>();
1447
1448 test_3d_subview_5d_impl_type<Space, const int* * [N2][N3][N4],
1449 const int[N2][N3][N4], LayoutSub, Layout,
1450 LayoutOrg, MemTraits>();
1451 test_3d_subview_5d_impl_type<Space, const int* * [N2][N3][N4],
1452 const int * [N3][N4], LayoutSub, Layout,
1453 LayoutOrg, MemTraits>();
1454 test_3d_subview_5d_impl_type<Space, const int* * [N2][N3][N4],
1455 const int* * [N4], LayoutSub, Layout, LayoutOrg,
1456 MemTraits>();
1457 test_3d_subview_5d_impl_type<Space, const int* * [N2][N3][N4], const int***,
1458 LayoutSub, Layout, LayoutOrg, MemTraits>();
1459
1460 test_3d_subview_5d_impl_type<Space, const int** * [N3][N4],
1461 const int[N2][N3][N4], LayoutSub, Layout,
1462 LayoutOrg, MemTraits>();
1463 test_3d_subview_5d_impl_type<Space, const int** * [N3][N4],
1464 const int * [N3][N4], LayoutSub, Layout,
1465 LayoutOrg, MemTraits>();
1466 test_3d_subview_5d_impl_type<Space, const int** * [N3][N4], const int* * [N4],
1467 LayoutSub, Layout, LayoutOrg, MemTraits>();
1468 test_3d_subview_5d_impl_type<Space, const int** * [N3][N4], const int***,
1469 LayoutSub, Layout, LayoutOrg, MemTraits>();
1470
1471 test_3d_subview_5d_impl_type<Space, const int*** * [N4],
1472 const int[N2][N3][N4], LayoutSub, Layout,
1473 LayoutOrg, MemTraits>();
1474 test_3d_subview_5d_impl_type<Space, const int*** * [N4], const int * [N3][N4],
1475 LayoutSub, Layout, LayoutOrg, MemTraits>();
1476 test_3d_subview_5d_impl_type<Space, const int*** * [N4], const int* * [N4],
1477 LayoutSub, Layout, LayoutOrg, MemTraits>();
1478 test_3d_subview_5d_impl_type<Space, const int*** * [N4], const int***,
1479 LayoutSub, Layout, LayoutOrg, MemTraits>();
1480
1481 test_3d_subview_5d_impl_type<Space, const int*****, const int[N2][N3][N4],
1482 LayoutSub, Layout, LayoutOrg, MemTraits>();
1483 test_3d_subview_5d_impl_type<Space, const int*****, const int * [N3][N4],
1484 LayoutSub, Layout, LayoutOrg, MemTraits>();
1485 test_3d_subview_5d_impl_type<Space, const int*****, const int* * [N4],
1486 LayoutSub, Layout, LayoutOrg, MemTraits>();
1487 test_3d_subview_5d_impl_type<Space, const int*****, const int***, LayoutSub,
1488 Layout, LayoutOrg, MemTraits>();
1489 }
1490
test_subview_legal_args_right()1491 inline void test_subview_legal_args_right() {
1492 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1493 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1494 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1495 Kokkos::pair<int, int>, int, int>::value));
1496 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1497 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1498 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1499 Kokkos::Impl::ALL_t, int, int>::value));
1500 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1501 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1502 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1503 Kokkos::pair<int, int>, int, int>::value));
1504 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1505 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1506 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1507 Kokkos::Impl::ALL_t, int, int>::value));
1508 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1509 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1510 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1511 Kokkos::pair<int, int>, int, int>::value));
1512 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1513 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1514 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1515 Kokkos::Impl::ALL_t, int, int>::value));
1516 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1517 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1518 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1519 Kokkos::pair<int, int>, int, int>::value));
1520 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1521 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1522 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1523 Kokkos::Impl::ALL_t, int, int>::value));
1524
1525 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1526 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1527 Kokkos::Impl::ALL_t, int, Kokkos::Impl::ALL_t,
1528 Kokkos::pair<int, int>, int>::value));
1529 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1530 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1531 Kokkos::Impl::ALL_t, int, Kokkos::Impl::ALL_t,
1532 Kokkos::Impl::ALL_t, int>::value));
1533 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1534 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1535 Kokkos::Impl::ALL_t, int, Kokkos::pair<int, int>,
1536 Kokkos::pair<int, int>, int>::value));
1537 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1538 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1539 Kokkos::Impl::ALL_t, int, Kokkos::pair<int, int>,
1540 Kokkos::Impl::ALL_t, int>::value));
1541 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1542 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1543 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t,
1544 Kokkos::pair<int, int>, int>::value));
1545 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1546 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1547 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t,
1548 Kokkos::Impl::ALL_t, int>::value));
1549 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1550 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1551 Kokkos::pair<int, int>, int, Kokkos::pair<int, int>,
1552 Kokkos::pair<int, int>, int>::value));
1553 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1554 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1555 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t,
1556 Kokkos::pair<int, int>, int>::value));
1557
1558 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1559 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1560 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int,
1561 Kokkos::pair<int, int>, int>::value));
1562 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1563 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1564 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int,
1565 Kokkos::Impl::ALL_t, int>::value));
1566 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1567 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1568 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int,
1569 Kokkos::pair<int, int>, int>::value));
1570 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1571 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1572 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int,
1573 Kokkos::Impl::ALL_t, int>::value));
1574 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1575 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1576 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1577 Kokkos::pair<int, int>, int>::value));
1578 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1579 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1580 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1581 Kokkos::Impl::ALL_t, int>::value));
1582 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1583 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1584 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int,
1585 Kokkos::pair<int, int>, int>::value));
1586 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1587 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0,
1588 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1589 Kokkos::pair<int, int>, int>::value));
1590
1591 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1592 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1593 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1594 Kokkos::pair<int, int>, int>::value));
1595 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1596 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1597 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1598 Kokkos::Impl::ALL_t, int>::value));
1599 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1600 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1601 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1602 Kokkos::pair<int, int>, int>::value));
1603 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1604 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1605 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1606 Kokkos::Impl::ALL_t, int>::value));
1607 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1608 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1609 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1610 Kokkos::pair<int, int>, int>::value));
1611 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1612 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1613 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1614 Kokkos::Impl::ALL_t, int>::value));
1615 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1616 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1617 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1618 Kokkos::pair<int, int>, int>::value));
1619 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1620 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1621 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1622 Kokkos::Impl::ALL_t, int>::value));
1623
1624 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1625 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1626 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int,
1627 Kokkos::pair<int, int>>::value));
1628 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1629 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1630 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int,
1631 Kokkos::Impl::ALL_t>::value));
1632 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1633 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1634 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int,
1635 Kokkos::pair<int, int>>::value));
1636 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1637 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1638 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int,
1639 Kokkos::Impl::ALL_t>::value));
1640 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1641 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1642 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1643 Kokkos::pair<int, int>>::value));
1644 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1645 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1646 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1647 Kokkos::Impl::ALL_t>::value));
1648 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1649 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1650 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int,
1651 Kokkos::pair<int, int>>::value));
1652 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1653 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int,
1654 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int,
1655 Kokkos::Impl::ALL_t>::value));
1656
1657 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1658 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1659 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1660 Kokkos::pair<int, int>>::value));
1661 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1662 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1663 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1664 Kokkos::Impl::ALL_t>::value));
1665 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1666 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1667 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1668 Kokkos::pair<int, int>>::value));
1669 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1670 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1671 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1672 Kokkos::Impl::ALL_t>::value));
1673 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1674 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1675 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1676 Kokkos::pair<int, int>>::value));
1677 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1678 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1679 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1680 Kokkos::Impl::ALL_t>::value));
1681 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1682 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1683 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1684 Kokkos::pair<int, int>>::value));
1685 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1686 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 5, 0, int, int,
1687 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1688 Kokkos::Impl::ALL_t>::value));
1689
1690 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1691 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1692 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1693 Kokkos::Impl::ALL_t>::value));
1694 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1695 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1696 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1697 Kokkos::pair<int, int>>::value));
1698 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1699 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1700 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1701 Kokkos::Impl::ALL_t>::value));
1702 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1703 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1704 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1705 Kokkos::pair<int, int>>::value));
1706 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1707 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1708 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1709 Kokkos::Impl::ALL_t>::value));
1710 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1711 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1712 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1713 Kokkos::pair<int, int>>::value));
1714 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1715 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1716 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1717 Kokkos::Impl::ALL_t>::value));
1718 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1719 Kokkos::LayoutRight, Kokkos::LayoutRight, 3, 3, 0,
1720 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1721 Kokkos::pair<int, int>>::value));
1722 }
1723
test_subview_legal_args_left()1724 inline void test_subview_legal_args_left() {
1725 ASSERT_EQ(
1726 1,
1727 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1728 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1729 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int, int>::value));
1730 ASSERT_EQ(
1731 1,
1732 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1733 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1734 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int, int>::value));
1735 ASSERT_EQ(
1736 0,
1737 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1738 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1739 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int, int>::value));
1740 ASSERT_EQ(
1741 0,
1742 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1743 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1744 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int, int>::value));
1745 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1746 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1747 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1748 Kokkos::pair<int, int>, int, int>::value));
1749 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1750 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1751 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1752 Kokkos::Impl::ALL_t, int, int>::value));
1753 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1754 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1755 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1756 Kokkos::pair<int, int>, int, int>::value));
1757 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1758 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1759 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1760 Kokkos::Impl::ALL_t, int, int>::value));
1761
1762 ASSERT_EQ(
1763 0,
1764 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1765 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1766 int, Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int>::value));
1767 ASSERT_EQ(
1768 0,
1769 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1770 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1771 int, Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int>::value));
1772 ASSERT_EQ(
1773 0,
1774 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1775 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1776 int, Kokkos::pair<int, int>, Kokkos::pair<int, int>, int>::value));
1777 ASSERT_EQ(
1778 0,
1779 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1780 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1781 int, Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int>::value));
1782 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1783 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1784 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t,
1785 Kokkos::pair<int, int>, int>::value));
1786 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1787 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1788 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t,
1789 Kokkos::Impl::ALL_t, int>::value));
1790 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1791 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1792 Kokkos::pair<int, int>, int, Kokkos::pair<int, int>,
1793 Kokkos::pair<int, int>, int>::value));
1794 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1795 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1796 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t,
1797 Kokkos::pair<int, int>, int>::value));
1798
1799 ASSERT_EQ(
1800 0,
1801 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1802 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1803 Kokkos::Impl::ALL_t, int, Kokkos::pair<int, int>, int>::value));
1804 ASSERT_EQ(
1805 0,
1806 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1807 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1808 Kokkos::Impl::ALL_t, int, Kokkos::Impl::ALL_t, int>::value));
1809 ASSERT_EQ(
1810 0,
1811 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1812 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1813 Kokkos::pair<int, int>, int, Kokkos::pair<int, int>, int>::value));
1814 ASSERT_EQ(
1815 0,
1816 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1817 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, Kokkos::Impl::ALL_t,
1818 Kokkos::pair<int, int>, int, Kokkos::Impl::ALL_t, int>::value));
1819 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1820 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1821 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1822 Kokkos::pair<int, int>, int>::value));
1823 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1824 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1825 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1826 Kokkos::Impl::ALL_t, int>::value));
1827 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1828 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1829 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int,
1830 Kokkos::pair<int, int>, int>::value));
1831 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1832 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0,
1833 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1834 Kokkos::pair<int, int>, int>::value));
1835
1836 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1837 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1838 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1839 Kokkos::pair<int, int>, int>::value));
1840 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1841 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1842 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1843 Kokkos::Impl::ALL_t, int>::value));
1844 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1845 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1846 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1847 Kokkos::pair<int, int>, int>::value));
1848 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1849 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1850 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1851 Kokkos::Impl::ALL_t, int>::value));
1852 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1853 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1854 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1855 Kokkos::pair<int, int>, int>::value));
1856 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1857 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1858 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1859 Kokkos::Impl::ALL_t, int>::value));
1860 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1861 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1862 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1863 Kokkos::pair<int, int>, int>::value));
1864 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1865 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1866 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1867 Kokkos::Impl::ALL_t, int>::value));
1868
1869 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1870 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1871 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int,
1872 Kokkos::pair<int, int>>::value));
1873 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1874 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1875 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t, int,
1876 Kokkos::Impl::ALL_t>::value));
1877 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1878 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1879 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int,
1880 Kokkos::pair<int, int>>::value));
1881 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1882 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1883 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>, int,
1884 Kokkos::Impl::ALL_t>::value));
1885 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1886 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1887 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1888 Kokkos::pair<int, int>>::value));
1889 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1890 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1891 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t, int,
1892 Kokkos::Impl::ALL_t>::value));
1893 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1894 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1895 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int,
1896 Kokkos::pair<int, int>>::value));
1897 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1898 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int,
1899 Kokkos::pair<int, int>, Kokkos::pair<int, int>, int,
1900 Kokkos::Impl::ALL_t>::value));
1901
1902 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1903 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1904 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1905 Kokkos::pair<int, int>>::value));
1906 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1907 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1908 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t,
1909 Kokkos::Impl::ALL_t>::value));
1910 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1911 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1912 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1913 Kokkos::pair<int, int>>::value));
1914 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1915 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1916 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>,
1917 Kokkos::Impl::ALL_t>::value));
1918 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1919 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1920 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1921 Kokkos::pair<int, int>>::value));
1922 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1923 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1924 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1925 Kokkos::Impl::ALL_t>::value));
1926 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1927 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1928 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1929 Kokkos::pair<int, int>>::value));
1930 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1931 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 5, 0, int, int,
1932 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1933 Kokkos::Impl::ALL_t>::value));
1934
1935 ASSERT_EQ(
1936 1,
1937 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1938 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0, Kokkos::Impl::ALL_t,
1939 Kokkos::Impl::ALL_t, Kokkos::pair<int, int>>::value));
1940 ASSERT_EQ(
1941 1,
1942 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1943 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0, Kokkos::Impl::ALL_t,
1944 Kokkos::Impl::ALL_t, Kokkos::Impl::ALL_t>::value));
1945 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1946 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0,
1947 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1948 Kokkos::pair<int, int>>::value));
1949 ASSERT_EQ(1, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1950 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0,
1951 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t,
1952 Kokkos::Impl::ALL_t>::value));
1953 ASSERT_EQ(
1954 0,
1955 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1956 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0, Kokkos::Impl::ALL_t,
1957 Kokkos::pair<int, int>, Kokkos::Impl::ALL_t>::value));
1958 ASSERT_EQ(
1959 0,
1960 (Kokkos::Impl::SubviewLegalArgsCompileTime<
1961 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0, Kokkos::Impl::ALL_t,
1962 Kokkos::pair<int, int>, Kokkos::pair<int, int>>::value));
1963 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1964 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0,
1965 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1966 Kokkos::Impl::ALL_t>::value));
1967 ASSERT_EQ(0, (Kokkos::Impl::SubviewLegalArgsCompileTime<
1968 Kokkos::LayoutLeft, Kokkos::LayoutLeft, 3, 3, 0,
1969 Kokkos::pair<int, int>, Kokkos::pair<int, int>,
1970 Kokkos::pair<int, int>>::value));
1971 }
1972
1973 } // namespace Impl
1974
1975 template <class Space, class MemTraits = void>
test_1d_assign()1976 void test_1d_assign() {
1977 Impl::test_1d_assign_impl<Space, Kokkos::LayoutLeft, Kokkos::LayoutLeft,
1978 Kokkos::LayoutLeft, MemTraits>();
1979 // Impl::test_1d_assign_impl< Space, Kokkos::LayoutRight, Kokkos::LayoutLeft,
1980 // Kokkos::LayoutLeft >();
1981 Impl::test_1d_assign_impl<Space, Kokkos::LayoutStride, Kokkos::LayoutLeft,
1982 Kokkos::LayoutLeft, MemTraits>();
1983 // Impl::test_1d_assign_impl< Space, Kokkos::LayoutLeft, Kokkos::LayoutRight,
1984 // Kokkos::LayoutLeft >();
1985 Impl::test_1d_assign_impl<Space, Kokkos::LayoutRight, Kokkos::LayoutRight,
1986 Kokkos::LayoutRight, MemTraits>();
1987 Impl::test_1d_assign_impl<Space, Kokkos::LayoutStride, Kokkos::LayoutRight,
1988 Kokkos::LayoutRight, MemTraits>();
1989 // Impl::test_1d_assign_impl< Space, Kokkos::LayoutLeft, Kokkos::LayoutStride,
1990 // Kokkos::LayoutLeft >(); Impl::test_1d_assign_impl< Space,
1991 // Kokkos::LayoutRight, Kokkos::LayoutStride, Kokkos::LayoutLeft >();
1992 Impl::test_1d_assign_impl<Space, Kokkos::LayoutStride, Kokkos::LayoutStride,
1993 Kokkos::LayoutLeft, MemTraits>();
1994 }
1995
1996 template <class Space, class MemTraits = void>
test_2d_subview_3d()1997 void test_2d_subview_3d() {
1998 Impl::test_2d_subview_3d_impl_layout<Space, Kokkos::LayoutRight,
1999 Kokkos::LayoutRight, Kokkos::LayoutRight,
2000 MemTraits>();
2001 Impl::test_2d_subview_3d_impl_layout<Space, Kokkos::LayoutStride,
2002 Kokkos::LayoutRight, Kokkos::LayoutRight,
2003 MemTraits>();
2004 Impl::test_2d_subview_3d_impl_layout<Space, Kokkos::LayoutStride,
2005 Kokkos::LayoutStride,
2006 Kokkos::LayoutRight, MemTraits>();
2007 Impl::test_2d_subview_3d_impl_layout<Space, Kokkos::LayoutStride,
2008 Kokkos::LayoutLeft, Kokkos::LayoutLeft,
2009 MemTraits>();
2010 Impl::test_2d_subview_3d_impl_layout<Space, Kokkos::LayoutStride,
2011 Kokkos::LayoutStride, Kokkos::LayoutLeft,
2012 MemTraits>();
2013 }
2014
2015 template <class Space, class MemTraits = void>
test_3d_subview_5d_right()2016 void test_3d_subview_5d_right() {
2017 Impl::test_3d_subview_5d_impl_layout<Space, Kokkos::LayoutStride,
2018 Kokkos::LayoutRight, Kokkos::LayoutRight,
2019 MemTraits>();
2020 Impl::test_3d_subview_5d_impl_layout<Space, Kokkos::LayoutStride,
2021 Kokkos::LayoutStride,
2022 Kokkos::LayoutRight, MemTraits>();
2023 }
2024
2025 template <class Space, class MemTraits = void>
test_3d_subview_5d_left()2026 void test_3d_subview_5d_left() {
2027 Impl::test_3d_subview_5d_impl_layout<Space, Kokkos::LayoutStride,
2028 Kokkos::LayoutLeft, Kokkos::LayoutLeft,
2029 MemTraits>();
2030 Impl::test_3d_subview_5d_impl_layout<Space, Kokkos::LayoutStride,
2031 Kokkos::LayoutStride, Kokkos::LayoutLeft,
2032 MemTraits>();
2033 }
2034
2035 template <class Space, class MemTraits = void>
test_layoutleft_to_layoutleft()2036 void test_layoutleft_to_layoutleft() {
2037 Impl::test_subview_legal_args_left();
2038
2039 using view3D_t = Kokkos::View<int***, Kokkos::LayoutLeft, Space>;
2040 using view4D_t = Kokkos::View<int****, Kokkos::LayoutLeft, Space>;
2041 {
2042 view3D_t a("A", 100, 4, 3);
2043 view3D_t b(a, Kokkos::pair<int, int>(16, 32), Kokkos::ALL, Kokkos::ALL);
2044
2045 Impl::FillView_3D<Kokkos::LayoutLeft, Space> fill(a);
2046 fill.run();
2047
2048 Impl::CheckSubviewCorrectness_3D_3D<view3D_t, view3D_t> check(a, b, 16, 0);
2049 check.run();
2050 }
2051
2052 {
2053 view3D_t a("A", 100, 4, 5);
2054 view3D_t b(a, Kokkos::pair<int, int>(16, 32), Kokkos::ALL,
2055 Kokkos::pair<int, int>(1, 3));
2056
2057 Impl::FillView_3D<Kokkos::LayoutLeft, Space> fill(a);
2058 fill.run();
2059
2060 Impl::CheckSubviewCorrectness_3D_3D<view3D_t, view3D_t> check(a, b, 16, 1);
2061 check.run();
2062 }
2063
2064 {
2065 view4D_t a("A", 100, 4, 5, 3);
2066 view3D_t b(a, Kokkos::pair<int, int>(16, 32), Kokkos::ALL,
2067 Kokkos::pair<int, int>(1, 3), 1);
2068
2069 Impl::FillView_4D<Kokkos::LayoutLeft, Space> fill(a);
2070 fill.run();
2071
2072 Impl::CheckSubviewCorrectness_3D_4D<view4D_t, view3D_t> check(a, b, 1, 16,
2073 1);
2074 check.run();
2075 }
2076 }
2077
2078 template <class Space, class MemTraits = void>
test_layoutright_to_layoutright()2079 void test_layoutright_to_layoutright() {
2080 Impl::test_subview_legal_args_right();
2081
2082 using view3D_t = Kokkos::View<int***, Kokkos::LayoutRight, Space>;
2083 using view4D_t = Kokkos::View<int****, Kokkos::LayoutRight, Space>;
2084 {
2085 view3D_t a("A", 100, 4, 3);
2086 view3D_t b(a, Kokkos::pair<int, int>(16, 32), Kokkos::ALL, Kokkos::ALL);
2087
2088 Impl::FillView_3D<Kokkos::LayoutRight, Space> fill(a);
2089 fill.run();
2090
2091 Impl::CheckSubviewCorrectness_3D_3D<view3D_t, view3D_t> check(a, b, 16, 0);
2092 check.run();
2093 }
2094 {
2095 view4D_t a("A", 3, 4, 5, 100);
2096 view3D_t b(a, 1, Kokkos::pair<int, int>(1, 3), Kokkos::ALL, Kokkos::ALL);
2097
2098 Impl::FillView_4D<Kokkos::LayoutRight, Space> fill(a);
2099 fill.run();
2100
2101 Impl::CheckSubviewCorrectness_3D_4D<view4D_t, view3D_t> check(a, b, 1, 1,
2102 0);
2103 check.run();
2104 }
2105 }
2106 //----------------------------------------------------------------------------
2107
2108 template <class Space>
2109 struct TestUnmanagedSubviewReset {
2110 Kokkos::View<int****, Space> a;
2111
2112 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::TestUnmanagedSubviewReset2113 void operator()(int) const noexcept {
2114 auto sub_a = Kokkos::subview(a, 0, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL);
2115
2116 for (int i = 0; i < int(a.extent(0)); ++i) {
2117 sub_a.assign_data(&a(i, 0, 0, 0));
2118 if (&sub_a(1, 1, 1) != &a(i, 1, 1, 1)) {
2119 Kokkos::abort("TestUnmanagedSubviewReset");
2120 }
2121 }
2122 }
2123
TestUnmanagedSubviewResetTestViewSubview::TestUnmanagedSubviewReset2124 TestUnmanagedSubviewReset() : a(Kokkos::view_alloc(), 20, 10, 5, 2) {}
2125 };
2126
2127 template <class Space>
test_unmanaged_subview_reset()2128 void test_unmanaged_subview_reset() {
2129 Kokkos::parallel_for(
2130 Kokkos::RangePolicy<typename Space::execution_space>(0, 1),
2131 TestUnmanagedSubviewReset<Space>());
2132 }
2133
2134 //----------------------------------------------------------------------------
2135
2136 template <std::underlying_type_t<Kokkos::MemoryTraitsFlags> MTF>
2137 struct TestSubviewMemoryTraitsConstruction {
operator ()TestViewSubview::TestSubviewMemoryTraitsConstruction2138 void operator()() const noexcept {
2139 using view_type = Kokkos::View<double*, Kokkos::HostSpace>;
2140 using size_type = view_type::size_type;
2141 using memory_traits_type = Kokkos::MemoryTraits<MTF>;
2142
2143 view_type v("v", 7);
2144 for (size_type i = 0; i != v.size(); ++i) v[i] = static_cast<double>(i);
2145
2146 std::pair<int, int> range(3, 5);
2147 auto sv = Kokkos::subview<memory_traits_type>(v, range);
2148
2149 ASSERT_EQ(2u, sv.size());
2150 EXPECT_EQ(3., sv[0]);
2151 EXPECT_EQ(4., sv[1]);
2152 }
2153 };
2154
test_subview_memory_traits_construction()2155 inline void test_subview_memory_traits_construction() {
2156 // Test all combinations of MemoryTraits:
2157 // Unmanaged (1)
2158 // RandomAccess (2)
2159 // Atomic (4)
2160 // Restricted (8)
2161 TestSubviewMemoryTraitsConstruction<0>()();
2162 TestSubviewMemoryTraitsConstruction<1>()();
2163 TestSubviewMemoryTraitsConstruction<2>()();
2164 TestSubviewMemoryTraitsConstruction<3>()();
2165 TestSubviewMemoryTraitsConstruction<4>()();
2166 TestSubviewMemoryTraitsConstruction<5>()();
2167 TestSubviewMemoryTraitsConstruction<6>()();
2168 TestSubviewMemoryTraitsConstruction<7>()();
2169 TestSubviewMemoryTraitsConstruction<8>()();
2170 TestSubviewMemoryTraitsConstruction<9>()();
2171 TestSubviewMemoryTraitsConstruction<10>()();
2172 TestSubviewMemoryTraitsConstruction<11>()();
2173 TestSubviewMemoryTraitsConstruction<12>()();
2174 TestSubviewMemoryTraitsConstruction<13>()();
2175 TestSubviewMemoryTraitsConstruction<14>()();
2176 TestSubviewMemoryTraitsConstruction<15>()();
2177 }
2178
2179 //----------------------------------------------------------------------------
2180
2181 template <class T>
2182 struct get_view_type;
2183
2184 template <class T, class... Args>
2185 struct get_view_type<Kokkos::View<T, Args...>> {
2186 using type = T;
2187 };
2188
2189 template <class T>
2190 struct
2191 ___________________________________TYPE_DISPLAY________________________________________;
2192 #define TYPE_DISPLAY(...) \
2193 typename ___________________________________TYPE_DISPLAY________________________________________< \
2194 __VA_ARGS__>::type notdefined;
2195
2196 template <class Space, class Layout>
2197 struct TestSubviewStaticSizes {
2198 Kokkos::View<int * [10][5][2], Layout, Space> a;
2199 Kokkos::View<int[6][7][8], Layout, Space> b;
2200
2201 KOKKOS_INLINE_FUNCTION
operator ()TestViewSubview::TestSubviewStaticSizes2202 int operator()() const noexcept {
2203 /* Doesn't actually do anything; just static assertions */
2204
2205 auto sub_a = Kokkos::subview(a, 0, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL);
2206 typename static_expect_same<
2207 /* expected */ int[10][5][2],
2208 /* actual */ typename get_view_type<decltype(sub_a)>::type>::type
2209 test_1 = 0;
2210
2211 auto sub_a_2 = Kokkos::subview(a, 0, 0, Kokkos::ALL, Kokkos::ALL);
2212 typename static_expect_same<
2213 /* expected */ int[5][2],
2214 /* actual */ typename get_view_type<decltype(sub_a_2)>::type>::type
2215 test_2 = 0;
2216
2217 auto sub_a_3 = Kokkos::subview(a, 0, 0, Kokkos::ALL, 0);
2218 typename static_expect_same<
2219 /* expected */ int[5],
2220 /* actual */ typename get_view_type<decltype(sub_a_3)>::type>::type
2221 test_3 = 0;
2222
2223 auto sub_a_4 = Kokkos::subview(a, Kokkos::ALL, 0, Kokkos::ALL, Kokkos::ALL);
2224 typename static_expect_same<
2225 /* expected */ int * [5][2],
2226 /* actual */ typename get_view_type<decltype(sub_a_4)>::type>::type
2227 test_4 = 0;
2228
2229 // TODO we'll need to update this test once we allow interleaving of static
2230 // and dynamic
2231 auto sub_a_5 = Kokkos::subview(a, Kokkos::ALL, 0, Kokkos::ALL,
2232 Kokkos::make_pair(0, 1));
2233 typename static_expect_same<
2234 /* expected */ int***,
2235 /* actual */ typename get_view_type<decltype(sub_a_5)>::type>::type
2236 test_5 = 0;
2237
2238 auto sub_a_sub = Kokkos::subview(sub_a_5, 0, Kokkos::ALL, 0);
2239 typename static_expect_same<
2240 /* expected */ int*,
2241 /* actual */ typename get_view_type<decltype(sub_a_sub)>::type>::type
2242 test_sub = 0;
2243
2244 auto sub_a_7 = Kokkos::subview(a, Kokkos::ALL, 0, Kokkos::make_pair(0, 1),
2245 Kokkos::ALL);
2246 typename static_expect_same<
2247 /* expected */ int* * [2],
2248 /* actual */ typename get_view_type<decltype(sub_a_7)>::type>::type
2249 test_7 = 0;
2250
2251 auto sub_a_8 =
2252 Kokkos::subview(a, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL);
2253 typename static_expect_same<
2254 /* expected */ int * [10][5][2],
2255 /* actual */ typename get_view_type<decltype(sub_a_8)>::type>::type
2256 test_8 = 0;
2257
2258 auto sub_b = Kokkos::subview(b, Kokkos::ALL, Kokkos::ALL, Kokkos::ALL);
2259 typename static_expect_same<
2260 /* expected */ int[6][7][8],
2261 /* actual */ typename get_view_type<decltype(sub_b)>::type>::type
2262 test_9 = 0;
2263
2264 auto sub_b_2 = Kokkos::subview(b, 0, Kokkos::ALL, Kokkos::ALL);
2265 typename static_expect_same<
2266 /* expected */ int[7][8],
2267 /* actual */ typename get_view_type<decltype(sub_b_2)>::type>::type
2268 test_10 = 0;
2269
2270 auto sub_b_3 =
2271 Kokkos::subview(b, Kokkos::make_pair(2, 3), Kokkos::ALL, Kokkos::ALL);
2272 typename static_expect_same<
2273 /* expected */ int * [7][8],
2274 /* actual */ typename get_view_type<decltype(sub_b_3)>::type>::type
2275 test_11 = 0;
2276
2277 return test_1 + test_2 + test_3 + test_4 + test_5 + test_sub + test_7 +
2278 test_8 + test_9 + test_10 + test_11;
2279 }
2280
TestSubviewStaticSizesTestViewSubview::TestSubviewStaticSizes2281 TestSubviewStaticSizes() : a(Kokkos::view_alloc("a"), 20), b("b") {}
2282 };
2283
2284 template <class Space>
2285 struct TestExtentsStaticTests {
2286 using test1 = typename static_expect_same<
2287 /* expected */
2288 Kokkos::Experimental::Extents<Kokkos::Experimental::dynamic_extent,
2289 Kokkos::Experimental::dynamic_extent, 1, 2,
2290 3>,
2291 /* actual */
2292 typename Kokkos::Impl::ParseViewExtents<double* * [1][2][3]>::type>::type;
2293
2294 using test2 = typename static_expect_same<
2295 /* expected */
2296 Kokkos::Experimental::Extents<1, 2, 3>,
2297 /* actual */
2298 typename Kokkos::Impl::ParseViewExtents<double[1][2][3]>::type>::type;
2299
2300 using test3 = typename static_expect_same<
2301 /* expected */
2302 Kokkos::Experimental::Extents<3>,
2303 /* actual */
2304 typename Kokkos::Impl::ParseViewExtents<double[3]>::type>::type;
2305
2306 using test4 = typename static_expect_same<
2307 /* expected */
2308 Kokkos::Experimental::Extents<>,
2309 /* actual */
2310 typename Kokkos::Impl::ParseViewExtents<double>::type>::type;
2311 };
2312
2313 } // namespace TestViewSubview
2314
2315 #endif
2316