Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 0 additions & 10 deletions src/feature/database/feature_irt.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ struct PRSummary
double total_demand = 0;
double total_overflow = 0;
double total_wire_length = 0;
std::map<std::string, std::map<std::string, double>> clock_timing_map;
std::map<std::string, double> type_power_map;
};

struct LASummary
Expand All @@ -63,8 +61,6 @@ struct LASummary
double total_wire_length = 0;
std::map<int32_t, int32_t> cut_via_num_map;
int32_t total_via_num = 0;
std::map<std::string, std::map<std::string, double>> clock_timing_map;
std::map<std::string, double> type_power_map;
};

struct SRSummary
Expand All @@ -77,8 +73,6 @@ struct SRSummary
double total_wire_length = 0;
std::map<int32_t, int32_t> cut_via_num_map;
int32_t total_via_num = 0;
std::map<std::string, std::map<std::string, double>> clock_timing_map;
std::map<std::string, double> type_power_map;
};

struct TASummary
Expand All @@ -99,8 +93,6 @@ struct DRSummary
int32_t total_patch_num = 0;
std::map<int32_t, int32_t> routing_violation_num_map;
int32_t total_violation_num = 0;
std::map<std::string, std::map<std::string, double>> clock_timing_map;
std::map<std::string, double> type_power_map;
};

struct VRSummary
Expand All @@ -119,8 +111,6 @@ struct VRSummary
std::map<std::string, int32_t> among_net_violation_type_num_map;
std::map<int32_t, int32_t> among_net_routing_violation_num_map;
int32_t among_net_total_violation_num = 0;
std::map<std::string, std::map<std::string, double>> clock_timing_map;
std::map<std::string, double> type_power_map;
};

struct RTSummary
Expand Down
40 changes: 0 additions & 40 deletions src/feature/parser/feature_parser_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ json FeatureParser::buildSummaryRT()
pr_json["total_demand"] = summary_irt.pr_summary.total_demand;
pr_json["total_overflow"] = summary_irt.pr_summary.total_overflow;
pr_json["total_wire_length"] = summary_irt.pr_summary.total_wire_length;
for (auto& [clock_name, timing] : summary_irt.pr_summary.clock_timing_map) {
pr_json["clock_timing_map"]["clock_name"] = clock_name;
pr_json["clock_timing_map"]["timing"] = timing;
}
for (auto& [type, power] : summary_irt.pr_summary.type_power_map) {
pr_json["type_power_map"]["type"] = type;
pr_json["type_power_map"]["power"] = power;
}
json_rt["PR"] = pr_json;
}

Expand All @@ -115,14 +107,6 @@ json FeatureParser::buildSummaryRT()
la_json["cut_via_num_map"][std::to_string(cut_layer_idx)] = via_num;
}
la_json["total_via_num"] = summary_irt.la_summary.total_via_num;
for (auto& [clock_name, timing] : summary_irt.la_summary.clock_timing_map) {
la_json["clock_timing_map"]["clock_name"] = clock_name;
la_json["clock_timing_map"]["timing"] = timing;
}
for (auto& [type, power] : summary_irt.la_summary.type_power_map) {
la_json["type_power_map"]["type"] = type;
la_json["type_power_map"]["power"] = power;
}
json_rt["LA"] = la_json;
}

Expand All @@ -148,14 +132,6 @@ json FeatureParser::buildSummaryRT()
sr_json["cut_via_num_map"][std::to_string(cut_layer_idx)] = via_num;
}
sr_json["total_via_num"] = sr_summary.total_via_num;
for (auto& [clock_name, timing] : sr_summary.clock_timing_map) {
sr_json["clock_timing_map"]["clock_name"] = clock_name;
sr_json["clock_timing_map"]["timing"] = timing;
}
for (auto& [type, power] : sr_summary.type_power_map) {
sr_json["type_power_map"]["type"] = type;
sr_json["type_power_map"]["power"] = power;
}
sr_json_list.push_back(sr_json);
}
json_rt["SR"] = sr_json_list;
Expand Down Expand Up @@ -197,14 +173,6 @@ json FeatureParser::buildSummaryRT()
dr_json["routing_violation_num_map"][std::to_string(routing_layer_idx)] = violation_num;
}
dr_json["total_violation_num"] = dr_summary.total_violation_num;
for (auto& [clock_name, timing] : dr_summary.clock_timing_map) {
dr_json["clock_timing_map"]["clock_name"] = clock_name;
dr_json["clock_timing_map"]["timing"] = timing;
}
for (auto& [type, power] : dr_summary.type_power_map) {
dr_json["type_power_map"]["type"] = type;
dr_json["type_power_map"]["power"] = power;
}
dr_json_list.push_back(dr_json);
}
json_rt["DR"] = dr_json_list;
Expand Down Expand Up @@ -233,14 +201,6 @@ json FeatureParser::buildSummaryRT()
vr_json["among_net_routing_violation_num_map"][std::to_string(routing_layer_idx)] = violation_num;
}
vr_json["among_net_total_violation_num"] = summary_irt.vr_summary.among_net_total_violation_num;
for (auto& [clock_name, timing] : summary_irt.vr_summary.clock_timing_map) {
vr_json["clock_timing_map"]["clock_name"] = clock_name;
vr_json["clock_timing_map"]["timing"] = timing;
}
for (auto& [type, power] : summary_irt.vr_summary.type_power_map) {
vr_json["type_power_map"]["type"] = type;
vr_json["type_power_map"]["power"] = power;
}
json_rt["VR"] = vr_json;
}

Expand Down
34 changes: 18 additions & 16 deletions src/interface/python/py_irt/py_irt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,39 @@
// ***************************************************************************************
#include "py_irt.h"

#include <tcl_util.h>

#include <string>

#include "RTInterface.hpp"

namespace python_interface {

bool initConfigMapByJSON(const std::string& config, std::map<std::string, std::any>& config_map);
bool initRTConfigMapByJSON(const std::string& config, std::map<std::string, std::any>& config_map);
void initRTConfigMapByDict(std::map<std::string, std::string>& config_dict, std::map<std::string, std::any>& config_map);
bool initERTConfigMapByJSON(const std::string& config, std::map<std::string, std::any>& config_map);
void initERTConfigMapByDict(std::map<std::string, std::string>& config_dict, std::map<std::string, std::any>& config_map);

bool destroyRT()
bool initRT(std::string& config, std::map<std::string, std::string>& config_dict)
{
RTI.destroyRT();
std::map<std::string, std::any> config_map;

bool pass = config.empty() ? true : initRTConfigMapByJSON(config, config_map);
if (!pass) {
return false;
}
initRTConfigMapByDict(config_dict, config_map);
RTI.initRT(config_map);
return true;
}

bool runERT(std::string& config, std::map<std::string, std::string>& config_dict)
{
std::map<std::string, std::any> config_map;

bool pass = false;
pass = !pass ? initConfigMapByJSON(config, config_map) : pass;
bool pass = config.empty() ? true : initERTConfigMapByJSON(config, config_map);
if (!pass) {
return false;
}
initERTConfigMapByDict(config_dict, config_map);
RTI.runERT(config_map);
return true;
}
Expand All @@ -50,16 +59,9 @@ bool runRT()
return true;
}

bool initRT(std::string& config, std::map<std::string, std::string>& config_dict)
bool destroyRT()
{
std::map<std::string, std::any> config_map;

bool pass = false;
pass = !pass ? initConfigMapByJSON(config, config_map) : pass;
if (!pass) {
return false;
}
RTI.initRT(config_map);
RTI.destroyRT();
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions src/interface/python/py_irt/py_irt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

namespace python_interface {

bool destroyRT();
bool initRT(std::string& config, std::map<std::string, std::string>& config_dict);
bool runDR();
bool runERT(std::string& config, std::map<std::string, std::string>& config_dict);
bool runRT();
bool destroyRT();

} // namespace python_interface
145 changes: 62 additions & 83 deletions src/interface/python/py_irt/py_irt_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,112 +14,91 @@
//
// See the Mulan PSL v2 for more details.
// ***************************************************************************************
#include <tcl_util.h>

#include <string>

#include "RTInterface.hpp"
#include "json_parser.h"
#include "py_irt.h"

namespace python_interface {
using tcl::ValueType;

std::map<std::string, double> strToDoubleMap(const std::string& input)
{
// Trim the leading and trailing whitespaces from the input
std::string input_trimmed = input;
input_trimmed.erase(input_trimmed.begin(),
std::find_if(input_trimmed.begin(), input_trimmed.end(), [](int ch) { return !std::isspace(ch); }));
input_trimmed.erase(std::find_if(input_trimmed.rbegin(), input_trimmed.rend(), [](int ch) { return !std::isspace(ch); }).base(),
input_trimmed.end());
std::map<std::string, double> result;
std::stringstream ss(input_trimmed.substr(1, input_trimmed.length() - 2));
std::string item;
while (std::getline(ss, item, ',')) {
size_t pos = item.find(":");
std::string key = item.substr(0, pos);
// Trim whitespaces from the key and value
key.erase(std::remove_if(key.begin(), key.end(), [](unsigned char c) { return std::isspace(c); }), key.end());
std::string value_str = item.substr(pos + 1);
value_str.erase(std::remove_if(value_str.begin(), value_str.end(), [](unsigned char c) { return std::isspace(c); }), value_str.end());
double value = std::stod(value_str);
result[key] = value;
}
return result;
}

std::vector<std::string> strToVector(const std::string& input)
bool initRTConfigMapByJSON(const std::string& config, std::map<std::string, std::any>& config_map)
{
std::vector<std::string> result;
std::string token;
for (char c : input) {
switch (c) {
case ' ':
case ',': {
if (!token.empty()) {
result.push_back(token);
token.clear();
}
break;
}
default:
token.push_back(c);
}
}
return result;
}
auto config_file = std::ifstream(config);
if (!config_file.is_open()) {
return false;
}
nlohmann::json json;
config_file >> json;
std::string value = ecc::getJsonData(json, {"RT", "-temp_directory_path"});
if (!value.empty()) {
config_map["-temp_directory_path"] = value;
}
value = ecc::getJsonData(json, {"RT", "-bottom_routing_layer"});
if (!value.empty()) {
config_map["-bottom_routing_layer"] = value;
}
value = ecc::getJsonData(json, {"RT", "-top_routing_layer"});
if (!value.empty()) {
config_map["-top_routing_layer"] = value;
}
value = ecc::getJsonData(json, {"RT", "-thread_number"});
if (!value.empty()) {
config_map["-thread_number"] = std::stoi(value);
}
value = ecc::getJsonData(json, {"RT", "-output_inter_result"});
if (!value.empty()) {
config_map["-output_inter_result"] = std::stoi(value);
}

std::vector<double> strToDoubleVec(const std::string& input)
{
auto tmp = strToVector(input);
std::vector<double> result;
result.reserve(tmp.size());
for_each(tmp.begin(), tmp.end(), [&result](const std::string& s) { result.push_back(std::stod(s)); });
return result;
return true;
}

std::vector<int> strToIntVec(const std::string& input)
void initRTConfigMapByDict(std::map<std::string, std::string>& config_dict, std::map<std::string, std::any>& config_map)
{
auto tmp = strToVector(input);
std::vector<int> result;
result.reserve(tmp.size());
for_each(tmp.begin(), tmp.end(), [&result](const std::string& s) { result.push_back(std::stoi(s)); });
return result;
if (config_dict.count("-temp_directory_path") > 0 && !config_dict["-temp_directory_path"].empty()) {
config_map["-temp_directory_path"] = config_dict["-temp_directory_path"];
}
if (config_dict.count("-bottom_routing_layer") > 0 && !config_dict["-bottom_routing_layer"].empty()) {
config_map["-bottom_routing_layer"] = config_dict["-bottom_routing_layer"];
}
if (config_dict.count("-top_routing_layer") > 0 && !config_dict["-top_routing_layer"].empty()) {
config_map["-top_routing_layer"] = config_dict["-top_routing_layer"];
}
if (config_dict.count("-thread_number") > 0 && !config_dict["-thread_number"].empty()) {
config_map["-thread_number"] = std::stoi(config_dict["-thread_number"]);
}
if (config_dict.count("-output_inter_result") > 0 && !config_dict["-output_inter_result"].empty()) {
config_map["-output_inter_result"] = std::stoi(config_dict["-output_inter_result"]);
}
}

// 通过json文件对config进行初始化
bool initConfigMapByJSON(const std::string& config, std::map<std::string, std::any>& config_map)
bool initERTConfigMapByJSON(const std::string& config, std::map<std::string, std::any>& config_map)
{
auto config_file = std::ifstream(config);
if (!config_file.is_open()) {
return false;
}
nlohmann::json json;
config_file >> json;
nlohmann::json rt_json = json["RT"];
std::string value;
value = ecc::getJsonData(json, {"RT", "-temp_directory_path"});
config_map.insert(std::make_pair("-temp_directory_path", value));
value = ecc::getJsonData(json, {"RT", "-bottom_routing_layer"});
config_map.insert(std::make_pair("-bottom_routing_layer", value));
value = ecc::getJsonData(json, {"RT", "-top_routing_layer"});
config_map.insert(std::make_pair("-top_routing_layer", value));
value = ecc::getJsonData(json, {"RT", "-thread_number"});
config_map.insert(std::make_pair("-thread_number", std::stoi(value)));
value = ecc::getJsonData(json, {"RT", "-enable_timing"});
config_map.insert(std::make_pair("-enable_timing", std::stoi(value)));
value = ecc::getJsonData(json, {"RT", "-output_inter_result"});
config_map.insert(std::make_pair("-output_inter_result", std::stoi(value)));
if (json.contains("RT") && json["RT"].contains("-enable_fast_mode")) {
value = ecc::getJsonData(json, {"RT", "-enable_fast_mode"});
config_map.insert(std::make_pair("-enable_fast_mode", std::stoi(value)));
std::string value = ecc::getJsonData(json, {"RT", "-stage"});
if (!value.empty()) {
config_map["-stage"] = value;
}
for (nlohmann::json::iterator item = rt_json.begin(); item != rt_json.end(); ++item) {
config_map.insert(std::make_pair(item.key(), item.value()));
value = ecc::getJsonData(json, {"RT", "-resolve_congestion"});
if (!value.empty()) {
config_map["-resolve_congestion"] = value;
}

return true;
}

} // namespace python_interface
void initERTConfigMapByDict(std::map<std::string, std::string>& config_dict, std::map<std::string, std::any>& config_map)
{
if (config_dict.count("-stage") > 0 && !config_dict["-stage"].empty()) {
config_map["-stage"] = config_dict["-stage"];
}
if (config_dict.count("-resolve_congestion") > 0 && !config_dict["-resolve_congestion"].empty()) {
config_map["-resolve_congestion"] = config_dict["-resolve_congestion"];
}
}

} // namespace python_interface
4 changes: 2 additions & 2 deletions src/interface/python/py_irt/py_register_irt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace python_interface {
namespace py = pybind11;
void register_irt(py::module& m)
{
m.def("destroy_rt", destroyRT);
m.def("init_rt", initRT, py::arg("config") = "", py::arg("config_dict") = std::map<std::string, std::string>{});
m.def("run_ert", runERT, py::arg("config") = "", py::arg("config_dict") = std::map<std::string, std::string>{});
m.def("run_rt", runRT);
m.def("destroy_rt", destroyRT);
}
} // namespace python_interface
} // namespace python_interface
1 change: 0 additions & 1 deletion src/interface/tcl/tcl_irt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ add_library(tcl_irt
${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_run_ert.cpp
${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_run_rt.cpp
${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_destroy_rt.cpp
${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_rt_clean_def.cpp
)

target_link_libraries(tcl_irt
Expand Down
Loading
Loading