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

Data structure rr_node_metadata/rr_edge_metadata owner change #1952

merged 3 commits into from
Feb 4, 2022

Conversation

Raza-jafari-RS
Copy link
Contributor

Description

In this PR the owner of data structures rr_node_metadata/rr_edge_metadata has been changed from device_ctx to rr_graph_builder.

Related Issue

The metadata is an internal data structure used in rr_graph_builder so it should be part of this class

Motivation and Context

These changes are continuation of reorder_nodes function location change

How Has This Been Tested?

Types of changes

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

@github-actions github-actions bot added the VPR VPR FPGA Placement & Routing Tool label Jan 11, 2022
Copy link
Contributor

@tangxifan tangxifan left a comment

Choose a reason for hiding this comment

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

@Raza-jafari-RS Some comments to address. Thanks for the hard working. We are getting close. If you have any questions, feel free to reach out to me.

@@ -149,6 +149,25 @@ struct DeviceContext : public Context {
*/
t_rr_graph_storage rr_nodes; // autogenerated in build_rr_graph

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments are related to metadata. They should be moved to RRGraphBuilder and RRGraphView
These dead codes should be removed once this PR is ready to merge.

inline void rr_node_metadata_clear() {
rr_node_metadata_.clear();
}
inline void rr_edge_metadata_clear() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Our naming convention is clear_rr_edge_metadata()

return rr_node_metadata_.size();
}

//rr_node_metadata_find
Copy link
Contributor

Choose a reason for hiding this comment

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

Templates should not be placed with regular APIs. My suggestion is to move to the head of a class definition.
See example:

public: /* Types */
/* Iterators used to create iterator-based loop for nodes/edges/switches/segments */
typedef vtr::vector<RRNodeId, RRNodeId>::const_iterator node_iterator;
typedef vtr::vector<RREdgeId, RREdgeId>::const_iterator edge_iterator;
typedef vtr::vector<RRSwitchId, RRSwitchId>::const_iterator switch_iterator;
typedef vtr::vector<RRSegmentId, RRSegmentId>::const_iterator segment_iterator;
/* Ranges used to create range-based loop for nodes/edges/switches/segments */
typedef vtr::Range<node_iterator> node_range;
typedef vtr::Range<edge_iterator> edge_range;
typedef vtr::Range<switch_iterator> switch_range;
typedef vtr::Range<segment_iterator> segment_range;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I make the template as a class template over the RR_graph_builder.h as it is on the metadata_storage.h. Almost all the API's in the class become unknown to the locations where they have been used. Should I make the changes in all the API's or I am doing some thing wrong as I am not worked much with the templates.

template<typename LookupKey>
class MetadataStorage {

Please guide me how to resolve this issue.

@@ -1367,9 +1367,9 @@ void free_rr_graph() {

device_ctx.switch_fanin_remap.clear();

device_ctx.rr_node_metadata.clear();
device_ctx.rr_graph_builder.rr_node_metadata_clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to

  • Convert the rr_node_metadata_clear() and rr_edge_metadata_clear() function to private.
  • Call these clear functions in the clear() API of RRGraphBuilder

Then, here you just need to call device_ctx.rr_graph_builder.clear()

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 have called the rr_node_metadata_.clear() inside the RRGraphBuilder::clear. I have done this following the convention used for node_loopup_.clear()
https://github.com/RapidSilicon/vtr-verilog-to-routing/blob/05dd5c00e92c2cd0ff958f750be9318a05973a2c/vpr/src/device/rr_graph_builder.cpp#L62-L66

@@ -72,8 +72,8 @@ void load_rr_file(const t_graph_type graph_type,
device_ctx.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_node_metadata.add_metadata(src_node,
key,
value);
device_ctx.rr_graph_builder.rr_node_metadata_add_metadata(src_node,
Copy link
Contributor

Choose a reason for hiding this comment

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

In principle, we should not reinvent the wheel. The ideal way is

device_ctx.rr_graph_builder.rr_node_metadata().add_metadata(..)

I remember you mentioned it caused some errors in compilation. If so, I am o.k. for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API rr_node_metadata_add_metadata has been removed and the add_metadata has been called as the prescribed method.


//rr_node_metadata_find
template<typename LookupKey>
inline typename vtr::flat_map<LookupKey, t_metadata_dict>::const_iterator rr_node_metadata_find(const LookupKey& lookup_key) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am reading the codes about rr_metadata at

const t_metadata_value* rr_node_metadata(int src_node, vtr::interned_string key);
void add_rr_node_metadata(int src_node, vtr::interned_string key, vtr::interned_string value);
void add_rr_node_metadata(int src_node, vtr::string_view key, vtr::string_view value);
const t_metadata_value* rr_edge_metadata(int src_node, int sink_node, short switch_id, vtr::interned_string key);
void add_rr_edge_metadata(int src_node, int sink_node, short switch_id, vtr::interned_string key, vtr::interned_string value);
void add_rr_edge_metadata(int src_node, int sink_node, short switch_id, vtr::string_view key, vtr::string_view value);

It does not include templates, can you explain more details why you want to include templates?
In general, we try to avoid it because it may slow down the runtime.

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 have created API's for the functions in metadata_storage.h and there a class template has been used.

typename vtr::flat_map<LookupKey, t_metadata_dict>::const_iterator find(const LookupKey& lookup_key) const {

Inorder to pass the values to the template I am using the function template.


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! */

Copy link
Contributor

@tangxifan tangxifan left a comment

Choose a reason for hiding this comment

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

@Raza-jafari-RS Thanks for the efforts. We are almost there.

@@ -40,6 +38,37 @@ 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();
/** @brief Return a writable object for 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.

Slight modification on the comments

/** @brief Return a writable object for the meta data on the nodes */

@@ -403,6 +405,14 @@ class RRGraphView {
return 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

@@ -72,8 +72,8 @@ void load_rr_file(const t_graph_type graph_type,
device_ctx.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.

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

Copy link
Contributor

@tangxifan tangxifan left a comment

Choose a reason for hiding this comment

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

Changes are clear. Please start QoR tests.

@tangxifan
Copy link
Contributor

@Raza-jafari-RS I have merged #1951 Please resolve the merging conflicts here. This PR is almost there. I am waiting for the QoR test results.

@Raza-jafari-RS
Copy link
Contributor Author

@tangxifan ,
Sorry for the delay, Actually the master was updated and to resolve conflicts i made changes which caused a bit mess and I have to redo the work. I will upload the qor test by tomorrow.

@tangxifan
Copy link
Contributor

@tangxifan , Sorry for the delay, Actually the master was updated and to resolve conflicts i made changes which caused a bit mess and I have to redo the work. I will upload the qor test by tomorrow.

O.K. No problem.

@tangxifan
Copy link
Contributor

@Raza-jafari-RS Waiting for QoR test results. Code changes are good. I expect CI to be green soon

@Raza-jafari-RS
Copy link
Contributor Author

QoR tests are complete and quick summary is given below. QoR comparison files are also attached.

vtr_reg_qor_chain_depop test:
Flow run time -9.09 % on average
critical path delay 0 % on average.
Peak memory usage 0.02 % on average
titan_quick_qor test:
Flow run time -15.01 % on average
critical path delay 0 % on average.
Peak memory usage 1.47 % on average

vtr_reg_qor_chain_depop.xlsx
titan_quick_qor.xlsx

@tangxifan
Copy link
Contributor

@Raza-jafari-RS Thanks for the input and great work

@vaughnbetz I propose to merge this PR as the code changes are clean and QoR results should no degradation.
Feel free to comment. We will address any issues in future PRs.

@tangxifan tangxifan merged commit 81b5aa2 into verilog-to-routing:master Feb 4, 2022
@tangxifan tangxifan deleted the metadata branch February 4, 2022 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants