Skip to content

Commit f821768

Browse files
add get_noc_links(...) method
1 parent f489781 commit f821768

File tree

3 files changed

+91
-29
lines changed

3 files changed

+91
-29
lines changed

vpr/src/noc/noc_storage.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ NocRouter& NocStorage::get_single_mutable_noc_router(NocRouterId id) {
6464
}
6565

6666
// get link properties
67-
const NocLink& NocStorage::get_single_noc_link(NocLinkId id) const {
67+
const NocLink& NocStorage::get_single_noc_link(NocLinkId id) const {
6868
return link_storage[id];
6969
}
7070

71-
NocLinkId NocStorage::get_single_noc_link_id(NocRouterId src_router, NocRouterId dst_router) const {
71+
NocLinkId NocStorage::get_single_noc_link_id(NocRouterId src_router, NocRouterId dst_router) const {
7272
NocLinkId link_id = NocLinkId::INVALID();
7373

7474
for (const auto& link : link_storage) {
@@ -209,6 +209,8 @@ void NocStorage::finished_building_noc() {
209209
VTR_ASSERT_MSG(!built_noc, "NoC already built, cannot modify further.");
210210
built_noc = true;
211211

212+
returnable_noc_link_const_refs_.reserve(link_storage.size());
213+
212214
/* We go through all NoC routers in the router_storage and check if there are any
213215
* two consecutive NoC routers whose latency is different. If such two routers are
214216
* found, we set detailed_router_latency_ to True.

vpr/src/noc/noc_storage.h

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

136+
/**
137+
* @brief When set true, specifies that some NoC routers have different
138+
* latencies than others. When set false, all the NoC routers have the same
139+
* latency.
140+
*/
136141
bool detailed_router_latency_;
142+
143+
/**
144+
* @brief When set true, specifies that some NoC links have different
145+
* latencies than others. When set false, all the NoC link have the same
146+
* latency.
147+
*/
137148
bool detailed_link_latency_;
149+
150+
/**
151+
* @brief When set true, specifies that some NoC links have different
152+
* bandwidth than others. When set false, all the NoC link have the same
153+
* bandwidth.
154+
*/
138155
bool detailed_link_bandwidth_;
139156

157+
/**
158+
* @brief A constant reference to this vector is returned by get_noc_links(...).
159+
* This is used to avoid memory allocation whenever get_noc_links(...) is called.
160+
* The vector is mutable so that get_noc_links(...), which is a const method, can
161+
* modify it.
162+
*/
163+
mutable std::vector<std::reference_wrapper<const NocLink>> returnable_noc_link_const_refs_;
164+
140165
/**
141166
* @brief Internal reference to the device grid width. This is necessary
142167
* to compute a unique key for a given grid location which we can then use
@@ -204,45 +229,54 @@ class NocStorage {
204229
*
205230
* @return A vector of links.
206231
*/
207-
vtr::vector<NocLinkId, NocLink>& get_mutable_noc_links(void);
232+
vtr::vector<NocLinkId, NocLink>& get_mutable_noc_links();
208233

209234
/**
210235
* @return An integer representing the total number of links within the
211236
* NoC.
212237
*/
213-
int get_number_of_noc_links(void) const;
238+
int get_number_of_noc_links() const;
214239

215240
/**
216241
* @brief Get the maximum allowable bandwidth for a link
217242
* within the NoC.
218243
*
219244
* @return a numeric value that represents the link bandwidth in bps
220245
*/
221-
222-
double get_noc_link_bandwidth(void) const;
246+
double get_noc_link_bandwidth() const;
223247

224248
/**
225249
* @brief Get the latency of traversing through a link in
226250
* the NoC.
227251
*
228252
* @return a numeric value that represents the link latency in seconds
229253
*/
230-
231-
double get_noc_link_latency(void) const;
254+
double get_noc_link_latency() const;
232255

233256
/**
234257
* @brief Get the latency of traversing through a router in
235258
* the NoC.
236259
*
237260
* @return a numeric value that represents the router latency in seconds
238261
*/
262+
double get_noc_router_latency() const;
239263

240-
double get_noc_router_latency(void) const;
241-
264+
/**
265+
* @return True if some NoC routers have different latencies than others.
266+
* False if all NoC routers have the same latency.
267+
*/
242268
bool get_detailed_router_latency() const;
243269

270+
/**
271+
* @return True if some NoC links have different latencies than others.
272+
* False if all NoC links have the same latency.
273+
*/
244274
bool get_detailed_link_latency() const;
245275

276+
/**
277+
* @return True if some NoC links have different bandwidths than others.
278+
* False if all NoC links have the same bandwidth.
279+
*/
246280
bool get_detailed_link_bandwidth() const;
247281

248282
// getters for routers
@@ -279,6 +313,18 @@ class NocStorage {
279313
*/
280314
const NocLink& get_single_noc_link(NocLinkId id) const;
281315

316+
/**
317+
*
318+
* @tparam Container The type of standard library container used to carry
319+
* NoCLinkIds. This container type must be iterable in a range-based loop.
320+
* @param noc_link_ids A standard container that contains NoCLinkIds of the
321+
* requested NoC links
322+
* @return A const
323+
*/
324+
template <template<typename> class Container>
325+
const std::vector<std::reference_wrapper<const NocLink>>& get_noc_links(const Container<NocLinkId>& noc_link_ids) const;
326+
327+
282328
/**
283329
* @brief Given source and sink router identifiers, this function
284330
* finds a link connecting these routers and returns its identifier.
@@ -292,7 +338,7 @@ class NocStorage {
292338
* to the destination router. NocLinkId::INVALID() is such a link is not
293339
* found.
294340
*/
295-
NocLinkId get_single_noc_link_id(NocRouterId src_router, NocRouterId dst_router) const;
341+
NocLinkId get_single_noc_link_id(NocRouterId src_router, NocRouterId dst_router) const;
296342

297343
/**
298344
* @brief Given a unique link identifier, get the corresponding link
@@ -376,7 +422,7 @@ class NocStorage {
376422

377423
void set_device_grid_spec(int grid_width, int grid_height);
378424

379-
// general utiliy functions
425+
// general utility functions
380426
/**
381427
* @brief The link is removed from the outgoing vector of links for
382428
* the source router. The link is not removed from the vector of all
@@ -404,6 +450,14 @@ class NocStorage {
404450
* NoC (routers and links cannot be added or removed). This function
405451
* should be called after building the NoC. Guarantees that
406452
* no future changes can be made.
453+
*
454+
* When the NoC building is finished, this function checks whether
455+
* all links and routers have the same bandwidth and latency.
456+
* If some NoC elements have different latencies or bandwidths than
457+
* others, a flag is set to indicate that the detailed NoC model should be
458+
* used. In the detailed model, instead of associating a single latency or
459+
* bandwidth value with all NoC routers or links, each NoC router or link
460+
* has its specific value.
407461
*
408462
*/
409463
void finished_building_noc();
@@ -495,4 +549,18 @@ class NocStorage {
495549
void echo_noc(char* file_name) const;
496550
};
497551

498-
#endif
552+
553+
template <template<typename> class Container>
554+
const std::vector<std::reference_wrapper<const NocLink>>& NocStorage::get_noc_links(const Container<NocLinkId>& noc_link_ids) const {
555+
returnable_noc_link_const_refs_.clear();
556+
557+
std::transform(noc_link_ids.begin(), noc_link_ids.end(), std::back_inserter(returnable_noc_link_const_refs_),
558+
[this](const NocLinkId lid) {
559+
return std::reference_wrapper<const NocLink>(this->get_single_noc_link(lid));
560+
});
561+
562+
return returnable_noc_link_const_refs_;
563+
}
564+
565+
#endif
566+

vpr/src/place/noc_place_utils.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_move
146146
}
147147

148148
// Iterate over all affected links and calculate their new congestion cost and store it
149-
for (const auto& link_id : affected_noc_links) {
150-
// get the affected link
151-
const auto& link = noc_ctx.noc_model.get_single_noc_link(link_id);
152-
149+
for (const NocLink& link : noc_ctx.noc_model.get_noc_links(affected_noc_links)) {
153150
// calculate the new congestion cost for the link and store it
154151
proposed_link_congestion_costs[link] = calculate_link_congestion_cost(link);
155152

@@ -174,10 +171,7 @@ void commit_noc_costs() {
174171
}
175172

176173
// Iterate over all the NoC links whose bandwidth utilization was affected by the proposed move
177-
for(auto link_id : affected_noc_links) {
178-
// get the affected link
179-
const auto& link = noc_ctx.noc_model.get_single_noc_link(link_id);
180-
174+
for (const NocLink& link : noc_ctx.noc_model.get_noc_links(affected_noc_links)) {
181175
// commit the new link congestion cost
182176
link_congestion_costs[link] = proposed_link_congestion_costs[link];
183177

@@ -494,7 +488,7 @@ int check_noc_placement_costs(const t_placer_costs& costs, double error_toleranc
494488
}
495489

496490
// Iterate over all NoC links and accumulate congestion cost
497-
for(const auto& link : temp_noc_link_storage) {
491+
for (const auto& link : temp_noc_link_storage) {
498492
cost_check.congestion += calculate_link_congestion_cost(link);
499493
}
500494

@@ -555,10 +549,9 @@ std::pair<double, double> calculate_traffic_flow_latency_cost(const std::vector<
555549

556550
double noc_link_latency_component = 0.0;
557551
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;
552+
for (const NocLink& link : noc_model.get_noc_links(traffic_flow_route)) {
553+
double link_latency = link.get_latency();
554+
noc_link_latency_component += link_latency;
562555
}
563556
} else {
564557
auto num_of_links_in_traffic_flow = (double)traffic_flow_route.size();
@@ -575,9 +568,8 @@ std::pair<double, double> calculate_traffic_flow_latency_cost(const std::vector<
575568
const NocRouter& source_noc_router = noc_model.get_single_noc_router(source_noc_router_id);
576569
noc_router_latency_component = source_noc_router.get_latency();
577570

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();
571+
for (const NocLink& link : noc_model.get_noc_links(traffic_flow_route)) {
572+
const NocRouterId sink_router_id = link.get_sink_router();
581573
const NocRouter& sink_router = noc_model.get_single_noc_router(sink_router_id);
582574
double noc_router_latency = sink_router.get_latency();
583575
noc_router_latency_component += noc_router_latency;

0 commit comments

Comments
 (0)