Skip to content

enum class rr_type #3001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 28, 2025
Merged
6 changes: 6 additions & 0 deletions doc/src/api/vtrutil/containers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ vtr_vector
:project: vtr
:sections: briefdescription detaileddescription innernamespace innerclass public-func typedef func

vtr_array
----------
.. doxygenfile:: vtr_array.h
:project: vtr
:sections: briefdescription detaileddescription innernamespace innerclass public-func typedef func

vtr_small_vector
----------------
.. doxygenclass:: vtr::small_vector
Expand Down
116 changes: 54 additions & 62 deletions libs/librrgraph/src/base/check_rr_graph.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions libs/librrgraph/src/base/check_rr_graph_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool check_rr_graph_source_nodes(const RRGraph& rr_graph) {
*/
for (auto node : rr_graph.nodes()) {
/* Pass nodes whose types are not SOURCE */
if (SOURCE != rr_graph.node_type(node)) {
if (e_rr_type::SOURCE != rr_graph.node_type(node)) {
continue;
}
if ((0 != rr_graph.node_fan_in(node))
Expand Down Expand Up @@ -123,7 +123,7 @@ static bool check_rr_graph_sink_nodes(const RRGraph& rr_graph) {
*/
for (auto node : rr_graph.nodes()) {
/* Pass nodes whose types are not SINK */
if (SINK != rr_graph.node_type(node)) {
if (e_rr_type::SINK != rr_graph.node_type(node)) {
continue;
}
if ((0 == rr_graph.node_fan_in(node))
Expand Down
14 changes: 7 additions & 7 deletions libs/librrgraph/src/base/rr_graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MetadataStorage<std::tuple<int, int, short>>& RRGraphBuilder::rr_edge_metadata()
}

void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
t_rr_type node_type = node_storage_.node_type(node);
e_rr_type node_type = node_storage_.node_type(node);
short node_ptc_num = node_storage_.node_ptc_num(node);
short node_layer = node_storage_.node_layer(node);
short node_twist = node_storage_.node_ptc_twist(node);
Expand All @@ -36,20 +36,20 @@ void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
node_ptc_num += node_twist * node_offset;
node_offset++;
switch (node_type) {
case SOURCE:
case SINK:
case CHANY:
case e_rr_type::SOURCE:
case e_rr_type::SINK:
case e_rr_type::CHANY:
node_lookup_.add_node(node, node_layer, ix, iy, node_type, node_ptc_num, TOTAL_2D_SIDES[0]);
break;
case CHANX:
case e_rr_type::CHANX:
/* Currently need to swap x and y for CHANX because of chan, seg convention
* TODO: Once the builders is reworked for use consistent (x, y) convention,
* the following swapping can be removed
*/
node_lookup_.add_node(node, node_layer, iy, ix, node_type, node_ptc_num, TOTAL_2D_SIDES[0]);
break;
case OPIN:
case IPIN:
case e_rr_type::OPIN:
case e_rr_type::IPIN:
for (const e_side& side : TOTAL_2D_SIDES) {
if (node_storage_.is_node_on_specific_side(node, side)) {
node_lookup_.add_node(node,node_layer, ix, iy, node_type, node_ptc_num, side);
Expand Down
2 changes: 1 addition & 1 deletion libs/librrgraph/src/base/rr_graph_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class RRGraphBuilder {
}

/** @brief Set the type of a node with a given valid id */
inline void set_node_type(RRNodeId id, t_rr_type type) {
inline void set_node_type(RRNodeId id, e_rr_type type) {
node_storage_.set_node_type(id, type);
}

Expand Down
67 changes: 35 additions & 32 deletions libs/librrgraph/src/base/rr_graph_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RRGraph::segment_range RRGraph::segments() const {
}

//Node attributes
t_rr_type RRGraph::node_type(const RRNodeId& node) const {
e_rr_type RRGraph::node_type(const RRNodeId& node) const {
VTR_ASSERT_SAFE(valid_node_id(node));
return node_types_[node];
}
Expand Down Expand Up @@ -81,7 +81,7 @@ vtr::Rect<short> RRGraph::node_bounding_box(const RRNodeId& node) const {
***********************************************************************/
vtr::Point<short> RRGraph::node_start_coordinate(const RRNodeId& node) const {
/* Make sure we have CHANX or CHANY */
VTR_ASSERT((CHANX == node_type(node)) || (CHANY == node_type(node)));
VTR_ASSERT((e_rr_type::CHANX == node_type(node)) || (e_rr_type::CHANY == node_type(node)));

vtr::Point<short> start_coordinate(node_xlow(node), node_ylow(node));

Expand All @@ -105,7 +105,7 @@ vtr::Point<short> RRGraph::node_start_coordinate(const RRNodeId& node) const {
***********************************************************************/
vtr::Point<short> RRGraph::node_end_coordinate(const RRNodeId& node) const {
/* Make sure we have CHANX or CHANY */
VTR_ASSERT((CHANX == node_type(node)) || (CHANY == node_type(node)));
VTR_ASSERT((e_rr_type::CHANX == node_type(node)) || (e_rr_type::CHANY == node_type(node)));

vtr::Point<short> end_coordinate(node_xhigh(node), node_yhigh(node));

Expand Down Expand Up @@ -135,19 +135,19 @@ short RRGraph::node_ptc_num(const RRNodeId& node) const {
}

short RRGraph::node_pin_num(const RRNodeId& node) const {
VTR_ASSERT_MSG(node_type(node) == IPIN || node_type(node) == OPIN,
VTR_ASSERT_MSG(node_type(node) == e_rr_type::IPIN || node_type(node) == e_rr_type::OPIN,
"Pin number valid only for IPIN/OPIN RR nodes");
return node_ptc_num(node);
}

short RRGraph::node_track_num(const RRNodeId& node) const {
VTR_ASSERT_MSG(node_type(node) == CHANX || node_type(node) == CHANY,
VTR_ASSERT_MSG(node_type(node) == e_rr_type::CHANX || node_type(node) == e_rr_type::CHANY,
"Track number valid only for CHANX/CHANY RR nodes");
return node_ptc_num(node);
}

short RRGraph::node_class_num(const RRNodeId& node) const {
VTR_ASSERT_MSG(node_type(node) == SOURCE || node_type(node) == SINK, "Class number valid only for SOURCE/SINK RR nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::SOURCE || node_type(node) == e_rr_type::SINK, "Class number valid only for SOURCE/SINK RR nodes");
return node_ptc_num(node);
}

Expand All @@ -158,13 +158,13 @@ RRIndexedDataId RRGraph::node_cost_index(const RRNodeId& node) const {

Direction RRGraph::node_direction(const RRNodeId& node) const {
VTR_ASSERT_SAFE(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == CHANX || node_type(node) == CHANY, "Direction valid only for CHANX/CHANY RR nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::CHANX || node_type(node) == e_rr_type::CHANY, "Direction valid only for CHANX/CHANY RR nodes");
return node_directions_[node];
}

e_side RRGraph::node_side(const RRNodeId& node) const {
VTR_ASSERT_SAFE(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == IPIN || node_type(node) == OPIN, "Side valid only for IPIN/OPIN RR nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::IPIN || node_type(node) == e_rr_type::OPIN, "Side valid only for IPIN/OPIN RR nodes");
return node_sides_[node];
}

Expand Down Expand Up @@ -372,11 +372,11 @@ std::vector<RREdgeId> RRGraph::find_edges(const RRNodeId& src_node, const RRNode
return matching_edges;
}

RRNodeId RRGraph::find_node(const short& x, const short& y, const t_rr_type& type, const int& ptc, const e_side& side) const {
RRNodeId RRGraph::find_node(const short& x, const short& y, const e_rr_type type, const int& ptc, const e_side& side) const {
initialize_fast_node_lookup();

size_t itype = type;
size_t iside = side;
const size_t itype = (size_t)type;
const size_t iside = side;

/* Check if x, y, type and ptc, side is valid */
if ((x < 0) /* See if x is smaller than the index of first element */
Expand All @@ -401,14 +401,14 @@ RRNodeId RRGraph::find_node(const short& x, const short& y, const t_rr_type& typ

/* Check if x, y, type and ptc, side is valid */
if ((ptc < 0) /* See if ptc is smaller than the index of first element */
|| (size_t(ptc) > node_lookup_[x][y][type].size() - 1)) { /* See if ptc is large than the index of last element */
|| (size_t(ptc) > node_lookup_[x][y][itype].size() - 1)) { /* See if ptc is large than the index of last element */
/* Return a zero range! */
return RRNodeId::INVALID();
}

/* Check if x, y, type and ptc, side is valid */
/* iside is always larger than -1, we can skip checking */
if (iside > node_lookup_[x][y][type][ptc].size() - 1) { /* See if side is large than the index of last element */
if (iside > node_lookup_[x][y][itype][ptc].size() - 1) { /* See if side is large than the index of last element */
/* Return a zero range! */
return RRNodeId::INVALID();
}
Expand All @@ -417,9 +417,9 @@ RRNodeId RRGraph::find_node(const short& x, const short& y, const t_rr_type& typ
}

/* Find the channel width (number of tracks) of a channel [x][y] */
short RRGraph::chan_num_tracks(const short& x, const short& y, const t_rr_type& type) const {
short RRGraph::chan_num_tracks(const short& x, const short& y, const e_rr_type& type) const {
/* Must be CHANX or CHANY */
VTR_ASSERT_MSG(CHANX == type || CHANY == type,
VTR_ASSERT_MSG(e_rr_type::CHANX == type || e_rr_type::CHANY == type,
"Required node_type to be CHANX or CHANY!");
initialize_fast_node_lookup();

Expand All @@ -432,18 +432,18 @@ short RRGraph::chan_num_tracks(const short& x, const short& y, const t_rr_type&

/* Check if x, y, type and ptc is valid */
if ((y < 0) /* See if y is smaller than the index of first element */
|| (size_t(y) > node_lookup_[x].size() - 1)) { /* See if y is large than the index of last element */
|| (size_t(y) > node_lookup_[x].size() - 1)) { /* See if y is larger than the index of last element */
/* Return a zero range! */
return 0;
}

/* Check if x, y, type and ptc is valid */
if ((size_t(type) > node_lookup_[x][y].size() - 1)) { /* See if type is large than the index of last element */
if ((size_t(type) > node_lookup_[x][y].size() - 1)) { /* See if type is larger than the index of last element */
/* Return a zero range! */
return 0;
}

const auto& matching_nodes = node_lookup_[x][y][type];
const auto& matching_nodes = node_lookup_[x][y][(size_t)type];

return vtr::make_range(matching_nodes.begin(), matching_nodes.end()).size();
}
Expand All @@ -465,8 +465,8 @@ void RRGraph::print_node(const RRNodeId& node) const {
bool RRGraph::validate_node_segment(const RRNodeId& node) const {
VTR_ASSERT_SAFE(valid_node_id(node));
/* Only CHANX and CHANY requires a valid segment id */
if ((CHANX == node_type(node))
|| (CHANY == node_type(node))) {
if ((e_rr_type::CHANX == node_type(node))
|| (e_rr_type::CHANY == node_type(node))) {
return valid_segment_id(node_segments_[node]);
} else {
return true;
Expand All @@ -477,7 +477,7 @@ bool RRGraph::validate_node_segment(const RRNodeId& node) const {
bool RRGraph::validate_node_segments() const {
bool all_valid = true;
for (auto node : nodes()) {
if (true == validate_node_segment(node)) {
if (validate_node_segment(node)) {
continue;
}
/* Reach here it means we find an invalid segment id */
Expand All @@ -499,7 +499,7 @@ bool RRGraph::validate_edge_switch(const RREdgeId& edge) const {
bool RRGraph::validate_edge_switches() const {
bool all_valid = true;
for (auto edge : edges()) {
if (true == validate_edge_switch(edge)) {
if (validate_edge_switch(edge)) {
continue;
}
/* Reach here it means we find an invalid segment id */
Expand Down Expand Up @@ -798,7 +798,7 @@ void RRGraph::reserve_segments(const int& num_segments) {
}

/* Mutators */
RRNodeId RRGraph::create_node(const t_rr_type& type) {
RRNodeId RRGraph::create_node(const e_rr_type& type) {
//Allocate an ID
RRNodeId node_id = RRNodeId(node_ids_.size());

Expand Down Expand Up @@ -971,21 +971,24 @@ void RRGraph::set_node_ptc_num(const RRNodeId& node, const short& ptc) {

void RRGraph::set_node_pin_num(const RRNodeId& node, const short& pin_id) {
VTR_ASSERT(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == IPIN || node_type(node) == OPIN, "Pin number valid only for IPIN/OPIN RR nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::IPIN || node_type(node) == e_rr_type::OPIN,
"Pin number valid only for IPIN/OPIN RR nodes");

set_node_ptc_num(node, pin_id);
}

void RRGraph::set_node_track_num(const RRNodeId& node, const short& track_id) {
VTR_ASSERT(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == CHANX || node_type(node) == CHANY, "Track number valid only for CHANX/CHANY RR nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::CHANX || node_type(node) == e_rr_type::CHANY,
"Track number valid only for CHANX/CHANY RR nodes");

set_node_ptc_num(node, track_id);
}

void RRGraph::set_node_class_num(const RRNodeId& node, const short& class_id) {
VTR_ASSERT(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == SOURCE || node_type(node) == SINK, "Class number valid only for SOURCE/SINK RR nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::SOURCE || node_type(node) == e_rr_type::SINK,
"Class number valid only for SOURCE/SINK RR nodes");

set_node_ptc_num(node, class_id);
}
Expand All @@ -997,14 +1000,14 @@ void RRGraph::set_node_cost_index(const RRNodeId& node, const RRIndexedDataId& c

void RRGraph::set_node_direction(const RRNodeId& node, const Direction& direction) {
VTR_ASSERT(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == CHANX || node_type(node) == CHANY, "Direct can only be specified on CHANX/CNAY rr nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::CHANX || node_type(node) == e_rr_type::CHANY, "Direct can only be specified on CHANX/CNAY rr nodes");

node_directions_[node] = direction;
}

void RRGraph::set_node_side(const RRNodeId& node, const e_side& side) {
VTR_ASSERT(valid_node_id(node));
VTR_ASSERT_MSG(node_type(node) == IPIN || node_type(node) == OPIN, "Side can only be specified on IPIN/OPIN rr nodes");
VTR_ASSERT_MSG(node_type(node) == e_rr_type::IPIN || node_type(node) == e_rr_type::OPIN, "Side can only be specified on IPIN/OPIN rr nodes");

node_sides_[node] = side;
}
Expand All @@ -1028,8 +1031,8 @@ void RRGraph::set_node_segment(const RRNodeId& node, const RRSegmentId& segment_
VTR_ASSERT(valid_node_id(node));

/* Only CHANX and CHANY requires a valid segment id */
if ((CHANX == node_type(node))
|| (CHANY == node_type(node))) {
if ((e_rr_type::CHANX == node_type(node))
|| (e_rr_type::CHANY == node_type(node))) {
VTR_ASSERT(valid_segment_id(segment_id));
}

Expand Down Expand Up @@ -1119,7 +1122,7 @@ void RRGraph::build_fast_node_lookup() const {
node_lookup_[x].resize(y + 1);
}

size_t itype = node_type(node);
size_t itype = (size_t)node_type(node);
if (itype >= node_lookup_[x][y].size()) {
node_lookup_[x][y].resize(itype + 1);
}
Expand All @@ -1130,7 +1133,7 @@ void RRGraph::build_fast_node_lookup() const {
}

size_t iside = -1;
if (node_type(node) == OPIN || node_type(node) == IPIN) {
if (node_type(node) == e_rr_type::OPIN || node_type(node) == e_rr_type::IPIN) {
iside = node_side(node);
} else {
iside = NUM_2D_SIDES;
Expand Down
14 changes: 7 additions & 7 deletions libs/librrgraph/src/base/rr_graph_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* // Get the unique node id that you may get
* // from other data structures or functions
* RRNodeId node_id;
* t_rr_type node_type = rr_graph.node_type(node_id);
* e_rr_type node_type = rr_graph.node_type(node_id);
*
* // Access all the fan-out edges from a given node
* for (const RREdgeId& out_edge_id : rr_graph.node_out_edges(node_id)) {
Expand Down Expand Up @@ -257,9 +257,9 @@ class RRGraph {

/* get the type of a RRGraph node : types of each node, can be channel wires (CHANX or CHANY) or
* logic block pins(OPIN or IPIN) or virtual nodes (SOURCE or SINK)
* see t_rr_type definition for more details
* see e_rr_type definition for more details
*/
t_rr_type node_type(const RRNodeId& node) const;
e_rr_type node_type(const RRNodeId& node) const;

/* Get coordinate of a node. (xlow, xhigh, ylow, yhigh):
* For OPIN/IPIN/SOURCE/SINK, xlow = xhigh and ylow = yhigh
Expand Down Expand Up @@ -510,9 +510,9 @@ class RRGraph {
/* Find the edges connecting two nodes */
std::vector<RREdgeId> find_edges(const RRNodeId& src_node, const RRNodeId& sink_node) const;
/* Find a node with given features from internal fast look-up */
RRNodeId find_node(const short& x, const short& y, const t_rr_type& type, const int& ptc, const e_side& side = NUM_2D_SIDES) const;
RRNodeId find_node(const short& x, const short& y, const e_rr_type type, const int& ptc, const e_side& side = NUM_2D_SIDES) const;
/* Find the number of routing tracks in a routing channel with a given coordinate */
short chan_num_tracks(const short& x, const short& y, const t_rr_type& type) const;
short chan_num_tracks(const short& x, const short& y, const e_rr_type& type) const;

/* This flag is raised when the RRgraph contains invalid nodes/edges etc.
* Invalid nodes/edges exist when users remove nodes/edges from RRGraph
Expand Down Expand Up @@ -589,7 +589,7 @@ class RRGraph {
* RRNodeId node = create_node();
* set_node_xlow(node, 0);
*/
RRNodeId create_node(const t_rr_type& type);
RRNodeId create_node(const e_rr_type& type);
/* Add a edge to the RRGraph, by providing the source and sink node
* This function will automatically create a node and
* configure the nodes and edges in connection
Expand Down Expand Up @@ -782,7 +782,7 @@ class RRGraph {
private: /* Internal Data */
/* Node related data */
vtr::vector<RRNodeId, RRNodeId> node_ids_; /* Unique identifiers for the nodes */
vtr::vector<RRNodeId, t_rr_type> node_types_;
vtr::vector<RRNodeId, e_rr_type> node_types_;

vtr::vector<RRNodeId, vtr::Rect<short>> node_bounding_boxes_;

Expand Down
Loading