1
+ #include < climits>
2
+ #include " arch_types.h"
1
3
#include " rr_graph_storage.h"
2
4
3
5
#include < algorithm>
4
6
5
- #include " globals.h"
6
-
7
7
void t_rr_graph_storage::reserve_edges (size_t num_edges) {
8
8
edge_src_node_.reserve (num_edges);
9
9
edge_dest_node_.reserve (num_edges);
@@ -488,8 +488,7 @@ void t_rr_graph_storage::mark_edges_as_rr_switch_ids() {
488
488
remapped_edges_ = true ;
489
489
}
490
490
491
- /* TODO: This API should be moved to RRGraphBuilder */
492
- void t_rr_graph_storage::partition_edges () {
491
+ void t_rr_graph_storage::partition_edges (const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) {
493
492
if (partitioned_) {
494
493
return ;
495
494
}
@@ -504,40 +503,65 @@ void t_rr_graph_storage::partition_edges() {
504
503
std::sort (
505
504
edge_sort_iterator (this , 0 ),
506
505
edge_sort_iterator (this , edge_src_node_.size ()),
507
- edge_compare_src_node_and_configurable_first (g_vpr_ctx. mutable_device (). rr_graph_builder . rr_switch () ));
506
+ edge_compare_src_node_and_configurable_first (rr_switches ));
508
507
509
508
partitioned_ = true ;
510
509
511
510
assign_first_edges ();
512
511
513
- VTR_ASSERT_SAFE (validate ());
512
+ VTR_ASSERT_SAFE (validate (rr_switches ));
514
513
}
515
514
516
- t_edge_size t_rr_graph_storage::num_configurable_edges (const RRNodeId& id ) const {
515
+ t_edge_size t_rr_graph_storage::num_configurable_edges (RRNodeId id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches ) const {
517
516
VTR_ASSERT (!node_first_edge_.empty () && remapped_edges_);
518
517
519
- const auto & device_ctx = g_vpr_ctx.device ();
520
- const auto & rr_graph = device_ctx.rr_graph ;
521
518
auto first_id = size_t (node_first_edge_[id]);
522
519
auto last_id = size_t ((&node_first_edge_[id])[1 ]);
523
520
for (size_t idx = first_id; idx < last_id; ++idx) {
524
521
auto switch_idx = edge_switch_[RREdgeId (idx)];
525
- if (!rr_graph. rr_switch_inf ( RRSwitchId (switch_idx)) .configurable ()) {
522
+ if (!rr_switches[ RRSwitchId (switch_idx)] .configurable ()) {
526
523
return idx - first_id;
527
524
}
528
525
}
529
526
530
527
return last_id - first_id;
531
528
}
532
529
533
- t_edge_size t_rr_graph_storage::num_non_configurable_edges (const RRNodeId& id) const {
534
- return num_edges (id) - num_configurable_edges (id);
530
+ t_edge_size t_rr_graph_storage::num_non_configurable_edges (RRNodeId node, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
531
+ return num_edges (node) - num_configurable_edges (node, rr_switches);
532
+ }
533
+
534
+ bool t_rr_graph_storage::edge_is_configurable (RRNodeId id, t_edge_size iedge, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
535
+ auto iswitch = edge_switch (id, iedge);
536
+ return rr_switches[RRSwitchId (iswitch)].configurable ();
537
+ }
538
+
539
+ bool t_rr_graph_storage::validate_node (RRNodeId node_id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
540
+ t_edge_size iedge = 0 ;
541
+ for (auto edge : edges (node_id)) {
542
+ if (edge < num_configurable_edges (node_id, rr_switches)) {
543
+ if (!edge_is_configurable (node_id, edge, rr_switches)) {
544
+ VTR_LOG_ERROR (" RR Node non-configurable edge found in configurable edge list" );
545
+ }
546
+ } else {
547
+ if (edge_is_configurable (node_id, edge, rr_switches)) {
548
+ VTR_LOG_ERROR (" RR Node configurable edge found in non-configurable edge list" );
549
+ }
550
+ }
551
+ ++iedge;
552
+ }
553
+
554
+ if (iedge != num_edges (node_id)) {
555
+ VTR_LOG_ERROR (" RR Node Edge iteration does not match edge size" );
556
+ }
557
+
558
+ return true ;
535
559
}
536
560
537
- bool t_rr_graph_storage::validate () const {
561
+ bool t_rr_graph_storage::validate (const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches ) const {
538
562
bool all_valid = verify_first_edges ();
539
563
for (size_t inode = 0 ; inode < size (); ++inode) {
540
- all_valid = (* this )[inode]. validate ( ) || all_valid;
564
+ all_valid = validate_node ( RRNodeId (inode), rr_switches ) || all_valid;
541
565
}
542
566
return all_valid;
543
567
}
@@ -567,37 +591,26 @@ const char* t_rr_graph_storage::node_side_string(RRNodeId id) const {
567
591
return SIDE_STRING[NUM_SIDES];
568
592
}
569
593
570
- float t_rr_graph_storage::node_R (RRNodeId id) const {
571
- auto & device_ctx = g_vpr_ctx.device ();
572
- return device_ctx.rr_rc_data [node_rc_index (id)].R ;
573
- }
574
-
575
- float t_rr_graph_storage::node_C (RRNodeId id) const {
576
- auto & device_ctx = g_vpr_ctx.device ();
577
- VTR_ASSERT (node_rc_index (id) < (short )device_ctx.rr_rc_data .size ());
578
- return device_ctx.rr_rc_data [node_rc_index (id)].C ;
579
- }
580
-
581
594
void t_rr_graph_storage::set_node_ptc_num (RRNodeId id, short new_ptc_num) {
582
595
node_ptc_[id].ptc_ .pin_num = new_ptc_num; // TODO: eventually remove
583
596
}
584
597
void t_rr_graph_storage::set_node_pin_num (RRNodeId id, short new_pin_num) {
585
598
if (node_type (id) != IPIN && node_type (id) != OPIN) {
586
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to set RR node 'pin_num' for non-IPIN/OPIN type '%s'" , node_type_string (id));
599
+ VTR_LOG_ERROR ( " Attempted to set RR node 'pin_num' for non-IPIN/OPIN type '%s'" , node_type_string (id));
587
600
}
588
601
node_ptc_[id].ptc_ .pin_num = new_pin_num;
589
602
}
590
603
591
604
void t_rr_graph_storage::set_node_track_num (RRNodeId id, short new_track_num) {
592
605
if (node_type (id) != CHANX && node_type (id) != CHANY) {
593
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to set RR node 'track_num' for non-CHANX/CHANY type '%s'" , node_type_string (id));
606
+ VTR_LOG_ERROR ( " Attempted to set RR node 'track_num' for non-CHANX/CHANY type '%s'" , node_type_string (id));
594
607
}
595
608
node_ptc_[id].ptc_ .track_num = new_track_num;
596
609
}
597
610
598
611
void t_rr_graph_storage::set_node_class_num (RRNodeId id, short new_class_num) {
599
612
if (node_type (id) != SOURCE && node_type (id) != SINK) {
600
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to set RR node 'class_num' for non-SOURCE/SINK type '%s'" , node_type_string (id));
613
+ VTR_LOG_ERROR ( " Attempted to set RR node 'class_num' for non-SOURCE/SINK type '%s'" , node_type_string (id));
601
614
}
602
615
node_ptc_[id].ptc_ .class_num = new_class_num;
603
616
}
@@ -612,7 +625,7 @@ static short get_node_pin_num(
612
625
RRNodeId id) {
613
626
auto node_type = node_storage[id].type_ ;
614
627
if (node_type != IPIN && node_type != OPIN) {
615
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to access RR node 'pin_num' for non-IPIN/OPIN type '%s'" , rr_node_typename[node_type]);
628
+ VTR_LOG_ERROR ( " Attempted to access RR node 'pin_num' for non-IPIN/OPIN type '%s'" , rr_node_typename[node_type]);
616
629
}
617
630
return node_ptc[id].ptc_ .pin_num ;
618
631
}
@@ -623,7 +636,7 @@ static short get_node_track_num(
623
636
RRNodeId id) {
624
637
auto node_type = node_storage[id].type_ ;
625
638
if (node_type != CHANX && node_type != CHANY) {
626
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to access RR node 'track_num' for non-CHANX/CHANY type '%s'" , rr_node_typename[node_type]);
639
+ VTR_LOG_ERROR ( " Attempted to access RR node 'track_num' for non-CHANX/CHANY type '%s'" , rr_node_typename[node_type]);
627
640
}
628
641
return node_ptc[id].ptc_ .track_num ;
629
642
}
@@ -634,7 +647,7 @@ static short get_node_class_num(
634
647
RRNodeId id) {
635
648
auto node_type = node_storage[id].type_ ;
636
649
if (node_type != SOURCE && node_type != SINK) {
637
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to access RR node 'class_num' for non-SOURCE/SINK type '%s'" , rr_node_typename[node_type]);
650
+ VTR_LOG_ERROR ( " Attempted to access RR node 'class_num' for non-SOURCE/SINK type '%s'" , rr_node_typename[node_type]);
638
651
}
639
652
return node_ptc[id].ptc_ .class_num ;
640
653
}
@@ -684,8 +697,8 @@ void t_rr_graph_storage::set_node_coordinates(RRNodeId id, short x1, short y1, s
684
697
void t_rr_graph_storage::set_node_cost_index (RRNodeId id, RRIndexedDataId new_cost_index) {
685
698
auto & node = node_storage_[id];
686
699
if ((size_t )new_cost_index >= std::numeric_limits<decltype (node.cost_index_ )>::max ()) {
687
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to set cost_index_ %zu above cost_index storage max value." ,
688
- new_cost_index);
700
+ VTR_LOG_ERROR ( " Attempted to set cost_index_ %zu above cost_index storage max value." ,
701
+ new_cost_index);
689
702
}
690
703
node.cost_index_ = (size_t )new_cost_index;
691
704
}
@@ -701,19 +714,19 @@ void t_rr_graph_storage::set_node_capacity(RRNodeId id, short new_capacity) {
701
714
702
715
void t_rr_graph_storage::set_node_direction (RRNodeId id, Direction new_direction) {
703
716
if (node_type (id) != CHANX && node_type (id) != CHANY) {
704
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to set RR node 'direction' for non-channel type '%s'" , node_type_string (id));
717
+ VTR_LOG_ERROR ( " Attempted to set RR node 'direction' for non-channel type '%s'" , node_type_string (id));
705
718
}
706
719
node_storage_[id].dir_side_ .direction = new_direction;
707
720
}
708
721
709
722
void t_rr_graph_storage::add_node_side (RRNodeId id, e_side new_side) {
710
723
if (node_type (id) != IPIN && node_type (id) != OPIN) {
711
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Attempted to set RR node 'side' for non-channel type '%s'" , node_type_string (id));
724
+ VTR_LOG_ERROR ( " Attempted to set RR node 'side' for non-channel type '%s'" , node_type_string (id));
712
725
}
713
726
std::bitset<NUM_SIDES> side_bits = node_storage_[id].dir_side_ .sides ;
714
727
side_bits[size_t (new_side)] = true ;
715
728
if (side_bits.to_ulong () > CHAR_MAX) {
716
- VPR_FATAL_ERROR (VPR_ERROR_ROUTE, " Invalid side '%s' to be added to rr node %u" , SIDE_STRING[new_side], size_t (id));
729
+ VTR_LOG_ERROR ( " Invalid side '%s' to be added to rr node %u" , SIDE_STRING[new_side], size_t (id));
717
730
}
718
731
node_storage_[id].dir_side_ .sides = static_cast <unsigned char >(side_bits.to_ulong ());
719
732
}
@@ -760,7 +773,6 @@ t_rr_graph_view t_rr_graph_storage::view() const {
760
773
// should generally be called before creating such references.
761
774
void t_rr_graph_storage::reorder (const vtr::vector<RRNodeId, RRNodeId>& order,
762
775
const vtr::vector<RRNodeId, RRNodeId>& inverse_order) {
763
- VTR_ASSERT_SAFE (validate ());
764
776
VTR_ASSERT (order.size () == inverse_order.size ());
765
777
{
766
778
auto old_node_storage = node_storage_;
@@ -805,6 +817,4 @@ void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
805
817
node_fan_in_[order[RRNodeId (i)]] = old_node_fan_in[RRNodeId (i)];
806
818
}
807
819
}
808
-
809
- VTR_ASSERT_SAFE (validate ());
810
820
}
0 commit comments