|
Kokkos Core Kernels Package
Version of the Day
|
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 00046 #ifndef KOKKOS_STATICCRSGRAPH_HPP 00047 #define KOKKOS_STATICCRSGRAPH_HPP 00048 00049 #include <string> 00050 #include <vector> 00051 00052 #include <Kokkos_Core.hpp> 00053 00054 namespace Kokkos { 00055 00086 template< class DataType, 00087 class Arg1Type, 00088 class Arg2Type = void, 00089 typename SizeType = typename ViewTraits<DataType*, Arg1Type, Arg2Type, void >::size_type> 00090 class StaticCrsGraph { 00091 private: 00092 typedef ViewTraits<DataType*, Arg1Type, Arg2Type, void> traits; 00093 00094 public: 00095 typedef DataType data_type; 00096 typedef typename traits::array_layout array_layout; 00097 typedef typename traits::device_type device_type; 00098 typedef SizeType size_type; 00099 00100 typedef StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType > staticcrsgraph_type; 00101 typedef StaticCrsGraph< DataType , array_layout , typename device_type::host_mirror_device_type , SizeType > HostMirror; 00102 //typedef StaticCrsGraph< DataType , array_layout , Kokkos::Threads , SizeType > HostMirror; 00103 typedef View< const size_type* , array_layout, device_type > row_map_type; 00104 typedef View< DataType* , array_layout, device_type > entries_type; 00105 00106 entries_type entries; 00107 row_map_type row_map; 00108 00110 StaticCrsGraph () : entries(), row_map() {} 00111 00113 StaticCrsGraph (const StaticCrsGraph& rhs) : entries (rhs.entries), row_map (rhs.row_map) 00114 {} 00115 00116 template<class EntriesType, class RowMapType> 00117 StaticCrsGraph (const EntriesType& entries_,const RowMapType& row_map_) : entries (entries_), row_map (row_map_) 00118 {} 00119 00124 StaticCrsGraph& operator= (const StaticCrsGraph& rhs) { 00125 entries = rhs.entries; 00126 row_map = rhs.row_map; 00127 return *this; 00128 } 00129 00133 ~StaticCrsGraph() {} 00134 00135 size_t numRows() const { 00136 return row_map.dimension_0()>0?row_map.dimension_0()-1:0; 00137 } 00138 00139 }; 00140 00141 //---------------------------------------------------------------------------- 00142 00143 template< class StaticCrsGraphType , class InputSizeType > 00144 typename StaticCrsGraphType::staticcrsgraph_type 00145 create_staticcrsgraph( const std::string & label , 00146 const std::vector< InputSizeType > & input ); 00147 00148 template< class StaticCrsGraphType , class InputSizeType > 00149 typename StaticCrsGraphType::staticcrsgraph_type 00150 create_staticcrsgraph( const std::string & label , 00151 const std::vector< std::vector< InputSizeType > > & input ); 00152 00153 //---------------------------------------------------------------------------- 00154 00155 template< class DataType , 00156 class Arg1Type , 00157 class Arg2Type , 00158 typename SizeType > 00159 typename StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror 00160 create_mirror_view( const StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType > & input ); 00161 00162 template< class DataType , 00163 class Arg1Type , 00164 class Arg2Type , 00165 typename SizeType > 00166 typename StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror 00167 create_mirror( const StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType > & input ); 00168 00169 } // namespace Kokkos 00170 00171 //---------------------------------------------------------------------------- 00172 //---------------------------------------------------------------------------- 00173 00174 #include <impl/Kokkos_StaticCrsGraph_factory.hpp> 00175 00176 //---------------------------------------------------------------------------- 00177 //---------------------------------------------------------------------------- 00178 00179 namespace Kokkos { 00180 namespace Impl { 00181 00182 template< class GraphType > 00183 struct StaticCrsGraphMaximumEntry { 00184 00185 typedef typename GraphType::device_type device_type ; 00186 typedef typename GraphType::data_type value_type ; 00187 00188 const typename GraphType::entries_type entries ; 00189 00190 StaticCrsGraphMaximumEntry( const GraphType & graph ) : entries( graph.entries ) {} 00191 00192 KOKKOS_INLINE_FUNCTION 00193 void operator()( const unsigned i , value_type & update ) const 00194 { if ( update < entries(i) ) update = entries(i); } 00195 00196 KOKKOS_INLINE_FUNCTION 00197 void init( value_type & update ) const 00198 { update = 0 ; } 00199 00200 KOKKOS_INLINE_FUNCTION 00201 void join( volatile value_type & update , 00202 volatile const value_type & input ) const 00203 { if ( update < input ) update = input ; } 00204 }; 00205 00206 } 00207 00208 template< class DataType, class Arg1Type, class Arg2Type, typename SizeType > 00209 DataType maximum_entry( const StaticCrsGraph< DataType , Arg1Type , Arg2Type , SizeType > & graph ) 00210 { 00211 typedef StaticCrsGraph<DataType,Arg1Type,Arg2Type,SizeType> GraphType ; 00212 typedef Impl::StaticCrsGraphMaximumEntry< GraphType > FunctorType ; 00213 00214 DataType result = 0 ; 00215 Kokkos::parallel_reduce( graph.entries.dimension_0(), 00216 FunctorType(graph), result ); 00217 return result ; 00218 } 00219 00220 } // namespace Kokkos 00221 00222 //---------------------------------------------------------------------------- 00223 //---------------------------------------------------------------------------- 00224 00225 #endif /* #ifndef KOKKOS_CRSARRAY_HPP */ 00226
1.7.6.1