Skip to content

Commit f6fb051

Browse files
committed
Calculate segment indices and sizes in x-y axis seprately based on segment_inf_x/y vectors in RRGraphSerializer
1 parent 5a6249a commit f6fb051

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
325325
, is_flat_(is_flat) {
326326
// Initialize internal data
327327
init_side_map();
328+
init_segment_inf_x_y();
328329
}
329330

330331
/* A truth table to help understand the conversion from VPR side mask to uxsd side code
@@ -381,6 +382,40 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
381382
side_map_[(1 << TOP) | (1 << RIGHT) | (1 << BOTTOM) | (1 << LEFT)] = uxsd::enum_loc_side::TOP_RIGHT_BOTTOM_LEFT;
382383
}
383384

385+
void init_segment_inf_x_y(){
386+
/* Create a temp copy to convert from vtr::vector to std::vector
387+
* This is required because the ``alloc_and_load_rr_indexed_data()`` function supports only std::vector data
388+
* type for ``rr_segments``
389+
* Note that this is a dirty fix (to avoid massive code changes)
390+
* TODO: The ``alloc_and_load_rr_indexed_data()`` function should embrace ``vtr::vector`` for ``rr_segments``
391+
*/
392+
std::vector<t_segment_inf> rr_segs;
393+
rr_segs.reserve(segment_inf_.size());
394+
for (auto& rr_seg : segment_inf_) {
395+
rr_segs.push_back(rr_seg);
396+
}
397+
398+
t_unified_to_parallel_seg_index seg_index_map;
399+
segment_inf_x_ = get_parallel_segs(rr_segs, seg_index_map, X_AXIS);
400+
segment_inf_y_ = get_parallel_segs(rr_segs, seg_index_map, Y_AXIS);
401+
402+
}
403+
404+
int find_segment_index_along_axis(int seg_index, e_parallel_axis axis) const {
405+
const std::vector<t_segment_inf>* segment_inf_vec_ptr;
406+
407+
if (axis == X_AXIS)
408+
segment_inf_vec_ptr = &segment_inf_x_;
409+
else
410+
segment_inf_vec_ptr = &segment_inf_y_;
411+
412+
for(std::vector<t_segment_inf>::size_type i=0; i < (*segment_inf_vec_ptr).size(); i++){
413+
if((*segment_inf_vec_ptr)[i].seg_index == seg_index)
414+
return static_cast<int>(i);
415+
}
416+
return 0;
417+
}
418+
384419
public:
385420
void start_load(const std::function<void(const char*)>* report_error_in) final {
386421
// report_error_in should be invoked if RrGraphSerializer encounters
@@ -748,10 +783,12 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
748783
if (GRAPH_GLOBAL == graph_type_) {
749784
rr_graph_builder_->set_node_cost_index(node_id, RRIndexedDataId(0));
750785
} else if (rr_graph.node_type(node.id()) == CHANX) {
751-
rr_graph_builder_->set_node_cost_index(node_id, RRIndexedDataId(CHANX_COST_INDEX_START + segment_id));
786+
int seg_ind_x = find_segment_index_along_axis(segment_id, X_AXIS);
787+
rr_graph_builder_->set_node_cost_index(node_id, RRIndexedDataId(CHANX_COST_INDEX_START + seg_ind_x));
752788
seg_index_[rr_graph.node_cost_index(node.id())] = segment_id;
753789
} else if (rr_graph.node_type(node.id()) == CHANY) {
754-
rr_graph_builder_->set_node_cost_index(node_id, RRIndexedDataId(CHANX_COST_INDEX_START + segment_inf_.size() + segment_id));
790+
int seg_ind_y = find_segment_index_along_axis(segment_id, Y_AXIS);
791+
rr_graph_builder_->set_node_cost_index(node_id, RRIndexedDataId(CHANX_COST_INDEX_START + segment_inf_x_.size() + seg_ind_y));
755792
seg_index_[rr_graph.node_cost_index(node.id())] = segment_id;
756793
}
757794
return inode;
@@ -884,7 +921,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
884921

885922
inline void* init_rr_graph_rr_nodes(void*& /*ctx*/) final {
886923
rr_nodes_->clear();
887-
seg_index_.resize(CHANX_COST_INDEX_START + 2 * segment_inf_.size(), -1);
924+
seg_index_.resize(CHANX_COST_INDEX_START + segment_inf_x_.size() + segment_inf_y_.size(), -1);
888925
return nullptr;
889926
}
890927
inline void finish_rr_graph_rr_nodes(void*& /*ctx*/) final {
@@ -1612,22 +1649,13 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
16121649
process_rr_node_indices();
16131650

16141651
rr_graph_builder_->init_fan_in();
1615-
/* Create a temp copy to convert from vtr::vector to std::vector
1616-
* This is required because the ``alloc_and_load_rr_indexed_data()`` function supports only std::vector data
1617-
* type for ``rr_segments``
1618-
* Note that this is a dirty fix (to avoid massive code changes)
1619-
* TODO: The ``alloc_and_load_rr_indexed_data()`` function should embrace ``vtr::vector`` for ``rr_segments``
1620-
*/
1652+
16211653
std::vector<t_segment_inf> temp_rr_segs;
16221654
temp_rr_segs.reserve(segment_inf_.size());
16231655
for (auto& rr_seg : segment_inf_) {
16241656
temp_rr_segs.push_back(rr_seg);
16251657
}
16261658

1627-
t_unified_to_parallel_seg_index seg_index_map;
1628-
auto segment_inf_x_ = get_parallel_segs(temp_rr_segs, seg_index_map, X_AXIS);
1629-
auto segment_inf_y_ = get_parallel_segs(temp_rr_segs, seg_index_map, Y_AXIS);
1630-
16311659
alloc_and_load_rr_indexed_data(
16321660
*rr_graph_,
16331661
grid_,
@@ -1972,6 +2000,8 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
19722000
* the methods following routines:rr_graph_rr_nodes and init_node_segment according to the changes in
19732001
* rr_graph_indexed_data.cpp */
19742002
const vtr::vector<RRSegmentId, t_segment_inf>& segment_inf_;
2003+
std::vector<t_segment_inf> segment_inf_x_;
2004+
std::vector<t_segment_inf> segment_inf_y_;
19752005
const std::vector<t_physical_tile_type>& physical_tile_types_;
19762006
const DeviceGrid& grid_;
19772007
MetadataStorage<int>* rr_node_metadata_;

0 commit comments

Comments
 (0)