Skip to content

Commit 15a9ef2

Browse files
litghostacomodi
authored andcommitted
vpr: added connection_box_map routing algorithm.
Signed-off-by: Keith Rothman <[email protected]> vpr: using namespace for connection_box_lookahead map This is to avoid conflicts in the linker. Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 2bb3101 commit 15a9ef2

17 files changed

+1126
-9
lines changed

vpr/src/base/echo_files.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ void alloc_and_load_echo_file_info() {
112112
setEchoFileName(E_ECHO_CHAN_DETAILS, "chan_details.txt");
113113
setEchoFileName(E_ECHO_SBLOCK_PATTERN, "sblock_pattern.txt");
114114
setEchoFileName(E_ECHO_ENDPOINT_TIMING, "endpoint_timing.echo.json");
115+
116+
setEchoFileName(E_ECHO_LOOKAHEAD_MAP, "lookahead_map.echo");
115117
}
116118

117119
void free_echo_file_info() {

vpr/src/base/echo_files.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum e_echo_files {
4343
E_ECHO_CHAN_DETAILS,
4444
E_ECHO_SBLOCK_PATTERN,
4545
E_ECHO_ENDPOINT_TIMING,
46+
E_ECHO_LOOKAHEAD_MAP,
4647

4748
//Timing Graphs
4849
E_ECHO_PRE_PACKING_TIMING_GRAPH,

vpr/src/base/read_options.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ struct ParseRouterLookahead {
648648
conv_value.set_value(e_router_lookahead::CLASSIC);
649649
else if (str == "map")
650650
conv_value.set_value(e_router_lookahead::MAP);
651+
else if (str == "connection_box_map")
652+
conv_value.set_value(e_router_lookahead::CONNECTION_BOX_MAP);
651653
else {
652654
std::stringstream msg;
653655
msg << "Invalid conversion from '"
@@ -661,17 +663,22 @@ struct ParseRouterLookahead {
661663

662664
ConvertedValue<std::string> to_str(e_router_lookahead val) {
663665
ConvertedValue<std::string> conv_value;
664-
if (val == e_router_lookahead::CLASSIC)
666+
if (val == e_router_lookahead::CLASSIC) {
665667
conv_value.set_value("classic");
666-
else {
667-
VTR_ASSERT(val == e_router_lookahead::MAP);
668+
} else if (val == e_router_lookahead::MAP) {
668669
conv_value.set_value("map");
670+
} else if (val == e_router_lookahead::CONNECTION_BOX_MAP) {
671+
conv_value.set_value("connection_box_map");
672+
} else {
673+
std::stringstream msg;
674+
msg << "Unrecognized e_router_lookahead";
675+
conv_value.set_error(msg.str());
669676
}
670677
return conv_value;
671678
}
672679

673680
std::vector<std::string> default_choices() {
674-
return {"classic", "map"};
681+
return {"classic", "map", "connection_box_map"};
675682
}
676683
};
677684

vpr/src/base/vpr_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clock_connection_builders.h"
2121
#include "route_traceback.h"
2222
#include "place_macro.h"
23+
#include "connection_box.h"
2324

2425
//A Context is collection of state relating to a particular part of VPR
2526
//
@@ -194,6 +195,8 @@ struct DeviceContext : public Context {
194195
* Clock Network
195196
********************************************************************/
196197
t_clock_arch* clock_arch;
198+
199+
ConnectionBoxes connection_boxes;
197200
};
198201

199202
//State relating to power analysis

vpr/src/base/vpr_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ constexpr const char* EMPTY_BLOCK_NAME = "EMPTY";
103103
enum class e_router_lookahead {
104104
CLASSIC, //VPR's classic lookahead (assumes uniform wire types)
105105
MAP, //Lookahead considering different wire types (see Oleg Petelin's MASc Thesis)
106-
NO_OP //A no-operation lookahead which always returns zero
106+
NO_OP, //A no-operation lookahead which always returns zero
107+
CONNECTION_BOX_MAP,
108+
// Lookahead considering different wire types and IPIN
109+
// connection box.
107110
};
108111

109112
enum class e_route_bb_update {

vpr/src/place/timing_place_lookup.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ static float route_connection_delay(int source_x, int source_y, int sink_x, int
264264

265265
VTR_ASSERT(sink_rr_node != OPEN);
266266

267-
successfully_routed = calculate_delay(source_rr_node, sink_rr_node,
268-
router_opts,
269-
&net_delay_value);
267+
{
268+
successfully_routed = calculate_delay(source_rr_node, sink_rr_node,
269+
router_opts,
270+
&net_delay_value);
271+
}
270272

271273
if (successfully_routed) break;
272274
}

vpr/src/route/connection_box.cpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#include "connection_box.h"
2+
#include "vtr_assert.h"
3+
#include "globals.h"
4+
5+
ConnectionBoxes::ConnectionBoxes()
6+
: size_(std::make_pair(0, 0)) {
7+
}
8+
9+
size_t ConnectionBoxes::num_connection_box_types() const {
10+
return boxes_.size();
11+
}
12+
13+
std::pair<size_t, size_t> ConnectionBoxes::connection_box_grid_size() const {
14+
return size_;
15+
}
16+
17+
const ConnectionBox* ConnectionBoxes::get_connection_box(ConnectionBoxId box) const {
18+
if (bool(box)) {
19+
return nullptr;
20+
}
21+
22+
size_t index = size_t(box);
23+
if (index >= boxes_.size()) {
24+
return nullptr;
25+
}
26+
27+
return &boxes_.at(index);
28+
}
29+
30+
bool ConnectionBoxes::find_connection_box(int inode,
31+
ConnectionBoxId* box_id,
32+
std::pair<size_t, size_t>* box_location) const {
33+
VTR_ASSERT(box_id != nullptr);
34+
VTR_ASSERT(box_location != nullptr);
35+
36+
const auto& conn_box_loc = ipin_map_[inode];
37+
if (conn_box_loc.box_id == ConnectionBoxId::INVALID()) {
38+
return false;
39+
}
40+
41+
*box_id = conn_box_loc.box_id;
42+
*box_location = conn_box_loc.box_location;
43+
return true;
44+
}
45+
46+
// Clear IPIN map and set connection box grid size and box ids.
47+
void ConnectionBoxes::reset_boxes(std::pair<size_t, size_t> size,
48+
const std::vector<ConnectionBox> boxes) {
49+
clear();
50+
51+
size_ = size;
52+
boxes_ = boxes;
53+
}
54+
55+
void ConnectionBoxes::resize_nodes(size_t rr_node_size) {
56+
ipin_map_.resize(rr_node_size);
57+
canonical_loc_map_.resize(rr_node_size,
58+
std::make_pair(-1, -1));
59+
}
60+
61+
void ConnectionBoxes::clear() {
62+
ipin_map_.clear();
63+
size_ = std::make_pair(0, 0);
64+
boxes_.clear();
65+
canonical_loc_map_.clear();
66+
sink_to_ipin_.clear();
67+
}
68+
69+
void ConnectionBoxes::add_connection_box(int inode, ConnectionBoxId box_id, std::pair<size_t, size_t> box_location) {
70+
// Ensure that box location is in bounds
71+
VTR_ASSERT(box_location.first < size_.first);
72+
VTR_ASSERT(box_location.second < size_.second);
73+
74+
// Bounds check box_id
75+
VTR_ASSERT(bool(box_id));
76+
VTR_ASSERT(size_t(box_id) < boxes_.size());
77+
78+
// Make sure sink map will not be invalidated upon insertion.
79+
VTR_ASSERT(sink_to_ipin_.size() == 0);
80+
81+
ipin_map_[inode] = ConnBoxLoc(box_location, box_id);
82+
}
83+
84+
void ConnectionBoxes::add_canonical_loc(int inode, std::pair<size_t, size_t> loc) {
85+
VTR_ASSERT(loc.first < size_.first);
86+
VTR_ASSERT(loc.second < size_.second);
87+
canonical_loc_map_[inode] = loc;
88+
}
89+
90+
const std::pair<size_t, size_t>* ConnectionBoxes::find_canonical_loc(int inode) const {
91+
const auto& canon_loc = canonical_loc_map_[inode];
92+
if (canon_loc.first == size_t(-1)) {
93+
return nullptr;
94+
}
95+
96+
return &canon_loc;
97+
}
98+
99+
void ConnectionBoxes::create_sink_back_ref() {
100+
const auto& device_ctx = g_vpr_ctx.device();
101+
102+
sink_to_ipin_.resize(device_ctx.rr_nodes.size(), {{0, 0, 0, 0}, 0});
103+
104+
for (size_t i = 0; i < device_ctx.rr_nodes.size(); ++i) {
105+
const auto& ipin_node = device_ctx.rr_nodes[i];
106+
if (ipin_node.type() != IPIN) {
107+
continue;
108+
}
109+
110+
if (ipin_map_[i].box_id == ConnectionBoxId::INVALID()) {
111+
continue;
112+
}
113+
114+
for (auto edge : ipin_node.edges()) {
115+
int sink_inode = ipin_node.edge_sink_node(edge);
116+
VTR_ASSERT(device_ctx.rr_nodes[sink_inode].type() == SINK);
117+
VTR_ASSERT(sink_to_ipin_[sink_inode].ipin_count < 4);
118+
auto& sink_to_ipin = sink_to_ipin_[sink_inode];
119+
sink_to_ipin.ipin_nodes[sink_to_ipin.ipin_count++] = i;
120+
}
121+
}
122+
}
123+
124+
const SinkToIpin& ConnectionBoxes::find_sink_connection_boxes(
125+
int inode) const {
126+
return sink_to_ipin_[inode];
127+
}

vpr/src/route/connection_box.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef CONNECTION_BOX_H
2+
#define CONNECTION_BOX_H
3+
// Some routing graphs have connectivity driven by types of connection boxes.
4+
// This class relates IPIN rr nodes with connection box type and locations, used
5+
// for connection box driven map lookahead.
6+
7+
#include <tuple>
8+
#include "vtr_strong_id.h"
9+
#include "vtr_flat_map.h"
10+
#include "vtr_range.h"
11+
#include <map>
12+
13+
struct connection_box_tag {};
14+
typedef vtr::StrongId<connection_box_tag> ConnectionBoxId;
15+
16+
struct ConnectionBox {
17+
std::string name;
18+
};
19+
20+
struct ConnBoxLoc {
21+
ConnBoxLoc()
22+
: box_location(std::make_pair(-1, -1)) {}
23+
ConnBoxLoc(
24+
const std::pair<size_t, size_t>& a_box_location,
25+
ConnectionBoxId a_box_id)
26+
: box_location(a_box_location)
27+
, box_id(a_box_id) {}
28+
29+
std::pair<size_t, size_t> box_location;
30+
ConnectionBoxId box_id;
31+
};
32+
33+
struct SinkToIpin {
34+
int ipin_nodes[4];
35+
int ipin_count;
36+
};
37+
38+
class ConnectionBoxes {
39+
public:
40+
ConnectionBoxes();
41+
42+
size_t num_connection_box_types() const;
43+
std::pair<size_t, size_t> connection_box_grid_size() const;
44+
const ConnectionBox* get_connection_box(ConnectionBoxId box) const;
45+
46+
bool find_connection_box(int inode,
47+
ConnectionBoxId* box_id,
48+
std::pair<size_t, size_t>* box_location) const;
49+
const std::pair<size_t, size_t>* find_canonical_loc(int inode) const;
50+
51+
// Clear IPIN map and set connection box grid size and box ids.
52+
void clear();
53+
void reset_boxes(std::pair<size_t, size_t> size,
54+
const std::vector<ConnectionBox> boxes);
55+
void resize_nodes(size_t rr_node_size);
56+
57+
void add_connection_box(int inode, ConnectionBoxId box_id, std::pair<size_t, size_t> box_location);
58+
void add_canonical_loc(int inode, std::pair<size_t, size_t> loc);
59+
60+
// Create map from SINK's back to IPIN's
61+
//
62+
// This must be called after all connection boxes have been added.
63+
void create_sink_back_ref();
64+
const SinkToIpin& find_sink_connection_boxes(
65+
int inode) const;
66+
67+
private:
68+
std::pair<size_t, size_t> size_;
69+
std::vector<ConnectionBox> boxes_;
70+
std::vector<ConnBoxLoc> ipin_map_;
71+
std::vector<SinkToIpin> sink_to_ipin_;
72+
std::vector<std::pair<size_t, size_t>>
73+
canonical_loc_map_;
74+
};
75+
76+
#endif

0 commit comments

Comments
 (0)