Skip to content

NocCostHandler class #2724

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 33 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
acb812c
Merge branch 'temp_net_cost_ref' into temp_remove_static_vars_noc
soheilshahrouz Sep 9, 2024
3689cca
add NocCostHandler class and move some functions to it
soheilshahrouz Sep 9, 2024
b19360e
fix compilation errors in noc_place_utils
soheilshahrouz Sep 10, 2024
65d067a
fix compilation erros in place.cpp
soheilshahrouz Sep 10, 2024
29cc099
fix compilation errors in initial_noc_placement.cpp/.h
soheilshahrouz Sep 10, 2024
fd36ecf
fix compilation errors in initial_placement.cpp
soheilshahrouz Sep 10, 2024
de0344f
fix compilation error in noc_place_checkpoint.cpp
soheilshahrouz Sep 11, 2024
2042423
add recompute_costs_from_scratch() method to NocCostHandler
soheilshahrouz Sep 11, 2024
80d98f7
temp fix for remaining compilation errors
soheilshahrouz Sep 15, 2024
ea103df
store traffic flow routes locally in NocCostHandler
soheilshahrouz Sep 15, 2024
7906b79
store a backup of the current route to avoid rerouting when a swap is…
soheilshahrouz Sep 15, 2024
e4a0722
remove block_locs argument from NocCostHandler methods
soheilshahrouz Sep 15, 2024
508e502
Merge branch 'master' into temp_remove_static_vars_noc
soheilshahrouz Sep 21, 2024
b9d9a69
remove dead code
soheilshahrouz Sep 21, 2024
26ec8cd
limit the scope of constant values declared in noc_place_utils.h
soheilshahrouz Sep 21, 2024
ca9c748
const correctness in NocCostHandler
soheilshahrouz Sep 21, 2024
bffb451
include optional in initial_placement.h
soheilshahrouz Sep 21, 2024
9660eea
fix compilation error
soheilshahrouz Sep 21, 2024
a6ad2f7
Merge branch 'master' into temp_remove_static_vars_noc
soheilshahrouz Sep 24, 2024
9fa4157
Merge branch 'master' into temp_remove_static_vars_noc
soheilshahrouz Sep 28, 2024
7fd83b6
fix most of compilation errors in test_noc_place_utils
soheilshahrouz Sep 28, 2024
5ff98e7
add get_link_used_bandwidth() to NocCostHandler
soheilshahrouz Sep 29, 2024
3eb518f
update test_revert_noc_traffic_flow_routes to be compatible with NocC…
soheilshahrouz Sep 29, 2024
2053c65
update link bandwidth utilization when traffic flow routes are reverted
soheilshahrouz Sep 29, 2024
2c7f183
fix unit test failure for check_noc_placement_costs()
soheilshahrouz Sep 29, 2024
4bd8de3
delete move assignment operator and constructor of NetCostHandler
soheilshahrouz Sep 29, 2024
a699e67
pass NoC link bandwidth utilization to graphics
soheilshahrouz Sep 29, 2024
30d9dbf
add guard for set_noc_link_bandwidth_usages_ref call
soheilshahrouz Sep 29, 2024
57ff88e
apply PR comments
soheilshahrouz Sep 30, 2024
c5a4a15
rename ERROR_TOL to PL_INCREMENTAL_COST_TOLERANCE
soheilshahrouz Oct 1, 2024
d1eea5f
Merge remote-tracking branch 'origin/master' into temp_remove_static_…
soheilshahrouz Oct 2, 2024
eace358
move clear_all_grid_locs() to BlkLocRegistry
soheilshahrouz Oct 2, 2024
169b31c
apply PR comments
soheilshahrouz Oct 2, 2024
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
2 changes: 1 addition & 1 deletion libs/libvtrutil/src/vtr_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace vtr {
/**
* @brief This function will force the container to be cleared
*
* It release it's held memory.
* It release its held memory.
* For efficiency, STL containers usually don't
* release their actual heap-allocated memory until
* destruction (even if Container::clear() is called).
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ struct t_2D_bb {
VTR_ASSERT(ymax_ >= ymin_);
VTR_ASSERT(layer_num_ >= 0);
}


int xmin = OPEN;
int xmax = OPEN;
int ymin = OPEN;
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/draw/draw_noc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void draw_noc_usage(vtr::vector<NocLinkId, ezgl::color>& noc_link_colors) {
// if we are here then the link was not updated previously, so assign the color here

//get the current link bandwidth usage (ratio calculation)
double link_bandwidth_usage_ratio = (noc_link.get_bandwidth_usage()) / noc_link.get_bandwidth();
double link_bandwidth_usage_ratio = 0.0;//(noc_link.get_bandwidth_usage()) / noc_link.get_bandwidth();

// check if the link is being overused and if it is then cap it at 1.0
if (link_bandwidth_usage_ratio > 1.0) {
Expand Down
39 changes: 16 additions & 23 deletions vpr/src/noc/noc_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ NocLink::NocLink(NocLinkId link_id, NocRouterId source, NocRouterId sink,
: id(link_id)
, source_router(source)
, sink_router(sink)
, bandwidth_usage(0.0)
, bandwidth(bw)
, latency(lat) { }

Expand All @@ -19,10 +18,6 @@ NocRouterId NocLink::get_sink_router() const {
return sink_router;
}

double NocLink::get_bandwidth_usage() const {
return bandwidth_usage;
}

//setters
void NocLink::set_source_router(NocRouterId source) {
source_router = source;
Expand All @@ -32,9 +27,7 @@ void NocLink::set_sink_router(NocRouterId sink) {
sink_router = sink;
}

void NocLink::set_bandwidth_usage(double new_bandwidth_usage) {
bandwidth_usage = new_bandwidth_usage;
}


void NocLink::set_bandwidth(double new_bandwidth) {
bandwidth = new_bandwidth;
Expand All @@ -44,21 +37,21 @@ double NocLink::get_bandwidth() const {
return bandwidth;
}

double NocLink::get_congested_bandwidth() const {
double congested_bandwidth = bandwidth_usage - bandwidth;
congested_bandwidth = std::max(congested_bandwidth, 0.0);

VTR_ASSERT(congested_bandwidth >= 0.0);
return congested_bandwidth;
}

double NocLink::get_congested_bandwidth_ratio() const {
double congested_bw = get_congested_bandwidth();
double congested_bw_ratio = congested_bw / get_bandwidth();

VTR_ASSERT(congested_bw_ratio >= 0.0);
return congested_bw_ratio;
}
//double NocLink::get_congested_bandwidth() const {
// double congested_bandwidth = bandwidth_usage - bandwidth;
// congested_bandwidth = std::max(congested_bandwidth, 0.0);
//
// VTR_ASSERT_SAFE(congested_bandwidth >= 0.0);
// return congested_bandwidth;
//}
//
//double NocLink::get_congested_bandwidth_ratio() const {
// double congested_bw = get_congested_bandwidth();
// double congested_bw_ratio = congested_bw / get_bandwidth();
//
// VTR_ASSERT(congested_bw_ratio >= 0.0);
// return congested_bw_ratio;
//}

double NocLink::get_latency() const {
return latency;
Expand Down
40 changes: 12 additions & 28 deletions vpr/src/noc/noc_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class NocLink {
NocRouterId source_router; /*!< The router which uses this link as an outgoing edge*/
NocRouterId sink_router; /*!< The router which uses this link as an incoming edge*/

double bandwidth_usage; /*!< Represents the bandwidth of the data being transmitted on the link. Units in bits-per-second(bps)*/
double bandwidth; /*!< Represents the maximum bits per second that can be transmitted over the link without causing congestion*/
double latency; /*!< The zero-load latency of this link in seconds.*/

Expand All @@ -73,30 +72,24 @@ class NocLink {
*/
NocRouterId get_sink_router() const;

/**
* @brief Provides the size of the data (bandwidth) being currently transmitted using the link.
* @return A numeric value of the bandwidth usage of the link
*/
double get_bandwidth_usage() const;

/**
* @brief Returns the maximum bandwidth that the link can carry without congestion.
* @return A numeric value of the bandwidth capacity of the link
*/
double get_bandwidth() const;

/**
* @brief Calculates the extent to which the current bandwidth utilization
* exceeds the link capacity. Any positive value means the link is congested.
* @return A numeric value of the bandwidth over-utilization in the link
*/
double get_congested_bandwidth() const;

/**
* @brief Computes the congested bandwidth to bandwidth capacity ratio.
* @return The congested bandwidth to bandwidth capacity of the link.
*/
double get_congested_bandwidth_ratio() const;
// /**
// * @brief Calculates the extent to which the current bandwidth utilization
// * exceeds the link capacity. Any positive value means the link is congested.
// * @return A numeric value of the bandwidth over-utilization in the link
// */
// double get_congested_bandwidth() const;
//
// /**
// * @brief Computes the congested bandwidth to bandwidth capacity ratio.
// * @return The congested bandwidth to bandwidth capacity of the link.
// */
// double get_congested_bandwidth_ratio() const;

/**
* @brief Returns the zero-load latency of the link.
Expand Down Expand Up @@ -126,15 +119,6 @@ class NocLink {
*/
void set_sink_router(NocRouterId sink);

/**
* @brief Can modify the bandwidth usage of the link. It is expected that when the NoC is being placed
* the traffic flows will be re-routed multiple times. So the links will end up being used and un-used
* by different traffic flows and the bandwidths of the links will correspondingly change. This function
* can be used to make those changes
* @param new_bandwidth_usage The new value of the bandwidth usage of the link
*/
void set_bandwidth_usage(double new_bandwidth_usage);

/**
* @brief Sets the bandwidth capacity of the link. This function should be used when
* global NoC data structures are created and populated. The bandwidth capacity is used
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/noc/noc_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ bool NocStorage::remove_link(NocRouterId src_router_id, NocRouterId sink_router_

link_storage[link_to_be_removed_id].set_source_router(NocRouterId::INVALID());
link_storage[link_to_be_removed_id].set_sink_router(NocRouterId::INVALID());
link_storage[link_to_be_removed_id].set_bandwidth_usage(-1);
// link_storage[link_to_be_removed_id].set_bandwidth_usage(-1);

}

Expand Down
8 changes: 4 additions & 4 deletions vpr/src/noc/noc_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ class NocStorage {
*/
int layer_num_grid_locs;

// prevent "copying" of this object
NocStorage(const NocStorage&) = delete;
void operator=(const NocStorage&) = delete;

public:
// default constructor (clear all the elements in the vectors)
NocStorage();

// prevent "copying" of this object
NocStorage(const NocStorage&) = delete;
void operator=(const NocStorage&) = delete;

// getters for the NoC

/**
Expand Down
26 changes: 13 additions & 13 deletions vpr/src/noc/noc_traffic_flows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ int NocTrafficFlows::get_number_of_routers_used_in_traffic_flows() {
return traffic_flows_associated_to_router_blocks.size();
}

const std::vector<NocLinkId>& NocTrafficFlows::get_traffic_flow_route(NocTrafficFlowId traffic_flow_id) const {
return traffic_flow_routes[traffic_flow_id];
}

std::vector<NocLinkId>& NocTrafficFlows::get_mutable_traffic_flow_route(NocTrafficFlowId traffic_flow_id) {
return traffic_flow_routes[traffic_flow_id];
}

const vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& NocTrafficFlows::get_all_traffic_flow_routes() const {
return traffic_flow_routes;
}
//const std::vector<NocLinkId>& NocTrafficFlows::get_traffic_flow_route(NocTrafficFlowId traffic_flow_id) const {
// return traffic_flow_routes[traffic_flow_id];
//}
//
//std::vector<NocLinkId>& NocTrafficFlows::get_mutable_traffic_flow_route(NocTrafficFlowId traffic_flow_id) {
// return traffic_flow_routes[traffic_flow_id];
//}
//
//const vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& NocTrafficFlows::get_all_traffic_flow_routes() const {
// return traffic_flow_routes;
//}

const std::vector<ClusterBlockId>& NocTrafficFlows::get_router_clusters_in_netlist() const {
return router_cluster_in_netlist;
Expand Down Expand Up @@ -107,7 +107,7 @@ void NocTrafficFlows::finished_noc_traffic_flows_setup() {

// create the storage space for all the traffic flow routes
int number_of_traffic_flows = noc_traffic_flows.size();
traffic_flow_routes.resize(number_of_traffic_flows);
// traffic_flow_routes.resize(number_of_traffic_flows);
}

void NocTrafficFlows::clear_traffic_flows() {
Expand All @@ -116,7 +116,7 @@ void NocTrafficFlows::clear_traffic_flows() {
noc_traffic_flows_ids.clear();
router_cluster_in_netlist.clear();
traffic_flows_associated_to_router_blocks.clear();
traffic_flow_routes.clear();
// traffic_flow_routes.clear();

// indicate that traffic flows need to be added again after clear
built_traffic_flows = false;
Expand Down
11 changes: 5 additions & 6 deletions vpr/src/noc/noc_traffic_flows.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ class NocTrafficFlows {
* traffic flows have been added. This datastructure should be used
* to store the path found whenever a traffic flow needs to be routed/
* re-routed. Also, this datastructure should be used to access the routed
* path of a traffic flow.
*
* path of a traffic flow.
*/
vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>> traffic_flow_routes;
// vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>> traffic_flow_routes;

// private functions

Expand Down Expand Up @@ -203,7 +202,7 @@ class NocTrafficFlows {
* @return std::vector<NocLinkId>& A reference to the provided
* traffic flow's routed path.
*/
const std::vector<NocLinkId>& get_traffic_flow_route(NocTrafficFlowId traffic_flow_id) const;
// const std::vector<NocLinkId>& get_traffic_flow_route(NocTrafficFlowId traffic_flow_id) const;

/**
* @brief Gets the routed path of a traffic flow. The path
Expand All @@ -214,7 +213,7 @@ class NocTrafficFlows {
* @return std::vector<NocLinkId>& A reference to the provided
* traffic flow's vector of links used from the src to dst.
*/
std::vector<NocLinkId>& get_mutable_traffic_flow_route(NocTrafficFlowId traffic_flow_id);
// std::vector<NocLinkId>& get_mutable_traffic_flow_route(NocTrafficFlowId traffic_flow_id);

/**
* @brief Gets all routed paths for all traffic flows. This cannot be
Expand All @@ -223,7 +222,7 @@ class NocTrafficFlows {
* @return vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& A reference
* to the provided container that includes all traffic flow routes.
*/
const vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& get_all_traffic_flow_routes() const;
// const vtr::vector<NocTrafficFlowId, std::vector<NocLinkId>>& get_all_traffic_flow_routes() const;

/**
* @return a vector ([0..num_logical_router-1]) where each entry gives the clusterBlockId
Expand Down
11 changes: 8 additions & 3 deletions vpr/src/place/RL_agent_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
const t_placer_opts& placer_opts,
int move_lim,
double noc_attraction_weight) {

e_reward_function reward_fun = string_to_reward(placer_opts.place_reward_fun);
std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> move_generators;


if (!placer_opts.RL_agent_placement) { // RL agent is disabled
auto move_types = placer_opts.place_static_move_prob;
move_types.resize((int)e_move_type::NUMBER_OF_AUTO_MOVES, 0.0f);
Expand All @@ -20,8 +21,8 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
move_name.c_str(),
placer_opts.place_static_move_prob[move_type]);
}
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, placer_opts.place_static_move_prob);
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, placer_opts.place_static_move_prob);
move_generators.first = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, placer_opts.place_static_move_prob);
move_generators.second = std::make_unique<StaticMoveGenerator>(placer_state, reward_fun, placer_opts.place_static_move_prob);
} else { //RL based placement
/* For the non timing driven placement: the agent has a single state *
* - Available moves are (Uniform / Median / Centroid) *
Expand Down Expand Up @@ -74,6 +75,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
}
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
reward_fun,
karmed_bandit_agent1,
noc_attraction_weight,
placer_opts.place_high_fanout_net);
Expand All @@ -83,6 +85,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
placer_opts.place_agent_epsilon);
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
reward_fun,
karmed_bandit_agent2,
noc_attraction_weight,
placer_opts.place_high_fanout_net);
Expand All @@ -100,6 +103,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
}
karmed_bandit_agent1->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.first = std::make_unique<SimpleRLMoveGenerator>(placer_state,
reward_fun,
karmed_bandit_agent1,
noc_attraction_weight,
placer_opts.place_high_fanout_net);
Expand All @@ -108,6 +112,7 @@ std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create
e_agent_space::MOVE_TYPE);
karmed_bandit_agent2->set_step(placer_opts.place_agent_gamma, move_lim);
move_generators.second = std::make_unique<SimpleRLMoveGenerator>(placer_state,
reward_fun,
karmed_bandit_agent2,
noc_attraction_weight,
placer_opts.place_high_fanout_net);
Expand Down
8 changes: 5 additions & 3 deletions vpr/src/place/centroid_move_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ vtr::vector<ClusterBlockId, NocGroupId> CentroidMoveGenerator::cluster_to_noc_gr
std::map<ClusterBlockId, NocGroupId> CentroidMoveGenerator::noc_router_to_noc_group_;


CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state)
: MoveGenerator(placer_state)
CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
e_reward_function reward_function)
: MoveGenerator(placer_state, reward_function)
, noc_attraction_w_(0.0f)
, noc_attraction_enabled_(false) {}

CentroidMoveGenerator::CentroidMoveGenerator(PlacerState& placer_state,
e_reward_function reward_function,
float noc_attraction_weight,
size_t high_fanout_net)
: MoveGenerator(placer_state)
: MoveGenerator(placer_state, reward_function)
, noc_attraction_w_(noc_attraction_weight)
, noc_attraction_enabled_(true) {
VTR_ASSERT(noc_attraction_weight > 0.0 && noc_attraction_weight <= 1.0);
Expand Down
4 changes: 3 additions & 1 deletion vpr/src/place/centroid_move_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class CentroidMoveGenerator : public MoveGenerator {
* @param placer_state A mutable reference to the placement state which will
* be stored in this object.
*/
explicit CentroidMoveGenerator(PlacerState& placer_state);
CentroidMoveGenerator(PlacerState& placer_state,
e_reward_function reward_function);

/**
* The move generator created by calling this constructor considers both
Expand All @@ -45,6 +46,7 @@ class CentroidMoveGenerator : public MoveGenerator {
* ignored when forming NoC groups.
*/
CentroidMoveGenerator(PlacerState& placer_state,
e_reward_function reward_function,
float noc_attraction_weight,
size_t high_fanout_net);

Expand Down
5 changes: 3 additions & 2 deletions vpr/src/place/critical_uniform_move_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include "placer_state.h"
#include "move_utils.h"

CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state)
: MoveGenerator(placer_state) {}
CriticalUniformMoveGenerator::CriticalUniformMoveGenerator(PlacerState& placer_state,
e_reward_function reward_function)
: MoveGenerator(placer_state, reward_function) {}

e_create_move CriticalUniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_affected,
t_propose_action& proposed_action,
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/place/critical_uniform_move_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
class CriticalUniformMoveGenerator : public MoveGenerator {
public:
CriticalUniformMoveGenerator() = delete;
explicit CriticalUniformMoveGenerator(PlacerState& placer_state);
CriticalUniformMoveGenerator(PlacerState& placer_state,
e_reward_function reward_function);

private:
e_create_move propose_move(t_pl_blocks_to_be_moved& blocks_affected,
Expand Down
Loading
Loading