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
38 changes: 29 additions & 9 deletions src/Compiler/CompilerOpenFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,11 @@ bool CompilerOpenFPGA::GenerateBitstream() {
std::filesystem::path config_mapping =
datapath / "configuration" / device_data.series /
(device_name + "_config_attributes.mapping.json");
std::filesystem::path routing_exe =
datapath / "configuration" / "routing_configurator.py";
std::filesystem::path routing_model = datapath / "configuration" /
device_data.series /
(device_name + "_routing.py");
std::filesystem::path backdoor_script =
datapath / "configuration" / device_data.series / "icb_backdoor.py";
if (!std::filesystem::exists(config_mapping)) {
Expand All @@ -3713,6 +3718,15 @@ bool CompilerOpenFPGA::GenerateBitstream() {
FilePath(Action::Synthesis, "io_config.json");
std::vector<std::filesystem::path> api_files =
FOEDAG::FileUtils::FindFilesByExtension(ric_folder.string(), ".json");
if (!std::filesystem::exists(routing_exe) ||
!std::filesystem::exists(routing_model)) {
#if 0
printf("Debug Routing exe: %s\n", routing_exe.c_str());
printf("Debug Routing model: %s\n", routing_model.c_str());
#endif
routing_exe = "";
routing_model = "";
}
if (std::filesystem::exists(ric_model) &&
std::filesystem::exists(config_mapping) &&
std::filesystem::exists(netlist_ppdb)) {
Expand Down Expand Up @@ -3770,21 +3784,27 @@ bool CompilerOpenFPGA::GenerateBitstream() {
if (CFG_find_string_in_vector({"Gemini", "Virgo"}, device_data.series) >=
0) {
command = CFG_print(
"%s\nmodel_config gen_ppdb -netlist_ppdb %s -config_mapping %s "
"-property_json model_config.property.json -pll_workaround 0 "
"%s\nmodel_config gen_ppdb -netlist_ppdb \"%s\" -config_mapping "
"\"%s\" -property_json model_config.property.json -routing_config "
"\"%s\" -routing_config_model \"%s\" -pll_workaround 0 "
"model_config.ppdb.json",
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str());
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str(),
routing_exe.c_str(), routing_model.c_str());
command = CFG_print(
"%s\nmodel_config gen_ppdb -netlist_ppdb %s -config_mapping %s "
"-property_json model_config.property.json -pll_workaround 1 "
"%s\nmodel_config gen_ppdb -netlist_ppdb \"%s\" -config_mapping "
"\"%s\" -property_json model_config.property.json -routing_config "
"\"%s\" -routing_config_model \"%s\" -pll_workaround 1 "
"model_config.post.ppdb.json",
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str());
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str(),
routing_exe.c_str(), routing_model.c_str());
gen_bitstream_count = 2;
} else {
command = CFG_print(
"%s\nmodel_config gen_ppdb -netlist_ppdb %s -config_mapping %s "
"-property_json model_config.property.json model_config.ppdb.json",
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str());
"%s\nmodel_config gen_ppdb -netlist_ppdb \"%s\" -config_mapping "
"\"%s\" -property_json model_config.property.json -routing_config "
"\"%s\" -routing_config_model \"%s\" model_config.ppdb.json",
command.c_str(), netlist_ppdb.c_str(), config_mapping.c_str(),
routing_exe.c_str(), routing_model.c_str());
}
std::string design = "model_config.ppdb.json";
std::string bit_file = "io_bitstream.bit";
Expand Down
45 changes: 33 additions & 12 deletions src/Configuration/CFGCommon/CFGCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ static void CFG_Python_get_result(PyObject* list,
}

std::map<std::string, CFG_Python_OBJ> CFG_Python(
std::vector<std::string> commands, std::vector<std::string> results,
std::vector<std::string> commands, const std::vector<std::string> results,
void* dict_ptr) {
PyObject* dict = nullptr;
if (dict_ptr == nullptr) {
Expand Down Expand Up @@ -935,26 +935,38 @@ std::vector<std::string> CFG_Python_OBJ::get_strs(const std::string& name) {
return strs;
}

CFG_Python_MGR::CFG_Python_MGR() {
CFG_Python_MGR::CFG_Python_MGR(const std::string& filepath,
const std::vector<std::string> results) {
Py_Initialize();
PyObject* dict = PyDict_New();
dict_ptr = dict;
if (filepath.size()) {
main_module = set_file(filepath, results);
CFG_ASSERT(main_module.size());
CFG_ASSERT(module_objs.find(main_module) != module_objs.end());
dict_ptr = PyModule_GetDict((PyObject*)(module_objs[main_module]));
} else {
CFG_ASSERT(main_module.empty());
PyObject* dict = PyDict_New();
dict_ptr = dict;
}
}

CFG_Python_MGR::~CFG_Python_MGR() {
if (dict_ptr != nullptr) {
if (main_module.empty() && dict_ptr != nullptr) {
PyObject* dict = static_cast<PyObject*>(dict_ptr);
Py_DECREF(dict);
dict_ptr = nullptr;
}
dict_ptr = nullptr;
for (auto& iter : module_objs) {
Py_XDECREF((PyObject*)(iter.second));
}
Py_Finalize();
main_module = "";
}

std::string CFG_Python_MGR::set_file(const std::string& file) {
CFG_ASSERT(dict_ptr != nullptr);
std::string CFG_Python_MGR::get_main_module() { return main_module; }

std::string CFG_Python_MGR::set_file(const std::string& file,
const std::vector<std::string> results) {
std::filesystem::path fullpath = std::filesystem::absolute(file.c_str());
CFG_ASSERT_MSG(std::filesystem::exists(fullpath),
"Python file %s does not exist", fullpath.c_str());
Expand All @@ -963,9 +975,11 @@ std::string CFG_Python_MGR::set_file(const std::string& file) {
std::filesystem::path dir = fullpath.parent_path();
std::filesystem::path filename = fullpath.filename();
std::string standard_dir = CFG_change_directory_to_linux_format(dir.string());
run({"import sys",
CFG_print("sys.path.insert(0, '%s')", standard_dir.c_str())},
{});
PyRun_SimpleString(CFG_print("import sys\n"
"if '%s' not in sys.path:\n"
" sys.path.insert(0, '%s')\n",
standard_dir.c_str(), standard_dir.c_str())
.c_str());
std::string module =
filename.string().substr(0, filename.string().size() - 3);
CFG_ASSERT(module_objs.find(module) == module_objs.end());
Expand All @@ -982,11 +996,18 @@ std::string CFG_Python_MGR::set_file(const std::string& file) {
module.c_str());
}
Py_XDECREF(pName);
if (results.size()) {
result_objs.clear();
PyObject* globals = PyModule_GetDict((PyObject*)(module_objs[module]));
for (auto key : results) {
CFG_Python_get_result(globals, key, result_objs);
}
}
return module;
}

void CFG_Python_MGR::run(std::vector<std::string> commands,
std::vector<std::string> results) {
const std::vector<std::string> results) {
CFG_ASSERT(dict_ptr != nullptr);
result_objs = CFG_Python(commands, results, dict_ptr);
}
Expand Down
13 changes: 9 additions & 4 deletions src/Configuration/CFGCommon/CFGCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ struct CFG_Python_OBJ {

class CFG_Python_MGR {
public:
CFG_Python_MGR();
CFG_Python_MGR(const std::string& filepath = "",
const std::vector<std::string> results = {});
~CFG_Python_MGR();
std::string set_file(const std::string& file);
void run(std::vector<std::string> commands, std::vector<std::string> results);
std::string get_main_module();
std::string set_file(const std::string& file,
const std::vector<std::string> results = {});
void run(std::vector<std::string> commands,
const std::vector<std::string> results);
std::vector<CFG_Python_OBJ> run_file(const std::string& module,
const std::string& function,
std::vector<CFG_Python_OBJ> args);
Expand All @@ -99,6 +103,7 @@ class CFG_Python_MGR {
std::vector<std::string> result_strs(const std::string& result);

private:
std::string main_module = "";
void* dict_ptr = nullptr;
std::map<std::string, CFG_Python_OBJ> result_objs;
std::map<std::string, void*> module_objs;
Expand Down Expand Up @@ -250,7 +255,7 @@ bool CFG_compare_two_binary_files(const std::string& filepath1,
const std::string& filepath2);

std::map<std::string, CFG_Python_OBJ> CFG_Python(
std::vector<std::string> commands, std::vector<std::string> results,
std::vector<std::string> commands, const std::vector<std::string> results,
void* dict_ptr = nullptr);

#define CFG_POST_MSG(...) \
Expand Down
1 change: 0 additions & 1 deletion src/Configuration/ModelConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ endif()
add_library(
${subsystem} ${CFG_LIB_TYPE}
ModelConfig.cpp
ModelConfig_IO_resource.cpp
ModelConfig_IO.cpp
ModelConfig_BITSTREAM_SETTING_XML.cpp
)
Expand Down
Loading