Skip to content

Commit 5cf4644

Browse files
New way to decide the IO routing configuration bits (#1706)
* New way to decide the IO routing configuration bits * Compilation warning as error * Compilation warning as error * Avoid hashlib because of msys2 * Windows issue * Debug windows * Windows debug * Tryout * Avoid using PyRun_File at all because windows seems to have known issue * Better sys path insertion * Perfect the code * Remove debug message * Update unit test file with latest compilation * Misc update on spacing
1 parent d8ddcde commit 5cf4644

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+11728
-8198
lines changed

src/Compiler/CompilerOpenFPGA.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,6 +3703,11 @@ bool CompilerOpenFPGA::GenerateBitstream() {
37033703
std::filesystem::path config_mapping =
37043704
datapath / "configuration" / device_data.series /
37053705
(device_name + "_config_attributes.mapping.json");
3706+
std::filesystem::path routing_exe =
3707+
datapath / "configuration" / "routing_configurator.py";
3708+
std::filesystem::path routing_model = datapath / "configuration" /
3709+
device_data.series /
3710+
(device_name + "_routing.py");
37063711
std::filesystem::path backdoor_script =
37073712
datapath / "configuration" / device_data.series / "icb_backdoor.py";
37083713
if (!std::filesystem::exists(config_mapping)) {
@@ -3713,6 +3718,15 @@ bool CompilerOpenFPGA::GenerateBitstream() {
37133718
FilePath(Action::Synthesis, "io_config.json");
37143719
std::vector<std::filesystem::path> api_files =
37153720
FOEDAG::FileUtils::FindFilesByExtension(ric_folder.string(), ".json");
3721+
if (!std::filesystem::exists(routing_exe) ||
3722+
!std::filesystem::exists(routing_model)) {
3723+
#if 0
3724+
printf("Debug Routing exe: %s\n", routing_exe.c_str());
3725+
printf("Debug Routing model: %s\n", routing_model.c_str());
3726+
#endif
3727+
routing_exe = "";
3728+
routing_model = "";
3729+
}
37163730
if (std::filesystem::exists(ric_model) &&
37173731
std::filesystem::exists(config_mapping) &&
37183732
std::filesystem::exists(netlist_ppdb)) {
@@ -3770,21 +3784,27 @@ bool CompilerOpenFPGA::GenerateBitstream() {
37703784
if (CFG_find_string_in_vector({"Gemini", "Virgo"}, device_data.series) >=
37713785
0) {
37723786
command = CFG_print(
3773-
"%s\nmodel_config gen_ppdb -netlist_ppdb %s -config_mapping %s "
3774-
"-property_json model_config.property.json -pll_workaround 0 "
3787+
"%s\nmodel_config gen_ppdb -netlist_ppdb \"%s\" -config_mapping "
3788+
"\"%s\" -property_json model_config.property.json -routing_config "
3789+
"\"%s\" -routing_config_model \"%s\" -pll_workaround 0 "
37753790
"model_config.ppdb.json",
3776-
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str());
3791+
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str(),
3792+
routing_exe.c_str(), routing_model.c_str());
37773793
command = CFG_print(
3778-
"%s\nmodel_config gen_ppdb -netlist_ppdb %s -config_mapping %s "
3779-
"-property_json model_config.property.json -pll_workaround 1 "
3794+
"%s\nmodel_config gen_ppdb -netlist_ppdb \"%s\" -config_mapping "
3795+
"\"%s\" -property_json model_config.property.json -routing_config "
3796+
"\"%s\" -routing_config_model \"%s\" -pll_workaround 1 "
37803797
"model_config.post.ppdb.json",
3781-
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str());
3798+
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str(),
3799+
routing_exe.c_str(), routing_model.c_str());
37823800
gen_bitstream_count = 2;
37833801
} else {
37843802
command = CFG_print(
3785-
"%s\nmodel_config gen_ppdb -netlist_ppdb %s -config_mapping %s "
3786-
"-property_json model_config.property.json model_config.ppdb.json",
3787-
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str());
3803+
"%s\nmodel_config gen_ppdb -netlist_ppdb \"%s\" -config_mapping "
3804+
"\"%s\" -property_json model_config.property.json -routing_config "
3805+
"\"%s\" -routing_config_model \"%s\" model_config.ppdb.json",
3806+
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str(),
3807+
routing_exe.c_str(), routing_model.c_str());
37883808
}
37893809
std::string design = "model_config.ppdb.json";
37903810
std::string bit_file = "io_bitstream.bit";

src/Configuration/CFGCommon/CFGCommon.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ static void CFG_Python_get_result(PyObject* list,
800800
}
801801

802802
std::map<std::string, CFG_Python_OBJ> CFG_Python(
803-
std::vector<std::string> commands, std::vector<std::string> results,
803+
std::vector<std::string> commands, const std::vector<std::string> results,
804804
void* dict_ptr) {
805805
PyObject* dict = nullptr;
806806
if (dict_ptr == nullptr) {
@@ -935,26 +935,38 @@ std::vector<std::string> CFG_Python_OBJ::get_strs(const std::string& name) {
935935
return strs;
936936
}
937937

938-
CFG_Python_MGR::CFG_Python_MGR() {
938+
CFG_Python_MGR::CFG_Python_MGR(const std::string& filepath,
939+
const std::vector<std::string> results) {
939940
Py_Initialize();
940-
PyObject* dict = PyDict_New();
941-
dict_ptr = dict;
941+
if (filepath.size()) {
942+
main_module = set_file(filepath, results);
943+
CFG_ASSERT(main_module.size());
944+
CFG_ASSERT(module_objs.find(main_module) != module_objs.end());
945+
dict_ptr = PyModule_GetDict((PyObject*)(module_objs[main_module]));
946+
} else {
947+
CFG_ASSERT(main_module.empty());
948+
PyObject* dict = PyDict_New();
949+
dict_ptr = dict;
950+
}
942951
}
943952

944953
CFG_Python_MGR::~CFG_Python_MGR() {
945-
if (dict_ptr != nullptr) {
954+
if (main_module.empty() && dict_ptr != nullptr) {
946955
PyObject* dict = static_cast<PyObject*>(dict_ptr);
947956
Py_DECREF(dict);
948-
dict_ptr = nullptr;
949957
}
958+
dict_ptr = nullptr;
950959
for (auto& iter : module_objs) {
951960
Py_XDECREF((PyObject*)(iter.second));
952961
}
953962
Py_Finalize();
963+
main_module = "";
954964
}
955965

956-
std::string CFG_Python_MGR::set_file(const std::string& file) {
957-
CFG_ASSERT(dict_ptr != nullptr);
966+
std::string CFG_Python_MGR::get_main_module() { return main_module; }
967+
968+
std::string CFG_Python_MGR::set_file(const std::string& file,
969+
const std::vector<std::string> results) {
958970
std::filesystem::path fullpath = std::filesystem::absolute(file.c_str());
959971
CFG_ASSERT_MSG(std::filesystem::exists(fullpath),
960972
"Python file %s does not exist", fullpath.c_str());
@@ -963,9 +975,11 @@ std::string CFG_Python_MGR::set_file(const std::string& file) {
963975
std::filesystem::path dir = fullpath.parent_path();
964976
std::filesystem::path filename = fullpath.filename();
965977
std::string standard_dir = CFG_change_directory_to_linux_format(dir.string());
966-
run({"import sys",
967-
CFG_print("sys.path.insert(0, '%s')", standard_dir.c_str())},
968-
{});
978+
PyRun_SimpleString(CFG_print("import sys\n"
979+
"if '%s' not in sys.path:\n"
980+
" sys.path.insert(0, '%s')\n",
981+
standard_dir.c_str(), standard_dir.c_str())
982+
.c_str());
969983
std::string module =
970984
filename.string().substr(0, filename.string().size() - 3);
971985
CFG_ASSERT(module_objs.find(module) == module_objs.end());
@@ -982,11 +996,18 @@ std::string CFG_Python_MGR::set_file(const std::string& file) {
982996
module.c_str());
983997
}
984998
Py_XDECREF(pName);
999+
if (results.size()) {
1000+
result_objs.clear();
1001+
PyObject* globals = PyModule_GetDict((PyObject*)(module_objs[module]));
1002+
for (auto key : results) {
1003+
CFG_Python_get_result(globals, key, result_objs);
1004+
}
1005+
}
9851006
return module;
9861007
}
9871008

9881009
void CFG_Python_MGR::run(std::vector<std::string> commands,
989-
std::vector<std::string> results) {
1010+
const std::vector<std::string> results) {
9901011
CFG_ASSERT(dict_ptr != nullptr);
9911012
result_objs = CFG_Python(commands, results, dict_ptr);
9921013
}

src/Configuration/CFGCommon/CFGCommon.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ struct CFG_Python_OBJ {
8383

8484
class CFG_Python_MGR {
8585
public:
86-
CFG_Python_MGR();
86+
CFG_Python_MGR(const std::string& filepath = "",
87+
const std::vector<std::string> results = {});
8788
~CFG_Python_MGR();
88-
std::string set_file(const std::string& file);
89-
void run(std::vector<std::string> commands, std::vector<std::string> results);
89+
std::string get_main_module();
90+
std::string set_file(const std::string& file,
91+
const std::vector<std::string> results = {});
92+
void run(std::vector<std::string> commands,
93+
const std::vector<std::string> results);
9094
std::vector<CFG_Python_OBJ> run_file(const std::string& module,
9195
const std::string& function,
9296
std::vector<CFG_Python_OBJ> args);
@@ -99,6 +103,7 @@ class CFG_Python_MGR {
99103
std::vector<std::string> result_strs(const std::string& result);
100104

101105
private:
106+
std::string main_module = "";
102107
void* dict_ptr = nullptr;
103108
std::map<std::string, CFG_Python_OBJ> result_objs;
104109
std::map<std::string, void*> module_objs;
@@ -250,7 +255,7 @@ bool CFG_compare_two_binary_files(const std::string& filepath1,
250255
const std::string& filepath2);
251256

252257
std::map<std::string, CFG_Python_OBJ> CFG_Python(
253-
std::vector<std::string> commands, std::vector<std::string> results,
258+
std::vector<std::string> commands, const std::vector<std::string> results,
254259
void* dict_ptr = nullptr);
255260

256261
#define CFG_POST_MSG(...) \

src/Configuration/ModelConfig/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ endif()
5151
add_library(
5252
${subsystem} ${CFG_LIB_TYPE}
5353
ModelConfig.cpp
54-
ModelConfig_IO_resource.cpp
5554
ModelConfig_IO.cpp
5655
ModelConfig_BITSTREAM_SETTING_XML.cpp
5756
)

0 commit comments

Comments
 (0)