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 ) )
103 using weight_function_t =
104 typename std::function< std::int32_t( PortInfo&,PortInfo&,void* ) >;
106 using raftgraph_t = raft::graph< std::int32_t,
111 template <
class Container >
113 void get_graph_info( Container &c,
114 raftgraph_t &raft_graph,
115 weight_function_t weight_func,
124 for( raft::kernel
const *k : c )
126 numbering.insert( std::make_pair( k, index++ ) );
131 LocalData( raftgraph_t &g, nummap_t &m )
138 } d ( raft_graph, numbering );
139 auto graph_function =
144 if( ! Schedule::isActive( a.my_kernel ) )
148 auto *
const local_data(
149 reinterpret_cast< LocalData* >( data ) );
150 const auto num_src( local_data->num_map[ a.my_kernel ] );
151 const auto num_dst( local_data->num_map[ b.my_kernel ] );
152 const auto weight( weight_func( a, b, weight_data ) );
153 local_data->graph.addEdge( num_src, num_dst, weight );
166 template <
class Container,
169 bool simple_check( Container &c,
170 MapContainer &mapping,
171 const std::size_t cores )
173 if( c.size() <= cores )
175 const auto length( c.size() );
176 for(
auto i( 0 ); i < length; i++ )
178 mapping.emplace_back( i );
189 template <
class Container,
192 void run_scotch( Container &c,
193 MapContainer &mapping,
194 const std::size_t cores,
195 weight_function_t weight_func,
199 static_assert( std::is_signed<
200 std::remove_reference< decltype( c.end() ) >::type >::value,
201 "Container must have signed types so that -1 may signify no mapping" );
203 raftgraph_t raft_graph;
209 if( SCOTCH_graphInit( &graph ) != 0 )
212 std::cerr <<
"Failed to initialize graph!!\n";
213 exit( EXIT_FAILURE );
215 auto table( raft_graph.getScotchTables() );
216 if( SCOTCH_graphBuild(
230 std::cerr <<
"Failed to build graph\n";
231 exit( EXIT_FAILURE );
233 if( SCOTCH_graphCheck( &graph ) != 0 )
236 std::cerr <<
"Graph is inconsistent\n";
237 std::remove_reference< decltype( table ) >::type::print( std::cerr, table );
239 raft_graph.print( std::cerr );
241 exit( EXIT_FAILURE );
245 if( SCOTCH_archInit( &archdat ) != 0 )
248 std::cerr <<
"Architecture initialization failed\n";
249 exit( EXIT_FAILURE );
252 if( SCOTCH_archCmplt( &archdat, cores ) != 0 )
255 std::cerr <<
"Failed to create architecture file\n";
256 exit( EXIT_FAILURE );
259 SCOTCH_Strat stradat;
260 if( SCOTCH_stratInit( &stradat ) != 0 )
263 std::cerr <<
"Failed to init strategy!!\n";
264 exit( EXIT_FAILURE );
267 if( SCOTCH_stratGraphClusterBuild(
275 std::cerr <<
"Failed to map strategy graph!!\n";
276 exit( EXIT_FAILURE );
286 std::cerr <<
"Failed to map!!\n";
287 exit( EXIT_FAILURE );
300 if( c.size() == table.num_vertices )
303 for(
auto i( 0 ); i < table.num_vertices; i++ )
305 mapping.emplace_back( table.partition[ i ] );
310 const auto &vmapping( raft_graph.getVertexNumbersAtIndicies() );
311 auto it_map_index( vmapping.cbegin() );
312 auto table_index( 0 );
313 const auto size( c.size() );
314 for(
auto i( 0 ); i < size; i++ )
316 if( i == (*it_map_index) && it_map_index != vmapping.cend() )
318 mapping.emplace_back( table.partition[ table_index++ ] );
323 mapping.emplace_back( -1 );
328 SCOTCH_graphExit( &graph );
329 SCOTCH_stratExit( &stradat );
330 SCOTCH_archExit ( &archdat );
Definition: partition_old.hpp:32
static void simple(Container &c, MappingContainer &mapping, const std::size_t cores)
Definition: partition_old.hpp:42
virtual std::size_t size()=0
static void utilization_weighted(Container &c, MappingContainer &mapping, const std::size_t cores)
Definition: partition_old.hpp:69
Definition: port_info.hpp:39
FIFO * getFIFO()
Definition: port_info.cpp:49
Definition: kernel.hpp:57