Skip to content

Data structure rr_node_metadata/rr_edge_metadata owner change #1952

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 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,19 @@ struct DeviceContext : public Context {
/* A writeable view of routing resource graph to be the ONLY database
* for routing resource graph builder functions.
*/
RRGraphBuilder rr_graph_builder{&rr_nodes, &rr_node_metadata, &rr_edge_metadata};
RRGraphBuilder rr_graph_builder{&rr_nodes};

/* A read-only view of routing resource graph to be the ONLY database
* for client functions: GUI, placer, router, timing analyzer etc.
*/
RRGraphView rr_graph{rr_nodes, rr_graph_builder.node_lookup(), rr_indexed_data, rr_graph_builder.rr_segments(), rr_graph_builder.rr_switch()};
RRGraphView rr_graph{rr_nodes,
rr_graph_builder.node_lookup(),
rr_graph_builder.rr_node_metadata(),
rr_graph_builder.rr_edge_metadata(),
rr_indexed_data,
rr_graph_builder.rr_segments(),
rr_graph_builder.rr_switch()};

int num_arch_switches;
t_arch_switch_inf* arch_switch_inf; // [0..(num_arch_switches-1)]

Expand All @@ -188,25 +195,6 @@ struct DeviceContext : public Context {
*/
int virtual_clock_network_root_idx;

/**
* @brief Attributes for each rr_node.
*
* key: rr_node index
* value: map of <attribute_name, attribute_value>
*/
MetadataStorage<int> rr_node_metadata;
/**
* @brief Attributes for each rr_edge
*
* key: <source rr_node_index, sink rr_node_index, iswitch>
* iswitch: Index of the switch type used to go from this rr_node to
* the next one in the routing. OPEN if there is no next node
* (i.e. this node is the last one (a SINK) in a branch of the
* net's routing).
* value: map of <attribute_name, attribute_value>
*/
MetadataStorage<std::tuple<int, int, short>> rr_edge_metadata;

/**
* @brief switch_fanin_remap is only used for printing out switch fanin stats
* (the -switch_stats option)
Expand Down
22 changes: 14 additions & 8 deletions vpr/src/device/rr_graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@

//#include "globals.h"

RRGraphBuilder::RRGraphBuilder(t_rr_graph_storage* node_storage,
MetadataStorage<int>* rr_node_metadata,
MetadataStorage<std::tuple<int, int, short>>* rr_edge_metadata)
: node_storage_(*node_storage)
, rr_node_metadata_(*rr_node_metadata)
, rr_edge_metadata_(*rr_edge_metadata) {
RRGraphBuilder::RRGraphBuilder(t_rr_graph_storage* node_storage)
: node_storage_(*node_storage) {
}

t_rr_graph_storage& RRGraphBuilder::node_storage() {
Expand All @@ -23,6 +19,14 @@ RRSpatialLookup& RRGraphBuilder::node_lookup() {
return node_lookup_;
}

MetadataStorage<int>& RRGraphBuilder::rr_node_metadata() {
return rr_node_metadata_;
}

MetadataStorage<std::tuple<int, int, short>>& RRGraphBuilder::rr_edge_metadata() {
return rr_edge_metadata_;
}

void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
t_rr_type node_type = node_storage_.node_type(node);
short node_ptc_num = node_storage_.node_ptc_num(node);
Expand Down Expand Up @@ -59,6 +63,8 @@ void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {

void RRGraphBuilder::clear() {
node_lookup_.clear();
rr_node_metadata_.clear();
rr_edge_metadata_.clear();
rr_segments_.clear();
rr_switch_inf_.clear();
}
Expand Down Expand Up @@ -123,8 +129,8 @@ void RRGraphBuilder::reorder_nodes(e_rr_node_reorder_algorithm reorder_rr_graph_

node_lookup().reorder(dest_order);

rr_node_metadata_.remap_keys([&](int node) { return size_t(dest_order[RRNodeId(node)]); });
rr_edge_metadata_.remap_keys([&](std::tuple<int, int, short> edge) {
rr_node_metadata().remap_keys([&](int node) { return size_t(dest_order[RRNodeId(node)]); });
rr_edge_metadata().remap_keys([&](std::tuple<int, int, short> edge) {
return std::make_tuple(size_t(dest_order[RRNodeId(std::get<0>(edge))]),
size_t(dest_order[RRNodeId(std::get<1>(edge))]),
std::get<2>(edge));
Expand Down
59 changes: 53 additions & 6 deletions vpr/src/device/rr_graph_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class RRGraphBuilder {
/* -- Constructors -- */
public:
/* See detailed comments about the data structures in the internal data storage section of this file */
RRGraphBuilder(t_rr_graph_storage* node_storage,
MetadataStorage<int>* rr_node_metadata,
MetadataStorage<std::tuple<int, int, short>>* rr_edge_metadata);
RRGraphBuilder(t_rr_graph_storage* node_storage);

/* Disable copy constructors and copy assignment operator
* This is to avoid accidental copy because it could be an expensive operation considering that the
Expand All @@ -40,6 +38,38 @@ class RRGraphBuilder {
t_rr_graph_storage& node_storage();
/** @brief Return a writable object for update the fast look-up of rr_node */
RRSpatialLookup& node_lookup();
/** .. warning:: The Metadata should stay as an independent data structure than rest of the internal data,
* e.g., node_lookup! */
/** @brief Return a writable object for the meta data on the nodes */
MetadataStorage<int>& rr_node_metadata();
/** @brief Return a writable object for the meta data on the edge */
MetadataStorage<std::tuple<int, int, short>>& rr_edge_metadata();

/** @brief Return the size for rr_node_metadata */
inline size_t rr_node_metadata_size() const {
return rr_node_metadata_.size();
}
/** @brief Return the size for rr_edge_metadata */
inline size_t rr_edge_metadata_size() const {
return rr_edge_metadata_.size();
}
/** @brief Find the node in rr_node_metadata */
inline vtr::flat_map<int, t_metadata_dict>::const_iterator find_rr_node_metadata(const int& lookup_key) const {
return rr_node_metadata_.find(lookup_key);
}
/** @brief Find the edge in rr_edge_metadata */
inline vtr::flat_map<std::tuple<int, int, short int>, t_metadata_dict>::const_iterator find_rr_edge_metadata(const std::tuple<int, int, short int>& lookup_key) const {
return rr_edge_metadata_.find(lookup_key);
}
/** @brief Return the last node in rr_node_metadata */
inline vtr::flat_map<int, t_metadata_dict>::const_iterator end_rr_node_metadata() const {
return rr_node_metadata_.end();
}

/** @brief Return the last edge in rr_edge_metadata */
inline vtr::flat_map<std::tuple<int, int, short int>, t_metadata_dict>::const_iterator end_rr_edge_metadata() const {
return rr_edge_metadata_.end();
}

/** @brief Add a rr_segment to the routing resource graph. Return an valid id if successful.
* - Each rr_segment contains the detailed information of a routing track, which is denoted by a node in CHANX or CHANY type.
Expand Down Expand Up @@ -304,13 +334,30 @@ class RRGraphBuilder {
/* Detailed information about the switches, which are used in the RRGraph */
vtr::vector<RRSwitchId, t_rr_switch_inf> rr_switch_inf_;

/** .. warning:: The Metadata should stay as an independent data structure than rest of the internal data,
* e.g., node_lookup! */
/* Metadata is an extra data on rr-nodes and edges, respectively, that is not used by vpr
* but simply passed through the flow so that it can be used by downstream tools.
* The main (perhaps only) current use of this metadata is the fasm tool of symbiflow,
* which needs extra metadata on which programming bits control which switch in order to produce a bitstream.*/

MetadataStorage<int>& rr_node_metadata_;
MetadataStorage<std::tuple<int, int, short>>& rr_edge_metadata_;
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a warning to the comments, in order to avoid any developers to merge the metadate into other internal data:

/** .. warning:: The Metadata should stay as an independent data structure than rest of the internal data, e.g., node_lookup! */

* @brief Attributes for each rr_node.
*
* key: rr_node index
* value: map of <attribute_name, attribute_value>
*/
MetadataStorage<int> rr_node_metadata_;
/**
* @brief Attributes for each rr_edge
*
* key: <source rr_node_index, sink rr_node_index, iswitch>
* iswitch: Index of the switch type used to go from this rr_node to
* the next one in the routing. OPEN if there is no next node
* (i.e. this node is the last one (a SINK) in a branch of the
* net's routing).
* value: map of <attribute_name, attribute_value>
*/
MetadataStorage<std::tuple<int, int, short>> rr_edge_metadata_;
};

#endif
10 changes: 9 additions & 1 deletion vpr/src/device/rr_graph_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
#include "rr_node.h"
#include "physical_types.h"

RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage, const RRSpatialLookup& node_lookup, const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switch_inf)
RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage,
const RRSpatialLookup& node_lookup,
const MetadataStorage<int>& rr_node_metadata,
const MetadataStorage<std::tuple<int, int, short>>& rr_edge_metadata,
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments,
const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switch_inf)
: node_storage_(node_storage)
, node_lookup_(node_lookup)
, rr_node_metadata_(rr_node_metadata)
, rr_edge_metadata_(rr_edge_metadata)
, rr_indexed_data_(rr_indexed_data)
, rr_segments_(rr_segments)
, rr_switch_inf_(rr_switch_inf) {
Expand Down
37 changes: 35 additions & 2 deletions vpr/src/device/rr_graph_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class RRGraphView {
/* See detailed comments about the data structures in the internal data storage section of this file */
RRGraphView(const t_rr_graph_storage& node_storage,
const RRSpatialLookup& node_lookup,
const MetadataStorage<int>& rr_node_metadata,
const MetadataStorage<std::tuple<int, int, short>>& rr_edge_metadata,
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments,
const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switch_inf);
Expand Down Expand Up @@ -419,6 +421,15 @@ class RRGraphView {
const RRSpatialLookup& node_lookup() const {
return node_lookup_;
}
/** .. warning:: The Metadata should stay as an independent data structure than rest of the internal data,
* e.g., node_lookup! */
MetadataStorage<int> rr_node_metadata_data() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add code comments

return rr_node_metadata_;
}

MetadataStorage<std::tuple<int, int, short>> rr_edge_metadata_data() const {
return rr_edge_metadata_;
}

/* -- Internal data storage -- */
/* Note: only read-only object or data structures are allowed!!! */
Expand All @@ -427,10 +438,32 @@ class RRGraphView {
const t_rr_graph_storage& node_storage_;
/* Fast look-up for rr nodes */
const RRSpatialLookup& node_lookup_;

/** .. warning:: The Metadata should stay as an independent data structure than rest of the internal data,
* e.g., node_lookup! */
/* Metadata is an extra data on rr-nodes and edges, respectively, that is not used by vpr
* but simply passed through the flow so that it can be used by downstream tools.
* The main (perhaps only) current use of this metadata is the fasm tool of symbiflow,
* which needs extra metadata on which programming bits control which switch in order to produce a bitstream.*/
/**
* @brief Attributes for each rr_node.
*
* key: rr_node index
* value: map of <attribute_name, attribute_value>
*/
const MetadataStorage<int>& rr_node_metadata_;
/**
* @brief Attributes for each rr_edge
*
* key: <source rr_node_index, sink rr_node_index, iswitch>
* iswitch: Index of the switch type used to go from this rr_node to
* the next one in the routing. OPEN if there is no next node
* (i.e. this node is the last one (a SINK) in a branch of the
* net's routing).
* value: map of <attribute_name, attribute_value>
*/
const MetadataStorage<std::tuple<int, int, short>>& rr_edge_metadata_;
/* rr_indexed_data_ and rr_segments_ are needed to lookup the segment information in node_coordinate_to_string() */
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data_;

/* Segment info for rr nodes */
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments_;
/* switch info for rr nodes */
Expand Down
4 changes: 0 additions & 4 deletions vpr/src/route/rr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,6 @@ void free_rr_graph() {

device_ctx.switch_fanin_remap.clear();

device_ctx.rr_node_metadata.clear();

device_ctx.rr_edge_metadata.clear();

invalidate_router_lookahead_cache();
}

Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/rr_graph_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void load_rr_file(const t_graph_type graph_type,
device_ctx.rr_graph.rr_segments(),
device_ctx.physical_tile_types,
grid,
&device_ctx.rr_node_metadata,
&device_ctx.rr_edge_metadata,
&device_ctx.rr_graph_builder.rr_node_metadata(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the two APIs rr_node_metadata() and rr_edge_metadata() already return reference, you may not need the & here. Please double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to remove the & operator here and it starts throwing error of "no known conversion for arguments" we have to make changes to the locations where this function is used. So should I go for the changings or keep it in the way as it is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is o.k. here. We may consider to change it later.

&device_ctx.rr_graph_builder.rr_edge_metadata(),
&device_ctx.arch->strings);

if (vtr::check_file_name_extension(read_rr_graph_name, ".xml")) {
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/rr_graph_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void write_rr_graph(const char* file_name) {
device_ctx.rr_graph.rr_segments(),
device_ctx.physical_tile_types,
device_ctx.grid,
&device_ctx.rr_node_metadata,
&device_ctx.rr_edge_metadata,
&device_ctx.rr_graph_builder.rr_node_metadata(),
&device_ctx.rr_graph_builder.rr_edge_metadata(),
&device_ctx.arch->strings);

if (vtr::check_file_name_extension(file_name, ".xml")) {
Expand Down
32 changes: 16 additions & 16 deletions vpr/src/route/rr_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ namespace vpr {
const t_metadata_value* rr_node_metadata(int src_node, vtr::interned_string key) {
auto& device_ctx = g_vpr_ctx.device();

auto iter = device_ctx.rr_node_metadata.find(src_node);
if (iter == device_ctx.rr_node_metadata.end()) {
auto iter = device_ctx.rr_graph_builder.find_rr_node_metadata(src_node);
if (iter == device_ctx.rr_graph_builder.end_rr_node_metadata()) {
return nullptr;
}
return iter->second.one(key);
}

void add_rr_node_metadata(int src_node, vtr::interned_string key, vtr::interned_string value) {
auto& device_ctx = g_vpr_ctx.mutable_device();
device_ctx.rr_node_metadata.add_metadata(src_node,
key,
value);
device_ctx.rr_graph_builder.rr_node_metadata().add_metadata(src_node,
key,
value);
}

void add_rr_node_metadata(int src_node, vtr::string_view key, vtr::string_view value) {
auto& device_ctx = g_vpr_ctx.mutable_device();
device_ctx.rr_node_metadata.add_metadata(src_node,
device_ctx.arch->strings.intern_string(key),
device_ctx.arch->strings.intern_string(value));
device_ctx.rr_graph_builder.rr_node_metadata().add_metadata(src_node,
device_ctx.arch->strings.intern_string(key),
device_ctx.arch->strings.intern_string(value));
}

const t_metadata_value* rr_edge_metadata(int src_node, int sink_id, short switch_id, vtr::interned_string key) {
const auto& device_ctx = g_vpr_ctx.device();
auto rr_edge = std::make_tuple(src_node, sink_id, switch_id);

auto iter = device_ctx.rr_edge_metadata.find(rr_edge);
if (iter == device_ctx.rr_edge_metadata.end()) {
auto iter = device_ctx.rr_graph_builder.find_rr_edge_metadata(rr_edge);
if (iter == device_ctx.rr_graph_builder.end_rr_edge_metadata()) {
return nullptr;
}

Expand All @@ -43,17 +43,17 @@ const t_metadata_value* rr_edge_metadata(int src_node, int sink_id, short switch
void add_rr_edge_metadata(int src_node, int sink_id, short switch_id, vtr::string_view key, vtr::string_view value) {
auto& device_ctx = g_vpr_ctx.mutable_device();
auto rr_edge = std::make_tuple(src_node, sink_id, switch_id);
device_ctx.rr_edge_metadata.add_metadata(rr_edge,
device_ctx.arch->strings.intern_string(key),
device_ctx.arch->strings.intern_string(value));
device_ctx.rr_graph_builder.rr_edge_metadata().add_metadata(rr_edge,
device_ctx.arch->strings.intern_string(key),
device_ctx.arch->strings.intern_string(value));
}

void add_rr_edge_metadata(int src_node, int sink_id, short switch_id, vtr::interned_string key, vtr::interned_string value) {
auto& device_ctx = g_vpr_ctx.mutable_device();
auto rr_edge = std::make_tuple(src_node, sink_id, switch_id);
device_ctx.rr_edge_metadata.add_metadata(rr_edge,
key,
value);
device_ctx.rr_graph_builder.rr_edge_metadata().add_metadata(rr_edge,
key,
value);
}

} // namespace vpr
8 changes: 4 additions & 4 deletions vpr/test/test_vpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ TEST_CASE("read_rr_graph_metadata", "[vpr]") {
std::mt19937 g(1);
std::shuffle(src_order.begin(), src_order.end(), g);

CHECK(device_ctx.rr_node_metadata.size() == 1);
CHECK(device_ctx.rr_edge_metadata.size() == 1);
CHECK(device_ctx.rr_graph_builder.rr_node_metadata_size() == 1);
CHECK(device_ctx.rr_graph_builder.rr_edge_metadata_size() == 1);

auto node = arch.strings.intern_string(vtr::string_view("node"));
auto edge = arch.strings.intern_string(vtr::string_view("edge"));

for (const auto& node_meta : device_ctx.rr_node_metadata) {
for (const auto& node_meta : device_ctx.rr_graph.rr_node_metadata_data()) {
CHECK(src_order[node_meta.first] == src_inode);
REQUIRE(node_meta.second.has(node));
auto* value = node_meta.second.one(node);
REQUIRE(value != nullptr);
CHECK_THAT(value->as_string().get(&arch.strings), Equals("test node"));
}

for (const auto& edge_meta : device_ctx.rr_edge_metadata) {
for (const auto& edge_meta : device_ctx.rr_graph.rr_edge_metadata_data()) {
CHECK(src_order[std::get<0>(edge_meta.first)] == src_inode);
CHECK(src_order[std::get<1>(edge_meta.first)] == sink_inode);
CHECK(std::get<2>(edge_meta.first) == switch_id);
Expand Down