20 #ifndef _PARTITION_HPP_
21 #define _PARTITION_HPP_ 1
30 #include "graphtools.hpp"
38 template <
class Container,
39 class MappingContainer >
43 MappingContainer &mapping,
44 const std::size_t cores )
46 if( simple_check( c, mapping, cores ) )
65 template <
class Container,
66 class MappingContainer >
70 MappingContainer &mapping,
71 const std::size_t cores )
73 if( simple_check( c, mapping, cores ) )
96 using weight_function_t =
97 typename std::function< std::int32_t( PortInfo&,PortInfo&,void* ) >;
99 using raftgraph_t = raft::graph< std::int32_t,
104 template <
class Container >
106 void get_graph_info( Container &c,
107 raftgraph_t &raft_graph,
108 weight_function_t weight_func,
117 for( raft::kernel
const *k : c )
119 numbering.insert( std::make_pair( k, index++ ) );
124 LocalData( raftgraph_t &g, nummap_t &m )
131 } d ( raft_graph, numbering );
132 auto graph_function =
137 if( ! Schedule::isActive( a.my_kernel ) )
142 reinterpret_cast< LocalData* >( data ) );
143 const auto num_src( local_data->num_map[ a.my_kernel ] );
144 const auto num_dst( local_data->num_map[ b.my_kernel ] );
145 const auto weight( weight_func( a, b, weight_data ) );
146 local_data->graph.addEdge( num_src, num_dst, weight );
159 template <
class Container,
162 bool simple_check( Container &c,
163 MapContainer &mapping,
164 const std::size_t cores )
166 if( c.size() <= cores )
168 const auto length( c.size() );
169 for(
auto i( 0 ); i < length; i++ )
171 mapping.push_back( i );
182 template <
class Container,
185 void run_scotch( Container &c,
186 MapContainer &mapping,
187 const std::size_t cores,
188 weight_function_t weight_func,
192 static_assert( std::is_signed<
193 std::remove_reference< decltype( c.end() ) >::type >::value,
194 "Container must have signed types so that -1 may signify no mapping" );
196 raftgraph_t raft_graph;
202 if( SCOTCH_graphInit( &graph ) != 0 )
205 std::cerr <<
"Failed to initialize graph!!\n";
206 exit( EXIT_FAILURE );
208 auto table( raft_graph.getScotchTables() );
209 if( SCOTCH_graphBuild(
223 std::cerr <<
"Failed to build graph\n";
224 exit( EXIT_FAILURE );
226 if( SCOTCH_graphCheck( &graph ) != 0 )
229 std::cerr <<
"Graph is inconsistent\n";
230 exit( EXIT_FAILURE );
234 if( SCOTCH_archInit( &archdat ) != 0 )
237 std::cerr <<
"Architecture initialization failed\n";
238 exit( EXIT_FAILURE );
241 if( SCOTCH_archCmplt( &archdat, cores ) != 0 )
244 std::cerr <<
"Failed to create architecture file\n";
245 exit( EXIT_FAILURE );
248 SCOTCH_Strat stradat;
249 if( SCOTCH_stratInit( &stradat ) != 0 )
252 std::cerr <<
"Failed to init strategy!!\n";
253 exit( EXIT_FAILURE );
256 if( SCOTCH_stratGraphClusterBuild(
258 SCOTCH_STRATRECURSIVE,
264 std::cerr <<
"Failed to map strategy graph!!\n";
265 exit( EXIT_FAILURE );
275 std::cerr <<
"Failed to map!!\n";
276 exit( EXIT_FAILURE );
289 if( c.size() == table.num_vertices )
292 for(
auto i( 0 ); i < table.num_vertices; i++ )
294 mapping.push_back( table.partition[ i ] );
299 const auto &vmapping( raft_graph.getVertexNumbersAtIndicies() );
300 auto it_map_index( vmapping.cbegin() );
301 auto table_index( 0 );
302 const auto size( c.size() );
303 for(
auto i( 0 ); i < size; i++ )
305 if( i == (*it_map_index) && it_map_index != vmapping.cend() )
307 mapping.push_back( table.partition[ table_index++ ] );
312 mapping.push_back( -1 );
317 SCOTCH_graphExit( &graph );
318 SCOTCH_stratExit( &stradat );
319 SCOTCH_archExit ( &archdat );
Definition: partition.hpp:32
static void simple(Container &c, MappingContainer &mapping, const std::size_t cores)
Definition: partition.hpp:42
virtual std::size_t size()=0
static void utilization_weighted(Container &c, MappingContainer &mapping, const std::size_t cores)
Definition: partition.hpp:69
FIFO * getFIFO()
Definition: port_info.hpp:93
Definition: port_info.hpp:39
Definition: kernel.hpp:48