vpr/src/route/rr_graph_reader.cpp
/*Loads the edges information from file into vpr. Nodes and switches must be loaded
 * before calling this function*/
Loads the edges information from file into vpr. Nodes and switches must be loaded
before calling this function
Loads the edges information from file into vpr . Nodes and switches must be loaded before calling this function
void process_edges(pugi::xml_node parent, const pugiutil::loc_data& loc_data, int* wire_to_rr_ipin_switch, const int num_rr_switches) {
    auto& device_ctx = g_vpr_ctx.mutable_device();
    pugi::xml_node edges;
    edges = get_first_child(parent, "edge", loc_data);
    vtr::vector<RRNodeId, size_t> num_edges_for_node;
    num_edges_for_node.resize(device_ctx.rr_graph.nodes().size(), 0);
    unsigned long num_edges_to_reserve = 0;
    while (edges) {
        RRNodeId source_node = RRNodeId(get_attribute(edges, "src_node", loc_data).as_uint());
        if (false == device_ctx.rr_graph.valid_node_id(source_node)) {
            VPR_FATAL_ERROR(VPR_ERROR_OTHER,
                            "source_node %d is larger than rr_nodes.size() %d",
                            size_t(source_node), device_ctx.rr_graph.nodes().size());
        }
        num_edges_for_node[source_node]++;
        num_edges_to_reserve++;
        edges = edges.next_sibling(edges.name());
    }
    for (const RRNodeId& inode : device_ctx.rr_graph.nodes()) {
        if (num_edges_for_node[inode] > 4 * std::numeric_limits<uint16_t>::max()) {
            VPR_FATAL_ERROR(VPR_ERROR_OTHER,
                            "source node %d edge count %d is too high",
                            size_t(inode), num_edges_for_node[inode]);
        }
        num_edges_for_node[inode] = 0;
    }
    device_ctx.rr_graph.reserve_edges(num_edges_to_reserve);
    edges = get_first_child(parent, "edge", loc_data);
    std::vector<int> count_for_wire_to_ipin_switches;
    count_for_wire_to_ipin_switches.resize(num_rr_switches, 0);
    std::pair<int, int> most_frequent_switch(-1, 0);
    while (edges) {
        RRNodeId source_node = RRNodeId(get_attribute(edges, "src_node", loc_data).as_uint());
        RRNodeId sink_node = RRNodeId(get_attribute(edges, "sink_node", loc_data).as_uint());
        int switch_id = get_attribute(edges, "switch_id", loc_data).as_int();
        if (false == device_ctx.rr_graph.valid_node_id(sink_node)) {
            VPR_FATAL_ERROR(VPR_ERROR_OTHER,
                            "sink_node %d is larger than rr_nodes.size() %d",
                            size_t(sink_node), device_ctx.rr_graph.nodes().size());
        }
        if (switch_id >= num_rr_switches) {
            VPR_FATAL_ERROR(VPR_ERROR_OTHER,
                            "switch_id %d is larger than num_rr_switches %d",
                            switch_id, num_rr_switches);
        }
        if (device_ctx.rr_graph.node_type(source_node) == CHANX || device_ctx.rr_graph.node_type(source_node) == CHANY) {
            if (device_ctx.rr_graph.node_type(sink_node) == IPIN) {
                count_for_wire_to_ipin_switches[switch_id]++;
                if (count_for_wire_to_ipin_switches[switch_id] > most_frequent_switch.second) {
                    most_frequent_switch.first = switch_id;
                    most_frequent_switch.second = count_for_wire_to_ipin_switches[switch_id];
                }
            }
        }
        device_ctx.rr_graph.create_edge(source_node, sink_node, RRSwitchId(switch_id));
        auto metadata = get_single_child(edges, "metadata", loc_data, pugiutil::OPTIONAL);
        if (metadata) {
            auto edges_meta = get_first_child(metadata, "meta", loc_data);
            while (edges_meta) {
                auto key = get_attribute(edges_meta, "name", loc_data).as_string();
                vpr::add_rr_edge_metadata(size_t(source_node), size_t(sink_node), switch_id,
                                          key, edges_meta.child_value());
                edges_meta = edges_meta.next_sibling(edges_meta.name());
            }
        }
        num_edges_for_node[source_node]++;
        edges = edges.next_sibling(edges.name()); 
    }
    *wire_to_rr_ipin_switch = most_frequent_switch.first;
    num_edges_for_node.clear();
    count_for_wire_to_ipin_switches.clear();
}
void process_edges ( pugi :: xml_node parent , const pugiutil :: loc_data & loc_data , int * wire_to_rr_ipin_switch , const int num_rr_switches ) { auto & device_ctx = g_vpr_ctx . mutable_device ( ) ; pugi :: xml_node edges ; edges = get_first_child ( parent , " " , loc_data ) ; vtr :: vector < RRNodeId , size_t > num_edges_for_node ; num_edges_for_node . resize ( device_ctx . rr_graph . nodes ( ) . size ( ) , 0 ) ; unsigned long num_edges_to_reserve = 0 ; while ( edges ) { RRNodeId source_node = RRNodeId ( get_attribute ( edges , " " , loc_data ) . as_uint ( ) ) ; if ( false == device_ctx . rr_graph . valid_node_id ( source_node ) ) { VPR_FATAL_ERROR ( VPR_ERROR_OTHER , " " , size_t ( source_node ) , device_ctx . rr_graph . nodes ( ) . size ( ) ) ; } num_edges_for_node [ source_node ] ++ ; num_edges_to_reserve ++ ; edges = edges . next_sibling ( edges . name ( ) ) ; } for ( const RRNodeId & inode : device_ctx . rr_graph . nodes ( ) ) { if ( num_edges_for_node [ inode ] > 4 * std :: numeric_limits < uint16_t > :: max ( ) ) { VPR_FATAL_ERROR ( VPR_ERROR_OTHER , " " , size_t ( inode ) , num_edges_for_node [ inode ] ) ; } num_edges_for_node [ inode ] = 0 ; } device_ctx . rr_graph . reserve_edges ( num_edges_to_reserve ) ; edges = get_first_child ( parent , " " , loc_data ) ; std :: vector < int > count_for_wire_to_ipin_switches ; count_for_wire_to_ipin_switches . resize ( num_rr_switches , 0 ) ; std :: pair < int , int > most_frequent_switch ( -1 , 0 ) ; while ( edges ) { RRNodeId source_node = RRNodeId ( get_attribute ( edges , " " , loc_data ) . as_uint ( ) ) ; RRNodeId sink_node = RRNodeId ( get_attribute ( edges , " " , loc_data ) . as_uint ( ) ) ; int switch_id = get_attribute ( edges , " " , loc_data ) . as_int ( ) ; if ( false == device_ctx . rr_graph . valid_node_id ( sink_node ) ) { VPR_FATAL_ERROR ( VPR_ERROR_OTHER , " " , size_t ( sink_node ) , device_ctx . rr_graph . nodes ( ) . size ( ) ) ; } if ( switch_id >= num_rr_switches ) { VPR_FATAL_ERROR ( VPR_ERROR_OTHER , " " , switch_id , num_rr_switches ) ; } if ( device_ctx . rr_graph . node_type ( source_node ) == CHANX || device_ctx . rr_graph . node_type ( source_node ) == CHANY ) { if ( device_ctx . rr_graph . node_type ( sink_node ) == IPIN ) { count_for_wire_to_ipin_switches [ switch_id ] ++ ; if ( count_for_wire_to_ipin_switches [ switch_id ] > most_frequent_switch . second ) { most_frequent_switch . first = switch_id ; most_frequent_switch . second = count_for_wire_to_ipin_switches [ switch_id ] ; } } } device_ctx . rr_graph . create_edge ( source_node , sink_node , RRSwitchId ( switch_id ) ) ; auto metadata = get_single_child ( edges , " " , loc_data , pugiutil :: OPTIONAL ) ; if ( metadata ) { auto edges_meta = get_first_child ( metadata , " " , loc_data ) ; while ( edges_meta ) { auto key = get_attribute ( edges_meta , " " , loc_data ) . as_string ( ) ; vpr :: add_rr_edge_metadata ( size_t ( source_node ) , size_t ( sink_node ) , switch_id , key , edges_meta . child_value ( ) ) ; edges_meta = edges_meta . next_sibling ( edges_meta . name ( ) ) ; } } num_edges_for_node [ source_node ] ++ ; edges = edges . next_sibling ( edges . name ( ) ) ; } * wire_to_rr_ipin_switch = most_frequent_switch . first ; num_edges_for_node . clear ( ) ; count_for_wire_to_ipin_switches . clear ( ) ; }
Loads the edges information from file into vpr.
Loads the edges information from file into vpr .
//count the number of edges and store it in a vector //reset this vector in order to start count for num edges again /* uint16_t is the data type for each type of edges in RRGraph object 
         * Multiplied by 4 is due to the fact that each node has 4 groups of edges
         * and each group is bounded by uint16_t
         * See rr_graph_obj.h for more details
         */ /* Reserve the memory for edges */ /*initialize a vector that keeps track of the number of wire to ipin switches
     * There should be only one wire to ipin switch. In case there are more, make sure to
     * store the most frequent switch */ //first is index, second is count /*Keeps track of the number of the specific type of switch that connects a wire to an ipin
         * use the pair data structure to keep the maximum*/ //set edge in correct rr_node data structure // Read the metadata for the edge //Next edge