/* //@HEADER // ************************************************************************ // // Kokkos v. 2.0 // Copyright (2014) Sandia Corporation // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // 3. Neither the name of the Corporation nor the names of the // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov) // // ************************************************************************ //@HEADER */ #include #include #include #include #include /*--------------------------------------------------------------------------*/ namespace TestViewSubview { template struct getView { static Kokkos::View get(int n, int m) { return Kokkos::View("G",n,m); } }; template struct getView { static Kokkos::View get(int n, int m) { const int rank = 2 ; const int order[] = { 0, 1 }; const unsigned dim[] = { unsigned(n), unsigned(m) }; Kokkos::LayoutStride stride = Kokkos::LayoutStride::order_dimensions( rank , order , dim ); return Kokkos::View("G",stride); } }; template struct fill_1D { typedef typename Space::execution_space execution_space; typedef typename ViewType::size_type size_type; ViewType a; double val; fill_1D(ViewType a_, double val_):a(a_),val(val_) { } KOKKOS_INLINE_FUNCTION void operator() (const int i) const { a(i) = val; } }; template struct fill_2D { typedef typename Space::execution_space execution_space; typedef typename ViewType::size_type size_type; ViewType a; double val; fill_2D(ViewType a_, double val_):a(a_),val(val_) { } KOKKOS_INLINE_FUNCTION void operator() (const int i) const{ for(int j = 0; j < static_cast(a.dimension_1()); j++) a(i,j) = val; } }; template void test_auto_1d () { typedef Kokkos::View mv_type; typedef typename mv_type::size_type size_type; const double ZERO = 0.0; const double ONE = 1.0; const double TWO = 2.0; const size_type numRows = 10; const size_type numCols = 3; mv_type X = getView::get(numRows, numCols); typename mv_type::HostMirror X_h = Kokkos::create_mirror_view (X); fill_2D f1(X, ONE); Kokkos::parallel_for(X.dimension_0(),f1); Kokkos::deep_copy (X_h, X); for (size_type j = 0; j < numCols; ++j) { for (size_type i = 0; i < numRows; ++i) { ASSERT_TRUE(X_h(i,j) == ONE); } } fill_2D f2(X, 0.0); Kokkos::parallel_for(X.dimension_0(),f2); Kokkos::deep_copy (X_h, X); for (size_type j = 0; j < numCols; ++j) { for (size_type i = 0; i < numRows; ++i) { ASSERT_TRUE(X_h(i,j) == ZERO); } } fill_2D f3(X, TWO); Kokkos::parallel_for(X.dimension_0(),f3); Kokkos::deep_copy (X_h, X); for (size_type j = 0; j < numCols; ++j) { for (size_type i = 0; i < numRows; ++i) { ASSERT_TRUE(X_h(i,j) == TWO); } } for (size_type j = 0; j < numCols; ++j) { auto X_j = Kokkos::subview (X, Kokkos::ALL(), j); fill_1D f4(X_j, ZERO); Kokkos::parallel_for(X_j.dimension_0(),f4); Kokkos::deep_copy (X_h, X); for (size_type i = 0; i < numRows; ++i) { ASSERT_TRUE(X_h(i,j) == ZERO); } for (size_type jj = 0; jj < numCols; ++jj) { auto X_jj = Kokkos::subview (X, Kokkos::ALL(), jj); fill_1D f5(X_jj, ONE); Kokkos::parallel_for(X_jj.dimension_0(),f5); Kokkos::deep_copy (X_h, X); for (size_type i = 0; i < numRows; ++i) { ASSERT_TRUE(X_h(i,jj) == ONE); } } } } template void test_1d_strided_assignment_impl(bool a, bool b, bool c, bool d, int n, int m) { Kokkos::View l2d("l2d",n,m); int col = n>2?2:0; int row = m>2?2:0; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { if(a) { Kokkos::View l1da = Kokkos::subview(l2d,Kokkos::ALL(),row); ASSERT_TRUE( & l1da(0) == & l2d(0,row) ); if(n>1) ASSERT_TRUE( & l1da(1) == & l2d(1,row) ); } if(b && n>13) { Kokkos::View l1db = Kokkos::subview(l2d,std::pair(2,13),row); ASSERT_TRUE( & l1db(0) == & l2d(2,row) ); ASSERT_TRUE( & l1db(1) == & l2d(3,row) ); } if(c) { Kokkos::View l1dc = Kokkos::subview(l2d,col,Kokkos::ALL()); ASSERT_TRUE( & l1dc(0) == & l2d(col,0) ); if(m>1) ASSERT_TRUE( & l1dc(1) == & l2d(col,1) ); } if(d && m>13) { Kokkos::View l1dd = Kokkos::subview(l2d,col,std::pair(2,13)); ASSERT_TRUE( & l1dd(0) == & l2d(col,2) ); ASSERT_TRUE( & l1dd(1) == & l2d(col,3) ); } } } template void test_1d_strided_assignment() { test_1d_strided_assignment_impl(true,true,true,true,17,3); test_1d_strided_assignment_impl(true,true,true,true,17,3); test_1d_strided_assignment_impl(true,true,false,false,17,3); test_1d_strided_assignment_impl(true,true,false,false,17,3); test_1d_strided_assignment_impl(false,false,true,true,17,3); test_1d_strided_assignment_impl(false,false,true,true,17,3); test_1d_strided_assignment_impl(true,true,false,false,17,1); test_1d_strided_assignment_impl(true,true,true,true,1,17); test_1d_strided_assignment_impl(true,true,true,true,1,17); test_1d_strided_assignment_impl(true,true,false,false,17,1); test_1d_strided_assignment_impl(true,true,true,true,17,1); test_1d_strided_assignment_impl(false,false,true,true,1,17); test_1d_strided_assignment_impl(false,false,true,true,1,17); test_1d_strided_assignment_impl(true,true,true,true,17,1); } template< class Space > void test_left_0() { typedef Kokkos::View< int [2][3][4][5][2][3][4][5] , Kokkos::LayoutLeft , Space > view_static_8_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_static_8_type x_static_8("x_static_left_8"); ASSERT_TRUE( x_static_8.is_contiguous() ); Kokkos::View x0 = Kokkos::subview( x_static_8 , 0, 0, 0, 0, 0, 0, 0, 0 ); ASSERT_TRUE( x0.is_contiguous() ); ASSERT_TRUE( & x0() == & x_static_8(0,0,0,0,0,0,0,0) ); Kokkos::View x1 = Kokkos::subview( x_static_8, Kokkos::pair(0,2), 1, 2, 3, 0, 1, 2, 3 ); ASSERT_TRUE( x1.is_contiguous() ); ASSERT_TRUE( & x1(0) == & x_static_8(0,1,2,3,0,1,2,3) ); ASSERT_TRUE( & x1(1) == & x_static_8(1,1,2,3,0,1,2,3) ); Kokkos::View x2 = Kokkos::subview( x_static_8, Kokkos::pair(0,2), 1, 2, 3 , Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( ! x2.is_contiguous() ); ASSERT_TRUE( & x2(0,0) == & x_static_8(0,1,2,3,0,1,2,3) ); ASSERT_TRUE( & x2(1,0) == & x_static_8(1,1,2,3,0,1,2,3) ); ASSERT_TRUE( & x2(0,1) == & x_static_8(0,1,2,3,1,1,2,3) ); ASSERT_TRUE( & x2(1,1) == & x_static_8(1,1,2,3,1,1,2,3) ); // Kokkos::View error_2 = Kokkos::View sx2 = Kokkos::subview( x_static_8, 1, Kokkos::pair(0,2), 2, 3 , Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( ! sx2.is_contiguous() ); ASSERT_TRUE( & sx2(0,0) == & x_static_8(1,0,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(1,0) == & x_static_8(1,1,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(0,1) == & x_static_8(1,0,2,3,1,1,2,3) ); ASSERT_TRUE( & sx2(1,1) == & x_static_8(1,1,2,3,1,1,2,3) ); Kokkos::View sx4 = Kokkos::subview( x_static_8, 0, Kokkos::pair(0,2) /* of [3] */ , 1, Kokkos::pair(1,3) /* of [5] */ , 1, Kokkos::pair(0,2) /* of [3] */ , 2, Kokkos::pair(2,4) /* of [5] */ ); ASSERT_TRUE( ! sx4.is_contiguous() ); for ( int i0 = 0 ; i0 < (int) sx4.dimension_0() ; ++i0 ) for ( int i1 = 0 ; i1 < (int) sx4.dimension_1() ; ++i1 ) for ( int i2 = 0 ; i2 < (int) sx4.dimension_2() ; ++i2 ) for ( int i3 = 0 ; i3 < (int) sx4.dimension_3() ; ++i3 ) { ASSERT_TRUE( & sx4(i0,i1,i2,i3) == & x_static_8(0,0+i0, 1,1+i1, 1,0+i2, 2,2+i3) ); } } } template< class Space > void test_left_1() { typedef Kokkos::View< int ****[2][3][4][5] , Kokkos::LayoutLeft , Space > view_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_type x8("x_left_8",2,3,4,5); ASSERT_TRUE( x8.is_contiguous() ); Kokkos::View x0 = Kokkos::subview( x8 , 0, 0, 0, 0, 0, 0, 0, 0 ); ASSERT_TRUE( x0.is_contiguous() ); ASSERT_TRUE( & x0() == & x8(0,0,0,0,0,0,0,0) ); Kokkos::View x1 = Kokkos::subview( x8, Kokkos::pair(0,2), 1, 2, 3, 0, 1, 2, 3 ); ASSERT_TRUE( x1.is_contiguous() ); ASSERT_TRUE( & x1(0) == & x8(0,1,2,3,0,1,2,3) ); ASSERT_TRUE( & x1(1) == & x8(1,1,2,3,0,1,2,3) ); Kokkos::View x2 = Kokkos::subview( x8, Kokkos::pair(0,2), 1, 2, 3 , Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( ! x2.is_contiguous() ); ASSERT_TRUE( & x2(0,0) == & x8(0,1,2,3,0,1,2,3) ); ASSERT_TRUE( & x2(1,0) == & x8(1,1,2,3,0,1,2,3) ); ASSERT_TRUE( & x2(0,1) == & x8(0,1,2,3,1,1,2,3) ); ASSERT_TRUE( & x2(1,1) == & x8(1,1,2,3,1,1,2,3) ); // Kokkos::View error_2 = Kokkos::View sx2 = Kokkos::subview( x8, 1, Kokkos::pair(0,2), 2, 3 , Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( ! sx2.is_contiguous() ); ASSERT_TRUE( & sx2(0,0) == & x8(1,0,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(1,0) == & x8(1,1,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(0,1) == & x8(1,0,2,3,1,1,2,3) ); ASSERT_TRUE( & sx2(1,1) == & x8(1,1,2,3,1,1,2,3) ); Kokkos::View sx4 = Kokkos::subview( x8, 0, Kokkos::pair(0,2) /* of [3] */ , 1, Kokkos::pair(1,3) /* of [5] */ , 1, Kokkos::pair(0,2) /* of [3] */ , 2, Kokkos::pair(2,4) /* of [5] */ ); ASSERT_TRUE( ! sx4.is_contiguous() ); for ( int i0 = 0 ; i0 < (int) sx4.dimension_0() ; ++i0 ) for ( int i1 = 0 ; i1 < (int) sx4.dimension_1() ; ++i1 ) for ( int i2 = 0 ; i2 < (int) sx4.dimension_2() ; ++i2 ) for ( int i3 = 0 ; i3 < (int) sx4.dimension_3() ; ++i3 ) { ASSERT_TRUE( & sx4(i0,i1,i2,i3) == & x8(0,0+i0, 1,1+i1, 1,0+i2, 2,2+i3) ); } } } template< class Space > void test_left_2() { typedef Kokkos::View< int **** , Kokkos::LayoutLeft , Space > view_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_type x4("x4",2,3,4,5); ASSERT_TRUE( x4.is_contiguous() ); Kokkos::View x0 = Kokkos::subview( x4 , 0, 0, 0, 0 ); ASSERT_TRUE( x0.is_contiguous() ); ASSERT_TRUE( & x0() == & x4(0,0,0,0) ); Kokkos::View x1 = Kokkos::subview( x4, Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( x1.is_contiguous() ); ASSERT_TRUE( & x1(0) == & x4(0,1,2,3) ); ASSERT_TRUE( & x1(1) == & x4(1,1,2,3) ); Kokkos::View x2 = Kokkos::subview( x4, Kokkos::pair(0,2), 1, Kokkos::pair(1,3), 2 ); ASSERT_TRUE( ! x2.is_contiguous() ); ASSERT_TRUE( & x2(0,0) == & x4(0,1,1,2) ); ASSERT_TRUE( & x2(1,0) == & x4(1,1,1,2) ); ASSERT_TRUE( & x2(0,1) == & x4(0,1,2,2) ); ASSERT_TRUE( & x2(1,1) == & x4(1,1,2,2) ); // Kokkos::View error_2 = Kokkos::View sx2 = Kokkos::subview( x4, 1, Kokkos::pair(0,2) , 2, Kokkos::pair(1,4) ); ASSERT_TRUE( ! sx2.is_contiguous() ); ASSERT_TRUE( & sx2(0,0) == & x4(1,0,2,1) ); ASSERT_TRUE( & sx2(1,0) == & x4(1,1,2,1) ); ASSERT_TRUE( & sx2(0,1) == & x4(1,0,2,2) ); ASSERT_TRUE( & sx2(1,1) == & x4(1,1,2,2) ); ASSERT_TRUE( & sx2(0,2) == & x4(1,0,2,3) ); ASSERT_TRUE( & sx2(1,2) == & x4(1,1,2,3) ); Kokkos::View sx4 = Kokkos::subview( x4, Kokkos::pair(1,2) /* of [2] */ , Kokkos::pair(1,3) /* of [3] */ , Kokkos::pair(0,4) /* of [4] */ , Kokkos::pair(2,4) /* of [5] */ ); ASSERT_TRUE( ! sx4.is_contiguous() ); for ( int i0 = 0 ; i0 < (int) sx4.dimension_0() ; ++i0 ) for ( int i1 = 0 ; i1 < (int) sx4.dimension_1() ; ++i1 ) for ( int i2 = 0 ; i2 < (int) sx4.dimension_2() ; ++i2 ) for ( int i3 = 0 ; i3 < (int) sx4.dimension_3() ; ++i3 ) { ASSERT_TRUE( & sx4(i0,i1,i2,i3) == & x4( 1+i0, 1+i1, 0+i2, 2+i3 ) ); } } } template< class Space > void test_left_3() { typedef Kokkos::View< int ** , Kokkos::LayoutLeft , Space > view_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_type xm("x4",10,5); ASSERT_TRUE( xm.is_contiguous() ); Kokkos::View x0 = Kokkos::subview( xm , 5, 3 ); ASSERT_TRUE( x0.is_contiguous() ); ASSERT_TRUE( & x0() == & xm(5,3) ); Kokkos::View x1 = Kokkos::subview( xm, Kokkos::ALL(), 3 ); ASSERT_TRUE( x1.is_contiguous() ); for ( int i = 0 ; i < int(xm.dimension_0()) ; ++i ) { ASSERT_TRUE( & x1(i) == & xm(i,3) ); } Kokkos::View x2 = Kokkos::subview( xm, Kokkos::pair(1,9), Kokkos::ALL() ); ASSERT_TRUE( ! x2.is_contiguous() ); for ( int j = 0 ; j < int(x2.dimension_1()) ; ++j ) for ( int i = 0 ; i < int(x2.dimension_0()) ; ++i ) { ASSERT_TRUE( & x2(i,j) == & xm(1+i,j) ); } Kokkos::View x2c = Kokkos::subview( xm, Kokkos::ALL(), std::pair(2,4) ); ASSERT_TRUE( x2c.is_contiguous() ); for ( int j = 0 ; j < int(x2c.dimension_1()) ; ++j ) for ( int i = 0 ; i < int(x2c.dimension_0()) ; ++i ) { ASSERT_TRUE( & x2c(i,j) == & xm(i,2+j) ); } Kokkos::View x2_n1 = Kokkos::subview( xm , std::pair(1,1) , Kokkos::ALL() ); ASSERT_TRUE( x2_n1.dimension_0() == 0 ); ASSERT_TRUE( x2_n1.dimension_1() == xm.dimension_1() ); Kokkos::View x2_n2 = Kokkos::subview( xm , Kokkos::ALL() , std::pair(1,1) ); ASSERT_TRUE( x2_n2.dimension_0() == xm.dimension_0() ); ASSERT_TRUE( x2_n2.dimension_1() == 0 ); } } //---------------------------------------------------------------------------- template< class Space > void test_right_0() { typedef Kokkos::View< int [2][3][4][5][2][3][4][5] , Kokkos::LayoutRight , Space > view_static_8_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_static_8_type x_static_8("x_static_right_8"); Kokkos::View x0 = Kokkos::subview( x_static_8 , 0, 0, 0, 0, 0, 0, 0, 0 ); ASSERT_TRUE( & x0() == & x_static_8(0,0,0,0,0,0,0,0) ); Kokkos::View x1 = Kokkos::subview( x_static_8, 0, 1, 2, 3, 0, 1, 2, Kokkos::pair(1,3) ); ASSERT_TRUE( x1.dimension_0() == 2 ); ASSERT_TRUE( & x1(0) == & x_static_8(0,1,2,3,0,1,2,1) ); ASSERT_TRUE( & x1(1) == & x_static_8(0,1,2,3,0,1,2,2) ); Kokkos::View x2 = Kokkos::subview( x_static_8, 0, 1, 2, Kokkos::pair(1,3) , 0, 1, 2, Kokkos::pair(1,3) ); ASSERT_TRUE( x2.dimension_0() == 2 ); ASSERT_TRUE( x2.dimension_1() == 2 ); ASSERT_TRUE( & x2(0,0) == & x_static_8(0,1,2,1,0,1,2,1) ); ASSERT_TRUE( & x2(1,0) == & x_static_8(0,1,2,2,0,1,2,1) ); ASSERT_TRUE( & x2(0,1) == & x_static_8(0,1,2,1,0,1,2,2) ); ASSERT_TRUE( & x2(1,1) == & x_static_8(0,1,2,2,0,1,2,2) ); // Kokkos::View error_2 = Kokkos::View sx2 = Kokkos::subview( x_static_8, 1, Kokkos::pair(0,2), 2, 3 , Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( sx2.dimension_0() == 2 ); ASSERT_TRUE( sx2.dimension_1() == 2 ); ASSERT_TRUE( & sx2(0,0) == & x_static_8(1,0,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(1,0) == & x_static_8(1,1,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(0,1) == & x_static_8(1,0,2,3,1,1,2,3) ); ASSERT_TRUE( & sx2(1,1) == & x_static_8(1,1,2,3,1,1,2,3) ); Kokkos::View sx4 = Kokkos::subview( x_static_8, 0, Kokkos::pair(0,2) /* of [3] */ , 1, Kokkos::pair(1,3) /* of [5] */ , 1, Kokkos::pair(0,2) /* of [3] */ , 2, Kokkos::pair(2,4) /* of [5] */ ); ASSERT_TRUE( sx4.dimension_0() == 2 ); ASSERT_TRUE( sx4.dimension_1() == 2 ); ASSERT_TRUE( sx4.dimension_2() == 2 ); ASSERT_TRUE( sx4.dimension_3() == 2 ); for ( int i0 = 0 ; i0 < (int) sx4.dimension_0() ; ++i0 ) for ( int i1 = 0 ; i1 < (int) sx4.dimension_1() ; ++i1 ) for ( int i2 = 0 ; i2 < (int) sx4.dimension_2() ; ++i2 ) for ( int i3 = 0 ; i3 < (int) sx4.dimension_3() ; ++i3 ) { ASSERT_TRUE( & sx4(i0,i1,i2,i3) == & x_static_8(0, 0+i0, 1, 1+i1, 1, 0+i2, 2, 2+i3) ); } } } template< class Space > void test_right_1() { typedef Kokkos::View< int ****[2][3][4][5] , Kokkos::LayoutRight , Space > view_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_type x8("x_right_8",2,3,4,5); Kokkos::View x0 = Kokkos::subview( x8 , 0, 0, 0, 0, 0, 0, 0, 0 ); ASSERT_TRUE( & x0() == & x8(0,0,0,0,0,0,0,0) ); Kokkos::View x1 = Kokkos::subview( x8, 0, 1, 2, 3, 0, 1, 2, Kokkos::pair(1,3) ); ASSERT_TRUE( & x1(0) == & x8(0,1,2,3,0,1,2,1) ); ASSERT_TRUE( & x1(1) == & x8(0,1,2,3,0,1,2,2) ); Kokkos::View x2 = Kokkos::subview( x8, 0, 1, 2, Kokkos::pair(1,3) , 0, 1, 2, Kokkos::pair(1,3) ); ASSERT_TRUE( & x2(0,0) == & x8(0,1,2,1,0,1,2,1) ); ASSERT_TRUE( & x2(1,0) == & x8(0,1,2,2,0,1,2,1) ); ASSERT_TRUE( & x2(0,1) == & x8(0,1,2,1,0,1,2,2) ); ASSERT_TRUE( & x2(1,1) == & x8(0,1,2,2,0,1,2,2) ); // Kokkos::View error_2 = Kokkos::View sx2 = Kokkos::subview( x8, 1, Kokkos::pair(0,2), 2, 3 , Kokkos::pair(0,2), 1, 2, 3 ); ASSERT_TRUE( & sx2(0,0) == & x8(1,0,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(1,0) == & x8(1,1,2,3,0,1,2,3) ); ASSERT_TRUE( & sx2(0,1) == & x8(1,0,2,3,1,1,2,3) ); ASSERT_TRUE( & sx2(1,1) == & x8(1,1,2,3,1,1,2,3) ); Kokkos::View sx4 = Kokkos::subview( x8, 0, Kokkos::pair(0,2) /* of [3] */ , 1, Kokkos::pair(1,3) /* of [5] */ , 1, Kokkos::pair(0,2) /* of [3] */ , 2, Kokkos::pair(2,4) /* of [5] */ ); for ( int i0 = 0 ; i0 < (int) sx4.dimension_0() ; ++i0 ) for ( int i1 = 0 ; i1 < (int) sx4.dimension_1() ; ++i1 ) for ( int i2 = 0 ; i2 < (int) sx4.dimension_2() ; ++i2 ) for ( int i3 = 0 ; i3 < (int) sx4.dimension_3() ; ++i3 ) { ASSERT_TRUE( & sx4(i0,i1,i2,i3) == & x8(0,0+i0, 1,1+i1, 1,0+i2, 2,2+i3) ); } } } template< class Space > void test_right_3() { typedef Kokkos::View< int ** , Kokkos::LayoutRight , Space > view_type ; if(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace::value) { view_type xm("x4",10,5); ASSERT_TRUE( xm.is_contiguous() ); Kokkos::View x0 = Kokkos::subview( xm , 5, 3 ); ASSERT_TRUE( x0.is_contiguous() ); ASSERT_TRUE( & x0() == & xm(5,3) ); Kokkos::View x1 = Kokkos::subview( xm, 3, Kokkos::ALL() ); ASSERT_TRUE( x1.is_contiguous() ); for ( int i = 0 ; i < int(xm.dimension_1()) ; ++i ) { ASSERT_TRUE( & x1(i) == & xm(3,i) ); } Kokkos::View x2c = Kokkos::subview( xm, Kokkos::pair(1,9), Kokkos::ALL() ); ASSERT_TRUE( x2c.is_contiguous() ); for ( int j = 0 ; j < int(x2c.dimension_1()) ; ++j ) for ( int i = 0 ; i < int(x2c.dimension_0()) ; ++i ) { ASSERT_TRUE( & x2c(i,j) == & xm(1+i,j) ); } Kokkos::View x2 = Kokkos::subview( xm, Kokkos::ALL(), std::pair(2,4) ); ASSERT_TRUE( ! x2.is_contiguous() ); for ( int j = 0 ; j < int(x2.dimension_1()) ; ++j ) for ( int i = 0 ; i < int(x2.dimension_0()) ; ++i ) { ASSERT_TRUE( & x2(i,j) == & xm(i,2+j) ); } Kokkos::View x2_n1 = Kokkos::subview( xm , std::pair(1,1) , Kokkos::ALL() ); ASSERT_TRUE( x2_n1.dimension_0() == 0 ); ASSERT_TRUE( x2_n1.dimension_1() == xm.dimension_1() ); Kokkos::View x2_n2 = Kokkos::subview( xm , Kokkos::ALL() , std::pair(1,1) ); ASSERT_TRUE( x2_n2.dimension_0() == xm.dimension_0() ); ASSERT_TRUE( x2_n2.dimension_1() == 0 ); } } namespace Impl { constexpr int N0=113; constexpr int N1=11; constexpr int N2=17; constexpr int N3=5; constexpr int N4=7; template void test_Check1D(SubView a, View b, std::pair range) { int errors = 0; for(int i=0;i0) std::cout << "Error Suviews test_Check1D: " << errors < void test_Check1D2D(SubView a, View b, int i0, std::pair range) { int errors = 0; for(int i1=0;i10) std::cout << "Error Suviews test_Check1D2D: " << errors < void test_Check2D3D(SubView a, View b, int i0, std::pair range1, std::pair range2) { int errors = 0; for(int i1=0;i10) std::cout << "Error Suviews test_Check2D3D: " << errors < void test_Check3D5D(SubView a, View b, int i0, int i1, std::pair range2, std::pair range3, std::pair range4) { int errors = 0; for(int i2=0;i20) std::cout << "Error Suviews test_Check3D5D: " << errors < void test_1d_assign_impl() { { //Breaks Kokkos::View a("A",N0); Kokkos::fence(); for(int i=0; i a1(a); Kokkos::fence(); test_Check1D(a1,a,std::pair(0,N0)); Kokkos::View a2(a1); Kokkos::fence(); test_Check1D(a2,a,std::pair(0,N0)); a1 = a; test_Check1D(a1,a,std::pair(0,N0)); //Runtime Fail expected //Kokkos::View afail1(a); //Compile Time Fail expected //Kokkos::View afail2(a1); } { // Works Kokkos::View a("A"); Kokkos::View a1(a); Kokkos::fence(); test_Check1D(a1,a,std::pair(0,N0)); a1 = a; Kokkos::fence(); test_Check1D(a1,a,std::pair(0,N0)); } } template void test_2d_subview_3d_impl_type() { Kokkos::View a_org("A",N0,N1,N2); Kokkos::View a(a_org); for(int i0=0; i0 a1; a1 = Kokkos::subview(a,3,Kokkos::ALL(),Kokkos::ALL()); Kokkos::fence(); test_Check2D3D(a1,a,3,std::pair(0,N1),std::pair(0,N2)); Kokkos::View a2(a,3,Kokkos::ALL(),Kokkos::ALL()); Kokkos::fence(); test_Check2D3D(a2,a,3,std::pair(0,N1),std::pair(0,N2)); } template void test_2d_subview_3d_impl_layout() { test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); test_2d_subview_3d_impl_type(); } template void test_2d_subview_5d_impl_type() { Kokkos::View a_org("A",N0,N1,N2,N3,N4); Kokkos::View a(a_org); for(int i0=0; i0 a1; a1 = Kokkos::subview(a,3,5,Kokkos::ALL(),Kokkos::ALL(),Kokkos::ALL()); Kokkos::fence(); test_Check3D5D(a1,a,3,5,std::pair(0,N2),std::pair(0,N3),std::pair(0,N4)); Kokkos::View a2(a,3,5,Kokkos::ALL(),Kokkos::ALL(),Kokkos::ALL()); Kokkos::fence(); test_Check3D5D(a2,a,3,5,std::pair(0,N2),std::pair(0,N3),std::pair(0,N4)); } template void test_2d_subview_5d_impl_layout() { test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); test_2d_subview_5d_impl_type(); } } template< class Space > void test_1d_assign() { Impl::test_1d_assign_impl(); //Impl::test_1d_assign_impl(); Impl::test_1d_assign_impl(); //Impl::test_1d_assign_impl(); Impl::test_1d_assign_impl(); Impl::test_1d_assign_impl(); //Impl::test_1d_assign_impl(); //Impl::test_1d_assign_impl(); Impl::test_1d_assign_impl(); } template void test_2d_subview_3d() { Impl::test_2d_subview_3d_impl_layout(); Impl::test_2d_subview_3d_impl_layout(); Impl::test_2d_subview_3d_impl_layout(); Impl::test_2d_subview_3d_impl_layout(); Impl::test_2d_subview_3d_impl_layout(); } template void test_2d_subview_5d() { Impl::test_2d_subview_5d_impl_layout(); Impl::test_2d_subview_5d_impl_layout(); Impl::test_2d_subview_5d_impl_layout(); Impl::test_2d_subview_5d_impl_layout(); } } //----------------------------------------------------------------------------