Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Kokkos_Layout.hpp
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //                             Kokkos
00006 //         Manycore Performance-Portable Multidimensional Arrays
00007 //
00008 //              Copyright (2012) Sandia Corporation
00009 //
00010 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00011 // the U.S. Government retains certain rights in this software.
00012 //
00013 // Redistribution and use in source and binary forms, with or without
00014 // modification, are permitted provided that the following conditions are
00015 // met:
00016 //
00017 // 1. Redistributions of source code must retain the above copyright
00018 // notice, this list of conditions and the following disclaimer.
00019 //
00020 // 2. Redistributions in binary form must reproduce the above copyright
00021 // notice, this list of conditions and the following disclaimer in the
00022 // documentation and/or other materials provided with the distribution.
00023 //
00024 // 3. Neither the name of the Corporation nor the names of the
00025 // contributors may be used to endorse or promote products derived from
00026 // this software without specific prior written permission.
00027 //
00028 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00029 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00031 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00032 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00033 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00034 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00035 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00036 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00037 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 //
00040 // Questions?  Contact  H. Carter Edwards (hcedwar@sandia.gov)
00041 //
00042 // ************************************************************************
00043 //@HEADER
00044 */
00045 
00048 
00049 #ifndef KOKKOS_LAYOUT_HPP
00050 #define KOKKOS_LAYOUT_HPP
00051 
00052 #include <stddef.h>
00053 #include <impl/Kokkos_Traits.hpp>
00054 #include <impl/Kokkos_Tags.hpp>
00055 
00056 namespace Kokkos {
00057 
00058 //----------------------------------------------------------------------------
00073 struct LayoutLeft {
00075   typedef Impl::LayoutTag       kokkos_tag ;
00076   typedef LayoutLeft array_layout ;
00077 };
00078 
00079 //----------------------------------------------------------------------------
00093 struct LayoutRight {
00095   typedef Impl::LayoutTag       kokkos_tag ;
00096   typedef LayoutRight array_layout ;
00097 };
00098 
00099 //----------------------------------------------------------------------------
00103 struct LayoutStride {
00104 
00106   typedef Impl::LayoutTag       kokkos_tag ;
00107 
00108   typedef LayoutStride array_layout ;
00109 
00110   enum { MAX_RANK = 8 };
00111 
00112   size_t dimension[ MAX_RANK ] ;
00113   size_t stride[ MAX_RANK ] ; 
00114 
00122   template< typename iTypeOrder , typename iTypeDimen >
00123   KOKKOS_INLINE_FUNCTION static
00124   LayoutStride order_dimensions( int const rank
00125                                , iTypeOrder const * const order
00126                                , iTypeDimen const * const dimen )
00127     {
00128       LayoutStride tmp ;
00129       // Verify valid rank order:
00130       int check_input = MAX_RANK < rank ? 0 : int( 1 << rank ) - 1 ;
00131       for ( int r = 0 ; r < MAX_RANK ; ++r ) {
00132         tmp.dimension[r] = 0 ;
00133         tmp.stride[r]    = 0 ;
00134         check_input &= ~int( 1 << order[r] );
00135       }
00136       if ( 0 == check_input ) {
00137         size_t n = 1 ;
00138         for ( int r = 0 ; r < rank ; ++r ) {
00139           tmp.stride[ order[r] ] = n ;
00140           n *= ( dimen[order[r]] );
00141           tmp.dimension[r] = dimen[r];
00142         }
00143       }
00144       return tmp ;
00145     }
00146 };
00147 
00148 //----------------------------------------------------------------------------
00165 template < unsigned ArgN0 , unsigned ArgN1 ,
00166            bool IsPowerOfTwo = ( Impl::is_power_of_two<ArgN0>::value &&
00167                                  Impl::is_power_of_two<ArgN1>::value )
00168          >
00169 struct LayoutTileLeft {
00171   typedef Impl::LayoutTag       kokkos_tag ;
00172 
00173   typedef LayoutTileLeft<ArgN0,ArgN1,IsPowerOfTwo> array_layout ;
00174   enum { N0 = ArgN0 };
00175   enum { N1 = ArgN1 };
00176 };
00177 
00178 } // namespace Kokkos
00179 
00180 #endif // #ifndef KOKKOS_LAYOUT_HPP
00181 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends