-
Notifications
You must be signed in to change notification settings - Fork 415
Override edge attributes in RR graph #2930
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
Changes from 7 commits
ff48e6b
5722c79
dc89abd
08538ff
3be8914
7c6a282
16870df
43bde82
ba2656d
03849e4
04e25e8
a648aab
4115a25
97da592
305c46e
1163f30
dbeec69
690244a
fb5ad75
ebf88f0
9b6d824
df627ce
4110acd
14b562e
010b0ac
7ce51f0
94e24be
9f06be2
5da6cf7
8c960f9
c71a2bc
eac8bfc
2ef555f
d390291
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
#include "rr_graph_uxsdcxx.h" | ||
|
||
#include <fstream> | ||
#include <unordered_set> | ||
|
||
#include "vtr_time.h" | ||
#include "pugixml.hpp" | ||
|
@@ -53,7 +54,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder, | |
int* wire_to_rr_ipin_switch, | ||
int* wire_to_rr_ipin_switch_between_dice, | ||
const char* read_rr_graph_name, | ||
std::string* read_rr_graph_filename, | ||
std::string* loaded_rr_graph_filename, | ||
bool read_edge_metadata, | ||
bool do_check_rr_graph, | ||
bool echo_enabled, | ||
|
@@ -74,7 +75,7 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder, | |
wire_to_rr_ipin_switch_between_dice, | ||
do_check_rr_graph, | ||
read_rr_graph_name, | ||
read_rr_graph_filename, | ||
loaded_rr_graph_filename, | ||
read_edge_metadata, | ||
echo_enabled, | ||
echo_file_name, | ||
|
@@ -115,3 +116,140 @@ void load_rr_file(RRGraphBuilder* rr_graph_builder, | |
read_rr_graph_name); | ||
} | ||
} | ||
|
||
RREdgeId process_line(const std::string& line, | ||
std::vector<float>& overridden_values, | ||
const RRGraphView& rr_graph) { | ||
std::istringstream iss(line); | ||
char ch; | ||
RREdgeId edge_id; | ||
|
||
if (std::isdigit(line[0])) { | ||
// Line starts with an integer | ||
int first; | ||
iss >> first; | ||
edge_id = (RREdgeId)first; | ||
soheilshahrouz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else if (line[0] == '(') { | ||
// Line starts with (first, second) | ||
int first, second; | ||
iss >> ch >> first >> ch >> second >> ch; | ||
|
||
RRNodeId src_node_id = RRNodeId(first); | ||
RRNodeId sink_node_id = RRNodeId(second); | ||
|
||
for (RREdgeId outgoing_edge_id : rr_graph.rr_nodes().edge_range(src_node_id)) { | ||
if (rr_graph.rr_nodes().edge_sink_node(outgoing_edge_id) == sink_node_id) { | ||
edge_id = outgoing_edge_id; | ||
break; | ||
} | ||
} | ||
|
||
if (!edge_id.is_valid()) { | ||
soheilshahrouz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VTR_LOG_ERROR("Couldn't find an edge connecting node %d to node %d\n", src_node_id, sink_node_id); | ||
} | ||
|
||
} else { | ||
VTR_LOG_ERROR("Invalid line format: %s\n", line.c_str()); | ||
} | ||
|
||
float value; | ||
while (iss >> value) { | ||
overridden_values.push_back(value); | ||
} | ||
|
||
return edge_id; | ||
} | ||
|
||
struct t_rr_switch_inf_hash { | ||
soheilshahrouz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::size_t operator()(const t_rr_switch_inf& s) const { | ||
std::size_t seed = 0; | ||
|
||
// Helper function for hashing | ||
auto hash_combine = [&seed](auto&& val) { | ||
seed ^= std::hash<std::decay_t<decltype(val)>>{}(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | ||
}; | ||
|
||
// Combine all relevant fields | ||
hash_combine(s.R); | ||
hash_combine(s.Cin); | ||
hash_combine(s.Cout); | ||
hash_combine(s.Cinternal); | ||
hash_combine(s.Tdel); | ||
hash_combine(s.mux_trans_size); | ||
hash_combine(s.buf_size); | ||
hash_combine(static_cast<int>(s.power_buffer_type)); | ||
hash_combine(s.power_buffer_size); | ||
hash_combine(s.intra_tile); | ||
hash_combine(static_cast<int>(s.type())); | ||
|
||
return seed; | ||
} | ||
}; | ||
|
||
struct t_rr_switch_inf_equal { | ||
soheilshahrouz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool operator()(const t_rr_switch_inf& lhs, const t_rr_switch_inf& rhs) const { | ||
return lhs.R == rhs.R && | ||
lhs.Cin == rhs.Cin && | ||
lhs.Cout == rhs.Cout && | ||
lhs.Cinternal == rhs.Cinternal && | ||
lhs.Tdel == rhs.Tdel && | ||
lhs.mux_trans_size == rhs.mux_trans_size && | ||
lhs.buf_size == rhs.buf_size && | ||
lhs.power_buffer_type == rhs.power_buffer_type && | ||
lhs.power_buffer_size == rhs.power_buffer_size && | ||
lhs.intra_tile == rhs.intra_tile && | ||
lhs.type() == rhs.type(); | ||
} | ||
}; | ||
|
||
void load_rr_edge_overrides(std::string_view filename, | ||
RRGraphBuilder& rr_graph_builder, | ||
const RRGraphView& rr_graph) { | ||
std::ifstream file(filename.data()); | ||
if (!file) { | ||
soheilshahrouz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VTR_LOG_ERROR("Failed to open the RR edge override file: %s\n", filename.data()); | ||
} | ||
|
||
std::unordered_map<t_rr_switch_inf, RRSwitchId, t_rr_switch_inf_hash, t_rr_switch_inf_equal> unique_switch_info; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also needed to do something similar when creating edges while collapsing RR Node chains in the flat router. If you could create an issue to remind me to implement a function for this, that would be helpful. |
||
for (const auto& [rr_sw_idx, sw] : rr_graph.rr_switch().pairs()) { | ||
unique_switch_info.insert({sw, rr_sw_idx}); | ||
} | ||
|
||
std::string line; | ||
std::vector<float> overridden_values; | ||
bool firstLine = true; | ||
|
||
while (std::getline(file, line)) { | ||
if (firstLine) { | ||
if (line.empty() || line[0] != '#') { | ||
VTR_LOG_ERROR("Error: First line must start with #\n"); | ||
soheilshahrouz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
firstLine = false; | ||
continue; // Ignore first line | ||
} | ||
|
||
|
||
if (!line.empty()) { | ||
overridden_values.clear(); | ||
RREdgeId edge_id = process_line(line, overridden_values, rr_graph); | ||
RRSwitchId curr_switch_id = (RRSwitchId)rr_graph.edge_switch(edge_id); | ||
t_rr_switch_inf switch_override_info = rr_graph.rr_switch_inf(curr_switch_id); | ||
|
||
switch_override_info.Tdel = (overridden_values.size() >= 1) ? overridden_values[0] : switch_override_info.Tdel; | ||
switch_override_info.R = (overridden_values.size() >= 2) ? overridden_values[1] : switch_override_info.R; | ||
switch_override_info.Cin = (overridden_values.size() >= 3) ? overridden_values[2] : switch_override_info.Cin; | ||
switch_override_info.Cout = (overridden_values.size() >= 4) ? overridden_values[3] : switch_override_info.Cout; | ||
switch_override_info.Cinternal = (overridden_values.size() >= 5) ? overridden_values[4] : switch_override_info.Cinternal; | ||
|
||
RRSwitchId new_switch_id; | ||
auto it = unique_switch_info.find(switch_override_info); | ||
if (it == unique_switch_info.end()) { | ||
new_switch_id = rr_graph_builder.add_rr_switch(switch_override_info); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think about it, I'm pretty sure I wrote a function that retrieves switch info, searches the RR Node switches for one with similar characteristics, and, if none is found, creates a new one and returns the corresponding RR switch ID (I think the name was something like get_or_create_rr_switch_id). In the issue I mentioned, if you could reference this function, I'll update this part of the code myself. |
||
unique_switch_info.insert({switch_override_info, new_switch_id}); | ||
} else { | ||
new_switch_id = it->second; | ||
} | ||
rr_graph_builder.override_edge_switch(edge_id, new_switch_id); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.