vpr/src/route/rr_graph.cpp
/* allocate pin to track map for each segment type individually and then combine into a single
 * vector */
allocate pin to track map for each segment type individually and then combine into a single
vector
allocate pin to track map for each segment type individually and then combine into a single vector
static vtr::NdMatrix<std::vector<int>, 4> alloc_and_load_pin_to_track_map(const e_pin_type pin_type,
                                                                          const vtr::Matrix<int>& Fc,
                                                                          const t_physical_tile_type_ptr Type,
                                                                          const std::vector<bool>& perturb_switch_pattern,
                                                                          const e_directionality directionality,
                                                                          const int num_seg_types,
                                                                          const int* sets_per_seg_type) {
    size_t max_pin_tracks = 0;
    for (int iseg = 0; iseg < num_seg_types; iseg++) {
        int max_Fc = 0;
        for (int pin_index = 0; pin_index < Type->num_pins; ++pin_index) {
            int pin_class = Type->pin_class[pin_index];
            if (Fc[pin_index][iseg] > max_Fc && Type->class_inf[pin_class].type == pin_type) {
                max_Fc = Fc[pin_index][iseg];
            }
        }
        max_pin_tracks += max_Fc;
    }
    auto result = vtr::NdMatrix<std::vector<int>, 4>({
        size_t(Type->num_pins), 
        size_t(Type->width),    
        size_t(Type->height),   
        4,                      
    });
    int fac = 1;
    if (directionality == UNI_DIRECTIONAL) {
        fac = 2;
    }
    int seg_type_start_track = 0;
    for (int iseg = 0; iseg < num_seg_types; iseg++) {
        int num_seg_type_tracks = fac * sets_per_seg_type[iseg];
        int max_Fc = 0;
        for (int pin_index = 0; pin_index < Type->num_pins; ++pin_index) {
            int pin_class = Type->pin_class[pin_index];
            if (Fc[pin_index][iseg] > max_Fc && Type->class_inf[pin_class].type == pin_type) {
                max_Fc = Fc[pin_index][iseg];
            }
        }
        auto pin_to_seg_type_map = alloc_and_load_pin_to_seg_type(pin_type,
                                                                  num_seg_type_tracks, max_Fc, Type, perturb_switch_pattern[iseg], directionality);
        for (int ipin = 0; ipin < Type->num_pins; ipin++) {
            for (int iwidth = 0; iwidth < Type->width; iwidth++) {
                for (int iheight = 0; iheight < Type->height; iheight++) {
                    for (int iside = 0; iside < 4; iside++) {
                        for (int iconn = 0; iconn < max_Fc; iconn++) {
                            int relative_track_ind = pin_to_seg_type_map[ipin][iwidth][iheight][iside][iconn];
                            if (relative_track_ind == OPEN) continue;
                            int absolute_track_ind = relative_track_ind + seg_type_start_track;
                            VTR_ASSERT(absolute_track_ind >= 0);
                            result[ipin][iwidth][iheight][iside].push_back(absolute_track_ind);
                        }
                    }
                }
            }
        }
        seg_type_start_track += num_seg_type_tracks;
    }
    return result;
}
static vtr :: NdMatrix < std :: vector < int > , 4 > alloc_and_load_pin_to_track_map ( const e_pin_type pin_type , const vtr :: Matrix < int > & Fc , const t_physical_tile_type_ptr Type , const std :: vector < bool > & perturb_switch_pattern , const e_directionality directionality , const int num_seg_types , const int * sets_per_seg_type ) { size_t max_pin_tracks = 0 ; for ( int iseg = 0 ; iseg < num_seg_types ; iseg ++ ) { int max_Fc = 0 ; for ( int pin_index = 0 ; pin_index < Type -> num_pins ; ++ pin_index ) { int pin_class = Type -> pin_class [ pin_index ] ; if ( Fc [ pin_index ] [ iseg ] > max_Fc && Type -> class_inf [ pin_class ] . type == pin_type ) { max_Fc = Fc [ pin_index ] [ iseg ] ; } } max_pin_tracks += max_Fc ; } auto result = vtr :: NdMatrix < std :: vector < int > , 4 > ( { size_t ( Type -> num_pins ) , size_t ( Type -> width ) , size_t ( Type -> height ) , 4 , } ) ; int fac = 1 ; if ( directionality == UNI_DIRECTIONAL ) { fac = 2 ; } int seg_type_start_track = 0 ; for ( int iseg = 0 ; iseg < num_seg_types ; iseg ++ ) { int num_seg_type_tracks = fac * sets_per_seg_type [ iseg ] ; int max_Fc = 0 ; for ( int pin_index = 0 ; pin_index < Type -> num_pins ; ++ pin_index ) { int pin_class = Type -> pin_class [ pin_index ] ; if ( Fc [ pin_index ] [ iseg ] > max_Fc && Type -> class_inf [ pin_class ] . type == pin_type ) { max_Fc = Fc [ pin_index ] [ iseg ] ; } } auto pin_to_seg_type_map = alloc_and_load_pin_to_seg_type ( pin_type , num_seg_type_tracks , max_Fc , Type , perturb_switch_pattern [ iseg ] , directionality ) ; for ( int ipin = 0 ; ipin < Type -> num_pins ; ipin ++ ) { for ( int iwidth = 0 ; iwidth < Type -> width ; iwidth ++ ) { for ( int iheight = 0 ; iheight < Type -> height ; iheight ++ ) { for ( int iside = 0 ; iside < 4 ; iside ++ ) { for ( int iconn = 0 ; iconn < max_Fc ; iconn ++ ) { int relative_track_ind = pin_to_seg_type_map [ ipin ] [ iwidth ] [ iheight ] [ iside ] [ iconn ] ; if ( relative_track_ind == OPEN ) continue ; int absolute_track_ind = relative_track_ind + seg_type_start_track ; VTR_ASSERT ( absolute_track_ind >= 0 ) ; result [ ipin ] [ iwidth ] [ iheight ] [ iside ] . push_back ( absolute_track_ind ) ; } } } } } seg_type_start_track += num_seg_type_tracks ; } return result ; }
allocate pin to track map for each segment type individually and then combine into a single
 vector
allocate pin to track map for each segment type individually and then combine into a single vector
/* get the maximum number of tracks that any pin can connect to */ /* determine the maximum Fc to this segment type across all pins */ /* allocate 'result' matrix and initialize entries to OPEN. also allocate and intialize matrix which will be
     * used to index into the correct entries when loading up 'result' */ //[0..num_pins-1] //[0..width-1] //[0..height-1] //[0..sides-1] /* multiplier for unidirectional vs bidirectional architectures */ /* load the pin to track matrix by looking at each segment type in turn */ /* determine the maximum Fc to this segment type across all pins */ /* get pin connections to tracks of the current segment type */ /* connections in pin_to_seg_type_map are within that seg type -- i.e. in the [0,num_seg_type_tracks-1] range.
         * now load up 'result' array with these connections, but offset them so they are relative to the channel
         * as a whole */ /* next seg type will start at this track index */