Skip to content

Commit

Permalink
refactor top level logic of crit path calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
w0lek committed Dec 5, 2023
1 parent 8c1e4dc commit ae0dc2d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 39 deletions.
4 changes: 4 additions & 0 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ struct NocContext : public Context {

class ServerContext : public Context {
public:
bool is_enabled() const { return is_enabled_; }
void set_enabled(bool is_enabled) { is_enabled_ = is_enabled; }

const Server& server() const { return server_; }
Server& server() { return server_; }

Expand All @@ -587,6 +590,7 @@ class ServerContext : public Context {
const std::shared_ptr<SetupHoldTimingInfo>& hold_timing_info() const { return hold_timing_info_; }

private:
bool is_enabled_ = false;
Server server_;
TaskResolver task_resolver_;

Expand Down
1 change: 1 addition & 0 deletions vpr/src/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void init_graphics_state(bool show_graphics_val,
draw_state->is_flat = is_flat;

if (server) {
g_vpr_ctx.server_ctx().set_enabled(true);
g_vpr_ctx.server_ctx().server().setPortNum(port_num);
g_timeout_add(200, redraw_callback, &application);
}
Expand Down
31 changes: 21 additions & 10 deletions vpr/src/draw/draw_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,20 +951,31 @@ void draw_crit_path(ezgl::renderer* g) {
return; //No timing to draw
}

ServerContext& server_ctx = g_vpr_ctx.server_ctx(); // shortcut
calcCritPath(server_ctx.critical_path_num(), server_ctx.path_type());
if (g_vpr_ctx.server_ctx().is_enabled()) {
ServerContext& server_ctx = g_vpr_ctx.server_ctx(); // shortcut

const auto& paths = server_ctx.crit_paths(); // shortcut
auto paths = server_ctx.crit_paths();

// check path index
if (server_ctx.crit_path_index() >= static_cast<int>(paths.size())) {
server_ctx.set_crit_path_index(-1);
}
if (server_ctx.crit_path_index() == -1) {
return;
// check path index
if (server_ctx.crit_path_index() >= static_cast<int>(paths.size())) {
server_ctx.set_crit_path_index(-1);
}
if (server_ctx.crit_path_index() != -1) {
tatum::TimingPath path = paths[server_ctx.crit_path_index()];
draw_crit_path(path, g);
}
} else {
const int crit_path_index = 0;
auto paths = calcSetupCritPaths(1);
if (paths.size()>0) {
auto path = paths[crit_path_index];
draw_crit_path(path, g);
}
}
}

tatum::TimingPath path = paths[server_ctx.crit_path_index()];
void draw_crit_path(const tatum::TimingPath& path, ezgl::renderer* g) {
t_draw_state* draw_state = get_draw_state_vars();

//Walk through the timing path drawing each edge
tatum::NodeId prev_node;
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/draw/draw_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void draw_routing_util(ezgl::renderer* g);
*/
void draw_crit_path(ezgl::renderer* g);

void draw_crit_path(const tatum::TimingPath& path, ezgl::renderer* g);

/* Draws critical path shown as flylines. Takes in start and end coordinates, time delay, & renderer.*/
void draw_flyline_timing_edge(ezgl::point2d start, ezgl::point2d end, float incr_delay, ezgl::renderer* g);

Expand Down
34 changes: 14 additions & 20 deletions vpr/src/server/pathhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,25 @@ std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, const std::
return ss.str();
}

void calcCritPath(int numMax, const std::string& type)
std::vector<tatum::TimingPath> calcSetupCritPaths(int numMax)
{
ServerContext& server_ctx = g_vpr_ctx.server_ctx(); // shortcut
tatum::TimingPathCollector path_collector;

server_ctx.set_critical_path_num(numMax);
server_ctx.set_path_type(type);
t_draw_state* draw_state = get_draw_state_vars();
auto& timing_ctx = g_vpr_ctx.timing();

return path_collector.collect_worst_setup_timing_paths(
*timing_ctx.graph,
*(draw_state->setup_timing_info->setup_analyzer()), numMax);
}

std::vector<tatum::TimingPath> calcHoldCritPaths(int numMax, const std::shared_ptr<SetupHoldTimingInfo>& hold_timing_info)
{
tatum::TimingPathCollector path_collector;

t_draw_state* draw_state = get_draw_state_vars();
auto& timing_ctx = g_vpr_ctx.timing();

if (type == "setup") {
auto paths = path_collector.collect_worst_setup_timing_paths(
*timing_ctx.graph,
*(draw_state->setup_timing_info->setup_analyzer()), numMax);
server_ctx.set_crit_paths(paths);
} else if (type == "hold") {
if (server_ctx.hold_timing_info()) {
auto paths = path_collector.collect_worst_hold_timing_paths(
*timing_ctx.graph,
*(server_ctx.hold_timing_info()->hold_analyzer()), numMax);
server_ctx.set_crit_paths(paths);
} else {
std::cerr << "g_vpr_ctx.hold_timing_info is nullptr" << std::endl;
}
}
return path_collector.collect_worst_hold_timing_paths(
*timing_ctx.graph,
*(hold_timing_info->hold_analyzer()), numMax);
}
7 changes: 6 additions & 1 deletion vpr/src/server/pathhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

#include <vector>
#include <string>
#include <memory>

#include "tatum/report/TimingPath.hpp"

class SetupHoldTimingInfo;

std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, const std::string& detailesLevel, bool is_flat_routing);
void calcCritPath(int numMax, const std::string& type);

std::vector<tatum::TimingPath> calcSetupCritPaths(int numMax);
std::vector<tatum::TimingPath> calcHoldCritPaths(int numMax, const std::shared_ptr<SetupHoldTimingInfo>& hold_timing_info);

#endif
38 changes: 30 additions & 8 deletions vpr/src/server/taskresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,41 @@ bool TaskResolver::update(ezgl::application* app)
if (task.cmd() == CMD_GET_PATH_LIST_ID) {
options.validateNamePresence({OPTION_PATH_NUM, OPTION_PATH_TYPE, OPTION_DETAILS_LEVEL, OPTION_IS_FLOAT_ROUTING});
int nCriticalPathNum = options.getInt(OPTION_PATH_NUM, 1);
std::string typePath = options.getString(OPTION_PATH_TYPE);
std::string pathType = options.getString(OPTION_PATH_TYPE);
std::string detailsLevel = options.getString(OPTION_DETAILS_LEVEL);
bool isFlat = options.getBool(OPTION_IS_FLOAT_ROUTING, false);
if (!options.hasErrors()) {
if (typePath != server_ctx.path_type()) {
if (pathType != server_ctx.path_type()) {
server_ctx.set_crit_path_index(-1);
}
calcCritPath(nCriticalPathNum, typePath);
std::string msg = getPathsStr(server_ctx.crit_paths(), detailsLevel, isFlat);
server_ctx.set_path_type(typePath); // duplicated
task.success(msg);

server_ctx.set_path_type(pathType);
server_ctx.set_critical_path_num(nCriticalPathNum);
if (pathType == "setup") {
auto paths = calcSetupCritPaths(nCriticalPathNum);
server_ctx.set_crit_paths(paths);
} else if (pathType == "hold") {
auto hold_timing_info = server_ctx.hold_timing_info();
if (hold_timing_info) {
auto paths = calcHoldCritPaths(nCriticalPathNum, hold_timing_info);
server_ctx.set_crit_paths(paths);
} else {
std::string msg{"cannot calculate hold critical path due to hold_timing_info nullptr"};
std::cerr << msg << std::endl;
task.fail(msg);
}
} else {
std::string msg{"unknown path type " + pathType};
std::cerr << msg << std::endl;
task.fail(msg);
}

if (!task.hasError()) {
std::string msg{getPathsStr(server_ctx.crit_paths(), detailsLevel, isFlat)};
task.success(msg);
}
} else {
std::string msg = "options errors in get crit path list telegram: " + options.errorsStr();
std::string msg{"options errors in get crit path list telegram: " + options.errorsStr()};
std::cerr << msg << std::endl;
task.fail(msg);
}
Expand All @@ -92,7 +114,7 @@ bool TaskResolver::update(ezgl::application* app)
task.fail(msg);
}
} else {
std::string msg = "selectedIndex=" + std::to_string(pathIndex) + " is out of range [0-" + std::to_string(static_cast<int>(server_ctx.crit_paths().size())-1) + "]";
std::string msg{"selectedIndex=" + std::to_string(pathIndex) + " is out of range [0-" + std::to_string(static_cast<int>(server_ctx.crit_paths().size())-1) + "]"};
std::cerr << msg << std::endl;
task.fail(msg);
}
Expand Down

0 comments on commit ae0dc2d

Please sign in to comment.