Skip to content
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

Timed sim #1703

Merged
merged 1 commit into from
Sep 20, 2024
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
44 changes: 28 additions & 16 deletions src/Simulation/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,21 +1190,20 @@ bool Simulator::SimulatePNR(SimulatorType type) {
m_compiler->FilePath(Compiler::Action::Routing, netlistFile).string();
sdfFile = m_compiler->FilePath(Compiler::Action::Routing, sdfFile).string();

fileList += " " + netlistFile + " ";
for (auto path : m_gateSimulationModels) {
fileList += LibraryFileDirective(type) + path.string() + " ";
}

fileList = SimulationTypeMacro(SimulationType::PNR, type) + " " + fileList;

if (IsTimedSimulation()) {
fileList = " -DTIMED_SIM=1 " + fileList;
if (type == SimulatorType::Icarus) {
fileList = " -gspecify " + fileList;
std::filesystem::path sdfFilePath = sdfFile;
std::string sdfBlastedFile =
"fabric_" + m_compiler->DesignTopModule() + "_post_route_blasted.sdf";
sdfBlastedFile =
m_compiler->FilePath(Compiler::Action::Routing, sdfBlastedFile)
.string();
std::filesystem::path sdfBlastedFilePath = sdfBlastedFile;
// Icarus ignores the timescale present in the SDF file, so we need
// to scale the content from ps to ns to match the simulation timescale.
if (!FileUtils::convertPstoNsInSDFFile(sdfFilePath)) {
if (!FileUtils::convertPstoNsInSDFFile(sdfFilePath, sdfBlastedFilePath)) {
ErrorMessage("SDF Unit Conversion for Icarus failed!\n");
return false;
}
Expand All @@ -1229,23 +1228,36 @@ bool Simulator::SimulatePNR(SimulatorType type) {
std::filesystem::path ram_map = tech_datapath / "FPGA_PRIMITIVES_MODELS" /
"sim_models" / "primitives_mapping" /
"BRAM" / "rs_tdp36k_post_pnr_mapping.v";
std::string command = std::string(bitblast_exe.string()) +
" -nostdout -DSYNTHESIS=1 -top fabric_" +
m_compiler->DesignTopModule() + " " + netlistFile +
" -v " + primitives_file.string() + " " +
dsp_map.string() + " " + ram_map.string() + " -y " +
library_path.string() + " -bitblast -sdf_in " +
sdfFilePath.string() + " -sdf_out " +
sdfFilePath.string() + " -write " + netlistFile;
std::string netlistBlastedFile =
"fabric_" + m_compiler->DesignTopModule() + "_post_route_blasted.v";
netlistBlastedFile =
m_compiler->FilePath(Compiler::Action::Routing, netlistBlastedFile)
.string();
std::string command =
std::string(bitblast_exe.string()) +
" -nostdout -DSYNTHESIS=1 -top fabric_" +
m_compiler->DesignTopModule() + " " + netlistFile + " -v " +
primitives_file.string() + " " + dsp_map.string() + " " +
ram_map.string() + " -y " + library_path.string() +
" -bitblast -sdf_in " + sdfBlastedFilePath.string() + " -sdf_out " +
sdfBlastedFilePath.string() + " -write " + netlistBlastedFile;
int status = m_compiler->ExecuteAndMonitorSystemCommand(
command, "bitblast.log", false, workingDir);
if (status) {
ErrorMessage("Design " + ProjManager()->projectName() +
" Post-PnR simulation failed!\n");
return false;
}
netlistFile = netlistBlastedFile;
}
}
fileList += " " + netlistFile + " ";

for (auto path : m_gateSimulationModels) {
fileList += LibraryFileDirective(type) + path.string() + " ";
}

fileList = SimulationTypeMacro(SimulationType::PNR, type) + " " + fileList;

fileList = StringUtils::rtrim(fileList);

Expand Down
12 changes: 7 additions & 5 deletions src/Utils/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,14 @@ void FileUtils::MoveFolder(const std::filesystem::path& from,
fs::remove_all(from, ec);
}

bool FileUtils::convertPstoNsInSDFFile(const std::filesystem::path& path) {
if (path.empty()) return false;
if (!FileUtils::FileExists(path)) {
bool FileUtils::convertPstoNsInSDFFile(const std::filesystem::path& in_path,
const std::filesystem::path& out_path) {
if (in_path.empty()) return false;
if (out_path.empty()) return false;
if (!FileUtils::FileExists(in_path)) {
return false;
}
std::string content = GetFileContent(path);
std::string content = GetFileContent(in_path);
if (content.find("TIMESCALE 1 ns") != std::string::npos) {
// Already converted
return true;
Expand Down Expand Up @@ -470,7 +472,7 @@ bool FileUtils::convertPstoNsInSDFFile(const std::filesystem::path& path) {
}
}

WriteToFile(path, result);
WriteToFile(out_path, result);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Utils/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class FileUtils final {

static void terminateSystemCommand();

static bool convertPstoNsInSDFFile(const std::filesystem::path& path);
static bool convertPstoNsInSDFFile(const std::filesystem::path& in_path,
const std::filesystem::path& out_path);

private:
FileUtils() = delete;
Expand Down
Loading