From de1e300ec76f1948b0897191f856820b7e17e58d Mon Sep 17 00:00:00 2001 From: tangxifan Date: Sun, 5 Mar 2023 22:21:55 -0800 Subject: [PATCH] [core] now resize rr_node for clock graph is working --- .../src/base/clock_network.cpp | 17 ++++++++++++++- .../src/base/clock_network.h | 2 ++ .../src/base/rr_clock_spatial_lookup.cpp | 21 +++++++++++++++++++ .../src/base/rr_clock_spatial_lookup.h | 9 ++++++++ .../src/annotation/append_clock_rr_graph.cpp | 3 +++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/libs/libclkarchopenfpga/src/base/clock_network.cpp b/libs/libclkarchopenfpga/src/base/clock_network.cpp index aa7a09956..08feb206e 100644 --- a/libs/libclkarchopenfpga/src/base/clock_network.cpp +++ b/libs/libclkarchopenfpga/src/base/clock_network.cpp @@ -179,6 +179,22 @@ std::string ClockNetwork::tree_name(const ClockTreeId& tree_id) const { 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 { VTR_ASSERT(valid_tree_id(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) { - size_t depth = 0; for (ClockSpineId spine_id : spines(tree_id)) { spine_track_types_[spine_id] = spine_track_type(spine_id); spine_directions_[spine_id] = spine_direction(spine_id); diff --git a/libs/libclkarchopenfpga/src/base/clock_network.h b/libs/libclkarchopenfpga/src/base/clock_network.h index e729dbef2..0b9b8a42b 100644 --- a/libs/libclkarchopenfpga/src/base/clock_network.h +++ b/libs/libclkarchopenfpga/src/base/clock_network.h @@ -78,6 +78,8 @@ class ClockNetwork { std::string tree_name(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 max_tree_width() const; + size_t max_tree_depth() const; std::vector tree_top_spines(const ClockTreeId& tree_id) const; std::string spine_name(const ClockSpineId& spine_id) const; vtr::Point spine_start_point(const ClockSpineId& spine_id) const; diff --git a/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.cpp b/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.cpp index 32f403582..f77c37c1c 100644 --- a/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.cpp +++ b/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.cpp @@ -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; } +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, const Direction& direction) { /* Expand the fast look-up if the new node is out-of-range diff --git a/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.h b/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.h index 9eb48830a..25487a622 100644 --- a/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.h +++ b/libs/libclkarchopenfpga/src/base/rr_clock_spatial_lookup.h @@ -85,6 +85,15 @@ class RRClockSpatialLookup { const ClockLevelId& clk_lvl, const ClockTreePinId& clk_pin, 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 */ void clear(); diff --git a/openfpga/src/annotation/append_clock_rr_graph.cpp b/openfpga/src/annotation/append_clock_rr_graph.cpp index 171a24bba..23cc748f9 100644 --- a/openfpga/src/annotation/append_clock_rr_graph.cpp +++ b/openfpga/src/annotation/append_clock_rr_graph.cpp @@ -150,6 +150,9 @@ static void add_rr_graph_clock_nodes(RRGraphBuilder& rr_graph_builder, const bool& through_channel, const ClockNetwork& clk_ntwk, 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 */ for (size_t iy = 0; iy < grids.height() - 1; ++iy) { for (size_t ix = 1; ix < grids.width() - 1; ++ix) {