Skip to content

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

Merged
merged 34 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ff48e6b
added load_rr_edge_overrides function
soheilshahrouz Feb 7, 2025
5722c79
add -read_rr_edge_override command line option
soheilshahrouz Feb 7, 2025
dc89abd
Merge branch 'master' into ingest_per_edge_delay
soheilshahrouz Mar 12, 2025
08538ff
add help message for --read_rr_edge_override
soheilshahrouz Mar 12, 2025
3be8914
remove unused header files and types in rr_graph.cpp
soheilshahrouz Mar 12, 2025
7c6a282
rename device_ctx.read_rr_graph_filename to loaded_rr_graph_filename …
soheilshahrouz Mar 12, 2025
16870df
doxygen comment for t_det_routing_arch. Comment read_rr_edge_override…
soheilshahrouz Mar 12, 2025
43bde82
add declaration for process_rr_edge_override()
soheilshahrouz Mar 12, 2025
ba2656d
Merge branch 'master' into ingest_per_edge_delay
soheilshahrouz Apr 2, 2025
03849e4
fix a few typos
soheilshahrouz Apr 2, 2025
04e25e8
added a doxygen comments
soheilshahrouz Apr 2, 2025
a648aab
use VTR_LOGV_ERROR instead of is statements
soheilshahrouz Apr 2, 2025
4115a25
doxygen comment for load_rr_edge_overrides()
soheilshahrouz Apr 2, 2025
97da592
make format
soheilshahrouz Apr 2, 2025
305c46e
only override edge delay and not electrical stuff
soheilshahrouz Apr 2, 2025
1163f30
add a unit test for reading edge override file
soheilshahrouz Apr 9, 2025
dbeec69
Add edge_id() method to find an edge that connects given src and sink…
soheilshahrouz Apr 9, 2025
690244a
replace for loop with edge_id() method that return an edge connecting…
soheilshahrouz Apr 9, 2025
fb5ad75
add doxygen comment for edge_id() method
soheilshahrouz Apr 9, 2025
ebf88f0
verify overridden edge attribute in the unit test
soheilshahrouz Apr 9, 2025
9b6d824
move operator==() and hash function of t_rr_switch_inf to physical_ty…
soheilshahrouz Apr 9, 2025
df627ce
add test_read_rr_edge_override.txt
soheilshahrouz Apr 9, 2025
4110acd
make format
soheilshahrouz Apr 9, 2025
14b562e
Merge branch 'master' into ingest_per_edge_delay
soheilshahrouz Apr 9, 2025
010b0ac
init value of false for load_flat_placement
soheilshahrouz Apr 9, 2025
7ce51f0
Merge branch 'master' into ingest_per_edge_delay
soheilshahrouz Apr 10, 2025
94e24be
Merge remote-tracking branch 'origin/master' into ingest_per_edge_delay
soheilshahrouz Apr 15, 2025
9f06be2
apply PR comments
soheilshahrouz Apr 15, 2025
5da6cf7
add the requested comments
soheilshahrouz Apr 15, 2025
8c960f9
update file_formats.rst
soheilshahrouz Apr 15, 2025
c71a2bc
add --read_rr_edge_override to command_line_usage.rst
soheilshahrouz Apr 15, 2025
eac8bfc
remove duplicate text in command_line_usage.rst
soheilshahrouz Apr 15, 2025
2ef555f
Merge branch 'master' into ingest_per_edge_delay
soheilshahrouz Apr 19, 2025
d390291
explain what RR edge override feature is useful for
soheilshahrouz Apr 20, 2025
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ ifeq ($(VERBOSE),1)
override CMAKE_PARAMS := -DVTR_ENABLE_VERBOSE=on ${CMAKE_PARAMS}
endif

# -s : Suppresss makefile output (e.g. entering/leaving directories)
# -s : Suppresses makefile output (e.g. entering/leaving directories)
# --output-sync target : For parallel compilation ensure output for each target is synchronized (make version >= 4.0)
MAKEFLAGS := -s

SOURCE_DIR := $(PWD)
BUILD_DIR ?= build

#Check for the cmake exectuable
#Check for the cmake executable
CMAKE := $(shell command -v cmake 2> /dev/null)

#Show test log on failures with 'make test'
Expand Down
8 changes: 8 additions & 0 deletions doc/src/vpr/command_line_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ Use the options below to override this default naming behaviour.

.. seealso:: :ref:`Routing Resource XML File <vpr_route_resource_file>`.

.. option:: --read_rr_edge_override <file>

Reads a file that overrides the intrinsic delay of specific edges in RR graph.

This option should be used with both :option:`--read_rr_graph` and :option:`--write_rr_graph`. When used this way,
VPR reads the RR graph, updates the delays of selected edges using :option:`--read_rr_edge_override`,
and writes the updated RR graph. The modified RR graph can then be used in later VPR runs.

.. option:: --read_vpr_constraints <file>

Reads the :ref:`VPR constraints <vpr_constraints>` that the flow must respect from the specified XML file.
Expand Down
22 changes: 22 additions & 0 deletions doc/src/vpr/file_formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,28 @@ To aid in handling large graphs, rr_graph files can also be :ref:`saved in <file

.. _end:

RR Graph Edge Attribute Override File Format (.txt)
---------------------------------------------------
This file lets users override attributes of specific edges in the RR graph. Currently, only the intrinsic delay (Tdel)
can be changed. The expected format is:

.. code-block:: none

# edge Tdel
64812 5.9e-11
9981 4.2e-11
1234 7.1e-11
4321 9.4e-11
(42, 64) 7.3e-11

.. _end:

Lines starting with # are comments and ignored. Each other line should specify either: an edge ID and its new delay, or
a source/sink node pair and its delay.

This allows more accurate modeling of switch delays in the RR graph without creating many switch types
in the architecture file and limiting them to small regions. This can be useful for more detailed modeling of
a fabricated FPGA where layout differences lead to small delay differences in the same type of routing switch.

Network-on-Chip (NoC) Traffic Flows Format (.flows)
---------------------------------------------------
Expand Down
36 changes: 36 additions & 0 deletions libs/libarchfpga/src/physical_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ bool t_rr_switch_inf::configurable() const {
return switch_type_is_configurable(type());
}

bool t_rr_switch_inf::operator==(const t_rr_switch_inf& other) const {
return R == other.R
&& Cin == other.Cin
&& Cout == other.Cout
&& Cinternal == other.Cinternal
&& Tdel == other.Tdel
&& mux_trans_size == other.mux_trans_size
&& buf_size == other.buf_size
&& power_buffer_type == other.power_buffer_type
&& power_buffer_size == other.power_buffer_size
&& intra_tile == other.intra_tile
&& type() == other.type();
}

std::size_t t_rr_switch_inf::Hasher::operator()(const t_rr_switch_inf& s) const {
std::size_t hash_val = 0;

auto hash_combine = [&hash_val](auto&& val) {
hash_val ^= std::hash<std::decay_t<decltype(val)>>{}(val) + 0x9e3779b9 + (hash_val << 6) + (hash_val >> 2);
};

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 hash_val;
}

void t_rr_switch_inf::set_type(SwitchType type_val) {
type_ = type_val;
}
Expand Down
39 changes: 33 additions & 6 deletions libs/libarchfpga/src/physical_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1588,16 +1588,31 @@ enum class SegResType {
NUM_RES_TYPES
};

constexpr std::array<const char*, static_cast<size_t>(SegResType::NUM_RES_TYPES)> RES_TYPE_STRING = {{"GCLK", "GENERAL"}}; //String versions of segment resource types
/// String versions of segment resource types
constexpr std::array<const char*, static_cast<size_t>(SegResType::NUM_RES_TYPES)> RES_TYPE_STRING{"GCLK", "GENERAL"};

/// Defines the type of switch block used in FPGA routing.
enum e_switch_block_type {
/// If the type is SUBSET, I use a Xilinx-like switch block where track i in one channel always
/// connects to track i in other channels.
SUBSET,

/// If type is WILTON, I use a switch block where track i
/// does not always connect to track i in other channels.
/// See Steve Wilton, PhD Thesis, University of Toronto, 1996.
WILTON,

/// The UNIVERSAL switch block is from Y. W. Chang et al, TODAES, Jan. 1996, pp. 80 - 101.
UNIVERSAL,

/// The FULL switch block type allows for complete connectivity between tracks.
FULL,

/// A CUSTOM switch block has also been added which allows a user to describe custom permutation functions and connection patterns.
/// See comment at top of SRC/route/build_switchblocks.c
CUSTOM
};
typedef enum e_switch_block_type t_switch_block_type;

enum e_Fc_type {
ABSOLUTE,
FRACTIONAL
Expand Down Expand Up @@ -1906,16 +1921,28 @@ struct t_rr_switch_inf {
bool intra_tile = false;

public:
//Returns the type of switch
/// Returns the type of switch
SwitchType type() const;

//Returns true if this switch type isolates its input and output into
//separate DC-connected subcircuits
/// Returns true if this switch type isolates its input and output into
/// separate DC-connected subcircuits
bool buffered() const;

//Returns true if this switch type is configurable
/// Returns true if this switch type is configurable
bool configurable() const;

bool operator==(const t_rr_switch_inf& other) const;

/**
* @brief Functor for computing a hash value for t_rr_switch_inf.
*
* This custom hasher enables the use of t_rr_switch_inf objects as keys
* in unordered containers such as std::unordered_map or std::unordered_set.
*/
struct Hasher {
std::size_t operator()(const t_rr_switch_inf& s) const;
};

public:
void set_type(SwitchType type_val);

Expand Down
10 changes: 8 additions & 2 deletions libs/librrgraph/src/base/rr_graph_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class RRGraphBuilder {

/** @brief Reserve the lists of edges to be memory efficient.
* This function is mainly used to reserve memory space inside RRGraph,
* when adding a large number of edges in order to avoid memory fragements */
* when adding a large number of edges in order to avoid memory fragments */
inline void reserve_edges(size_t num_edges) {
node_storage_.reserve_edges(num_edges);
}
Expand All @@ -264,6 +264,12 @@ class RRGraphBuilder {
node_storage_.alloc_and_load_edges(rr_edges_to_create);
}

/** @brief Overrides the associated switch for a given edge by
* updating the edge to use the passed in switch. */
inline void override_edge_switch(RREdgeId edge_id, RRSwitchId switch_id) {
node_storage_.override_edge_switch(edge_id, switch_id);
}

/** @brief set_node_cost_index gets the index of cost data in the list of cost_indexed_data data structure
* It contains the routing cost for different nodes in the RRGraph
* when used in evaluate different routing paths
Expand Down Expand Up @@ -304,7 +310,7 @@ class RRGraphBuilder {
/** @brief Reserve the lists of nodes, edges, switches etc. to be memory efficient.
* This function is mainly used to reserve memory space inside RRGraph,
* when adding a large number of nodes/edge/switches/segments,
* in order to avoid memory fragements */
* in order to avoid memory fragments */
inline void reserve_nodes(size_t size) {
node_storage_.reserve(size);
}
Expand Down
13 changes: 9 additions & 4 deletions libs/librrgraph/src/base/rr_graph_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,9 @@ void t_rr_graph_storage::partition_edges(const vtr::vector<RRSwitchId, t_rr_swit
// by assign_first_edges()
// - Edges within a source node have the configurable edges before the
// non-configurable edges.
std::stable_sort(
edge_sort_iterator(this, 0),
edge_sort_iterator(this, edge_src_node_.size()),
edge_compare_src_node_and_configurable_first(rr_switches));
std::stable_sort(edge_sort_iterator(this, 0),
edge_sort_iterator(this, edge_src_node_.size()),
edge_compare_src_node_and_configurable_first(rr_switches));

partitioned_ = true;

Expand All @@ -548,6 +547,12 @@ void t_rr_graph_storage::partition_edges(const vtr::vector<RRSwitchId, t_rr_swit
VTR_ASSERT_SAFE(validate(rr_switches));
}

void t_rr_graph_storage::override_edge_switch(RREdgeId edge_id, RRSwitchId switch_id) {
VTR_ASSERT_DEBUG(partitioned_);
VTR_ASSERT_DEBUG(remapped_edges_);
edge_switch_[edge_id] = (short)((size_t)switch_id);
}

t_edge_size t_rr_graph_storage::num_configurable_edges(RRNodeId id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
VTR_ASSERT(!node_first_edge_.empty() && remapped_edges_);

Expand Down
35 changes: 26 additions & 9 deletions libs/librrgraph/src/base/rr_graph_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,27 @@ class t_rr_graph_storage {
* This method should generally not be used, and instead first_edge and
* last_edge should be used.
*/
RREdgeId edge_id(const RRNodeId& id, t_edge_size iedge) const {
RREdgeId edge_id(RRNodeId id, t_edge_size iedge) const {
RREdgeId first_edge = this->first_edge(id);
RREdgeId ret(size_t(first_edge) + iedge);
VTR_ASSERT_SAFE(ret < last_edge(id));
return ret;
}

/**
* @brief Retrieve the RREdgeId that connects the given source and sink nodes.
* If the given source/sink nodes are not connected, RREdgeId::INVALID() is returned.
*/
RREdgeId edge_id(RRNodeId src, RRNodeId sink) const {
for (RREdgeId outgoing_edge_id : edge_range(src)) {
if (edge_sink_node(outgoing_edge_id) == sink) {
return outgoing_edge_id;
}
}

return RREdgeId::INVALID();
}

/** @brief Get the source node for the specified edge. */
RRNodeId edge_src_node(const RREdgeId& edge) const {
VTR_ASSERT_DEBUG(edge.is_valid());
Expand Down Expand Up @@ -448,7 +462,7 @@ class t_rr_graph_storage {
*
* The following methods implement an interface that appears to be
* equivalent to the interface exposed by std::vector<t_rr_node>.
* This was done for backwards compability. See t_rr_node for more details.
* This was done for backwards compatibility. See t_rr_node for more details.
*
* Proxy methods:
*
Expand Down Expand Up @@ -483,8 +497,8 @@ class t_rr_graph_storage {
***************************/

/** @brief
* Makes room in storage for RRNodeId in amoritized O(1) fashion.
* This results in an allocation pattern similiar to what would happen
* Makes room in storage for RRNodeId in amortized O(1) fashion.
* This results in an allocation pattern similar to what would happen
* if push_back(x) / emplace_back() were used if underlying storage
* was not pre-allocated.
*/
Expand Down Expand Up @@ -616,8 +630,8 @@ class t_rr_graph_storage {
void set_node_direction(RRNodeId, Direction new_direction);

/** @brief
* Add a side to the node abbributes
* This is the function to use when you just add a new side WITHOUT reseting side attributes
* Add a side to the node attributes
* This is the function to use when you just add a new side WITHOUT resetting side attributes
*/
void add_node_side(RRNodeId, e_side new_side);

Expand Down Expand Up @@ -707,9 +721,8 @@ class t_rr_graph_storage {
*
* init_fan_in does not need to be invoked before this method.
*/
size_t count_rr_switches(
const std::vector<t_arch_switch_inf>& arch_switch_inf,
t_arch_switch_fanin& arch_switch_fanins);
size_t count_rr_switches(const std::vector<t_arch_switch_inf>& arch_switch_inf,
t_arch_switch_fanin& arch_switch_fanins);

/** @brief Maps arch_switch_inf indicies to rr_switch_inf indicies.
*
Expand All @@ -731,6 +744,10 @@ class t_rr_graph_storage {
*/
void partition_edges(const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches);

/** @brief Overrides the associated switch for a given edge by
* updating the edge to use the passed in switch. */
void override_edge_switch(RREdgeId edge_id, RRSwitchId switch_id);

/** @brief Validate that edge data is partitioned correctly.*/
bool validate_node(RRNodeId node_id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const;
bool validate(const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const;
Expand Down
5 changes: 5 additions & 0 deletions libs/librrgraph/src/base/rr_graph_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ class RRGraphView {
return node_storage_.edge_switch(id, iedge);
}

/// @brief Returns the associated switch for a given edge.
inline short edge_switch(RREdgeId id) const {
return node_storage_.edge_switch(id);
}

/** @brief Return the source node for the specified edge.
*/
inline RRNodeId edge_src_node(const RREdgeId edge_id) const {
Expand Down
Loading