Skip to content

Commit 547a7ea

Browse files
compute detailed noc latency cost
1 parent 7f071ac commit 547a7ea

File tree

7 files changed

+111
-34
lines changed

7 files changed

+111
-34
lines changed

vpr/src/noc/noc_link.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ double NocLink::get_congested_bandwidth_ratio() const {
6363
return congested_bw_ratio;
6464
}
6565

66+
double NocLink::get_latency() const {
67+
return latency;
68+
}
69+
6670
NocLinkId NocLink::get_link_id() const {
6771
return id;
6872
}
6973

7074
NocLink::operator NocLinkId() const {
7175
return get_link_id();
72-
}
76+
}
77+

vpr/src/noc/noc_link.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ class NocLink {
9898
*/
9999
double get_congested_bandwidth_ratio() const;
100100

101+
/**
102+
* @brief Returns the zero-load latency of the link.
103+
* @return double Zero-load latency of the link.
104+
*/
105+
double get_latency() const;
106+
101107
/**
102108
* @brief Returns the unique link ID. The ID can be used to index
103109
* vtr::vector<NoCLinkId, ...> instances.

vpr/src/noc/noc_router.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ t_physical_tile_loc NocRouter::get_router_physical_location(void) const {
3939
return phy_loc;
4040
}
4141

42+
double NocRouter::get_latency() const {
43+
return router_latency;
44+
}
45+
4246
ClusterBlockId NocRouter::get_router_block_ref(void) const {
4347
return router_block_ref;
4448
}

vpr/src/noc/noc_router.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class NocRouter {
9696
*/
9797
t_physical_tile_loc get_router_physical_location(void) const;
9898

99+
double get_latency() const;
100+
99101
/**
100102
* @brief Gets the unique id of the router block that is current placed on the physical router
101103
* @return A ClusterBlockId that identifies a router block in the clustered netlist

vpr/src/noc/noc_storage.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ double NocStorage::get_noc_router_latency(void) const {
4343
return noc_router_latency;
4444
}
4545

46+
bool NocStorage::get_detailed_router_latency() const {
47+
return detailed_router_latency_;
48+
}
49+
50+
bool NocStorage::get_detailed_link_latency() const {
51+
return detailed_link_latency_;
52+
}
53+
54+
bool NocStorage::get_detailed_link_bandwidth() const {
55+
return detailed_link_bandwidth_;
56+
}
57+
4658
const NocRouter& NocStorage::get_single_noc_router(NocRouterId id) const {
4759
return router_storage[id];
4860
}
@@ -130,29 +142,23 @@ void NocStorage::set_noc_link_bandwidth(double link_bandwidth) {
130142
for (auto& link : link_storage) {
131143
link.set_bandwidth(noc_link_bandwidth);
132144
}
133-
134-
return;
135145
}
136146

137147
void NocStorage::set_noc_link_latency(double link_latency) {
138148
noc_link_latency = link_latency;
139-
return;
140149
}
141150

142151
void NocStorage::set_noc_router_latency(double router_latency) {
143152
noc_router_latency = router_latency;
144-
return;
145153
}
146154

147155
void NocStorage::set_device_grid_width(int grid_width) {
148156
device_grid_width = grid_width;
149-
return;
150157
}
151158

152159
void NocStorage::set_device_grid_spec(int grid_width, int grid_height) {
153160
device_grid_width = grid_width;
154161
layer_num_grid_locs = grid_width * grid_height;
155-
return;
156162
}
157163

158164
bool NocStorage::remove_link(NocRouterId src_router_id, NocRouterId sink_router_id) {
@@ -161,7 +167,7 @@ bool NocStorage::remove_link(NocRouterId src_router_id, NocRouterId sink_router_
161167

162168
// check if the src router for the link to remove exists (within the id ranges). Otherwise, there is no point looking for the link
163169
if ((size_t)src_router_id < router_storage.size()) {
164-
// get all the outgoing links of the provided sourcer router
170+
// get all the outgoing links of the provided source router
165171
std::vector<NocLinkId>* source_router_outgoing_links = &router_link_list[src_router_id];
166172

167173
// keeps track of the position of each outgoing link for the provided src router. When the id of the link to remove is found, this index can be used to remove it from the outgoing link vector.
@@ -199,26 +205,48 @@ bool NocStorage::remove_link(NocRouterId src_router_id, NocRouterId sink_router_
199205
return link_removed_status;
200206
}
201207

202-
void NocStorage::finished_building_noc(void) {
208+
void NocStorage::finished_building_noc() {
203209
VTR_ASSERT_MSG(!built_noc, "NoC already built, cannot modify further.");
204210
built_noc = true;
205211

206-
return;
212+
/* We go through all NoC routers in the router_storage and check if there are any
213+
* two consecutive NoC routers whose latency is different. If such two routers are
214+
* found, we set detailed_router_latency_ to True.
215+
*
216+
* The values of detailed_link_latency_ and detailed_link_bandwidth_ are determined
217+
* in a similar way.
218+
*/
219+
220+
auto router_latency_it = std::adjacent_find(router_storage.begin(), router_storage.end(),
221+
[](const NocRouter& a, const NocRouter& b) {
222+
return a.get_latency() != b.get_latency();
223+
});
224+
detailed_router_latency_ = (router_latency_it != router_storage.end());
225+
226+
auto link_latency_it = std::adjacent_find(link_storage.begin(), link_storage.end(),
227+
[](const NocLink& a, const NocLink& b) {
228+
return a.get_latency() != b.get_latency();
229+
});
230+
detailed_link_latency_ = (link_latency_it != link_storage.end());
231+
232+
auto link_bandwidth_it = std::adjacent_find(link_storage.begin(), link_storage.end(),
233+
[](const NocLink& a, const NocLink& b) {
234+
return a.get_bandwidth() != b.get_bandwidth();
235+
});
236+
detailed_link_bandwidth_ = (link_bandwidth_it != link_storage.end());
207237
}
208238

209-
void NocStorage::clear_noc(void) {
239+
void NocStorage::clear_noc() {
210240
router_storage.clear();
211241
link_storage.clear();
212242
router_link_list.clear();
213243
grid_location_to_router_id.clear();
214244

215245
built_noc = false;
216-
217-
return;
218246
}
219247

220248
NocRouterId NocStorage::convert_router_id(int id) const {
221-
std::unordered_map<int, NocRouterId>::const_iterator result = router_id_conversion_table.find(id);
249+
auto result = router_id_conversion_table.find(id);
222250

223251
if (result == router_id_conversion_table.end()) {
224252
VPR_FATAL_ERROR(VPR_ERROR_OTHER, "Cannot convert router with id:%d. The router was not found within the NoC.", id);

vpr/src/noc/noc_storage.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class NocStorage {
133133
*/
134134
double noc_router_latency;
135135

136+
bool detailed_router_latency_;
137+
bool detailed_link_latency_;
138+
bool detailed_link_bandwidth_;
139+
136140
/**
137141
* @brief Internal reference to the device grid width. This is necessary
138142
* to compute a unique key for a given grid location which we can then use
@@ -235,6 +239,12 @@ class NocStorage {
235239

236240
double get_noc_router_latency(void) const;
237241

242+
bool get_detailed_router_latency() const;
243+
244+
bool get_detailed_link_latency() const;
245+
246+
bool get_detailed_link_bandwidth() const;
247+
238248
// getters for routers
239249

240250
/**
@@ -342,34 +352,26 @@ class NocStorage {
342352

343353
/**
344354
* @brief Set the maximum allowable bandwidth for a link
345-
* within the NoC.
346-
*
355+
* within the NoC
347356
*/
348-
349357
void set_noc_link_bandwidth(double link_bandwidth);
350358

351359
/**
352360
* @brief Set the latency of traversing through a link in
353361
* the NoC.
354-
*
355362
*/
356-
357363
void set_noc_link_latency(double link_latency);
358364

359365
/**
360366
* @brief Set the latency of traversing through a router in
361367
* the NoC.
362-
*
363368
*/
364-
365369
void set_noc_router_latency(double router_latency);
366370

367371
/**
368372
* @brief Set the internal reference to the device
369373
* grid width.
370-
*
371374
*/
372-
373375
void set_device_grid_width(int grid_width);
374376

375377
void set_device_grid_spec(int grid_width, int grid_height);
@@ -404,7 +406,7 @@ class NocStorage {
404406
* no future changes can be made.
405407
*
406408
*/
407-
void finished_building_noc(void);
409+
void finished_building_noc();
408410

409411
/**
410412
* @brief Resets the NoC by clearing all internal datastructures.
@@ -413,7 +415,7 @@ class NocStorage {
413415
* recommended to run this function before building the NoC.
414416
*
415417
*/
416-
void clear_noc(void);
418+
void clear_noc();
417419

418420
/**
419421
* @brief Given a user id of a router, this function converts

vpr/src/place/noc_place_utils.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -552,19 +552,49 @@ double calculate_traffic_flow_aggregate_bandwidth_cost(const std::vector<NocLink
552552
std::pair<double, double> calculate_traffic_flow_latency_cost(const std::vector<NocLinkId>& traffic_flow_route,
553553
const NocStorage& noc_model,
554554
const t_noc_traffic_flow& traffic_flow_info) {
555-
// there will always be one more router than links in a traffic flow
556-
int num_of_links_in_traffic_flow = traffic_flow_route.size();
557-
int num_of_routers_in_traffic_flow = num_of_links_in_traffic_flow + 1;
558-
double max_latency = traffic_flow_info.max_traffic_flow_latency;
559555

560-
// latencies of the noc
561-
double noc_link_latency = noc_model.get_noc_link_latency();
562-
double noc_router_latency = noc_model.get_noc_router_latency();
556+
double noc_link_latency_component = 0.0;
557+
if (noc_model.get_detailed_link_latency()) {
558+
for (auto noc_link_id : traffic_flow_route) {
559+
const NocLink& noc_link = noc_model.get_single_noc_link(noc_link_id);
560+
double noc_link_latency = noc_link.get_latency();
561+
noc_link_latency_component += noc_link_latency;
562+
}
563+
} else {
564+
auto num_of_links_in_traffic_flow = (double)traffic_flow_route.size();
565+
double noc_link_latency = noc_model.get_noc_link_latency();
566+
noc_link_latency_component = noc_link_latency * num_of_links_in_traffic_flow;
567+
}
568+
569+
double noc_router_latency_component = 0.0;
570+
571+
if (noc_model.get_detailed_router_latency()) {
572+
NocLinkId first_noc_link_id = traffic_flow_route[0];
573+
const NocLink& first_noc_link = noc_model.get_single_noc_link(first_noc_link_id);
574+
NocRouterId source_noc_router_id = first_noc_link.get_source_router();
575+
const NocRouter& source_noc_router = noc_model.get_single_noc_router(source_noc_router_id);
576+
noc_router_latency_component = source_noc_router.get_latency();
577+
578+
for (auto noc_link_id : traffic_flow_route) {
579+
const NocLink& noc_link = noc_model.get_single_noc_link(noc_link_id);
580+
const NocRouterId sink_router_id = noc_link.get_sink_router();
581+
const NocRouter& sink_router = noc_model.get_single_noc_router(sink_router_id);
582+
double noc_router_latency = sink_router.get_latency();
583+
noc_router_latency_component += noc_router_latency;
584+
}
585+
} else {
586+
// there will always be one more router than links in a traffic flow
587+
auto num_of_routers_in_traffic_flow = (double)traffic_flow_route.size() + 1;
588+
double noc_router_latency = noc_model.get_noc_router_latency();
589+
noc_router_latency_component = noc_router_latency * num_of_routers_in_traffic_flow;
590+
}
591+
563592

564-
// calculate the traffic flow latency
565-
double latency = (noc_link_latency * num_of_links_in_traffic_flow) + (noc_router_latency * num_of_routers_in_traffic_flow);
593+
// calculate the total traffic flow latency
594+
double latency = noc_router_latency_component + noc_link_latency_component;
566595

567596
// calculate the traffic flow latency overrun
597+
double max_latency = traffic_flow_info.max_traffic_flow_latency;
568598
double latency_overrun = std::max(latency - max_latency, 0.);
569599

570600
// scale the latency cost by its priority to indicate its importance

0 commit comments

Comments
 (0)