[core] now resize rr_node for clock graph is working

This commit is contained in:
tangxifan 2023-03-05 22:21:55 -08:00
parent 81e9187aac
commit de1e300ec7
5 changed files with 51 additions and 1 deletions

View File

@ -179,6 +179,22 @@ std::string ClockNetwork::tree_name(const ClockTreeId& tree_id) const {
return tree_names_[tree_id]; return tree_names_[tree_id];
} }
size_t ClockNetwork::max_tree_width() const {
size_t max_size = 0;
for (auto itree : trees()) {
max_size = std::max(tree_width(itree), max_size);
}
return max_size;
}
size_t ClockNetwork::max_tree_depth() const {
size_t max_size = 0;
for (auto itree : trees()) {
max_size = std::max(tree_depth(itree), max_size);
}
return max_size;
}
size_t ClockNetwork::tree_width(const ClockTreeId& tree_id) const { size_t ClockNetwork::tree_width(const ClockTreeId& tree_id) const {
VTR_ASSERT(valid_tree_id(tree_id)); VTR_ASSERT(valid_tree_id(tree_id));
return tree_widths_[tree_id]; return tree_widths_[tree_id];
@ -663,7 +679,6 @@ bool ClockNetwork::update_tree_depth(const ClockTreeId& tree_id) {
} }
bool ClockNetwork::update_spine_attributes(const ClockTreeId& tree_id) { bool ClockNetwork::update_spine_attributes(const ClockTreeId& tree_id) {
size_t depth = 0;
for (ClockSpineId spine_id : spines(tree_id)) { for (ClockSpineId spine_id : spines(tree_id)) {
spine_track_types_[spine_id] = spine_track_type(spine_id); spine_track_types_[spine_id] = spine_track_type(spine_id);
spine_directions_[spine_id] = spine_direction(spine_id); spine_directions_[spine_id] = spine_direction(spine_id);

View File

@ -78,6 +78,8 @@ class ClockNetwork {
std::string tree_name(const ClockTreeId& tree_id) const; std::string tree_name(const ClockTreeId& tree_id) const;
size_t tree_width(const ClockTreeId& tree_id) const; size_t tree_width(const ClockTreeId& tree_id) const;
size_t tree_depth(const ClockTreeId& tree_id) const; size_t tree_depth(const ClockTreeId& tree_id) const;
size_t max_tree_width() const;
size_t max_tree_depth() const;
std::vector<ClockSpineId> tree_top_spines(const ClockTreeId& tree_id) const; std::vector<ClockSpineId> tree_top_spines(const ClockTreeId& tree_id) const;
std::string spine_name(const ClockSpineId& spine_id) const; std::string spine_name(const ClockSpineId& spine_id) const;
vtr::Point<int> spine_start_point(const ClockSpineId& spine_id) const; vtr::Point<int> spine_start_point(const ClockSpineId& spine_id) const;

View File

@ -84,6 +84,27 @@ void RRClockSpatialLookup::add_node(RRNodeId node, int x, int y,
rr_node_indices_[dir][x][y][size_t(tree)][size_t(lvl)][size_t(pin)] = node; rr_node_indices_[dir][x][y][size_t(tree)][size_t(lvl)][size_t(pin)] = node;
} }
void RRClockSpatialLookup::reserve_nodes(int x, int y,
int tree,
int lvl,
int pin) {
for (Direction dir : {Direction::INC, Direction::DEC}) {
resize_nodes(x, y, dir);
for (int ix = 0; ix < x; ++ix) {
for (int iy = 0; iy < y; ++iy) {
rr_node_indices_[size_t(dir)][ix][iy].resize(tree);
for (int itree = 0; itree < tree; ++itree) {
rr_node_indices_[size_t(dir)][ix][iy][itree].resize(lvl);
for (int ilvl = 0; ilvl < lvl; ++ilvl) {
rr_node_indices_[size_t(dir)][ix][iy][itree][ilvl].resize(pin);
}
}
}
}
}
}
void RRClockSpatialLookup::resize_nodes(int x, int y, void RRClockSpatialLookup::resize_nodes(int x, int y,
const Direction& direction) { const Direction& direction) {
/* Expand the fast look-up if the new node is out-of-range /* Expand the fast look-up if the new node is out-of-range

View File

@ -85,6 +85,15 @@ class RRClockSpatialLookup {
const ClockLevelId& clk_lvl, const ClockTreePinId& clk_pin, const ClockLevelId& clk_lvl, const ClockTreePinId& clk_pin,
const Direction& direction); const Direction& direction);
/**
* @brief Allocate memory for the lookup with maximum sizes on each dimension
* .. note:: Must run before any other API!
*/
void reserve_nodes(int x, int y,
int tree,
int lvl,
int pin);
/** @brief Clear all the data inside */ /** @brief Clear all the data inside */
void clear(); void clear();

View File

@ -150,6 +150,9 @@ static void add_rr_graph_clock_nodes(RRGraphBuilder& rr_graph_builder,
const bool& through_channel, const bool& through_channel,
const ClockNetwork& clk_ntwk, const ClockNetwork& clk_ntwk,
const bool& verbose) { const bool& verbose) {
/* Pre-allocate memory: Must do otherwise data will be messed up! */
clk_rr_lookup.reserve_nodes(grids.width(), grids.height(), clk_ntwk.num_trees(), clk_ntwk.max_tree_depth(), clk_ntwk.max_tree_width());
/* Add X-direction clock nodes */ /* Add X-direction clock nodes */
for (size_t iy = 0; iy < grids.height() - 1; ++iy) { for (size_t iy = 0; iy < grids.height() - 1; ++iy) {
for (size_t ix = 1; ix < grids.width() - 1; ++ix) { for (size_t ix = 1; ix < grids.width() - 1; ++ix) {