add XML writer for simulation setting object

This commit is contained in:
tangxifan 2020-01-18 16:41:42 -07:00
parent bc3130d196
commit 9693c3a12d
6 changed files with 270 additions and 29 deletions

View File

@ -278,12 +278,12 @@
</measurement_setting> </measurement_setting>
<stimulus> <stimulus>
<clock> <clock>
<rise slew_time="20e-12" slew_type="abs"/> <rise slew_type="abs" slew_time="20e-12" />
<fall slew_time="20e-12" slew_type="abs"/> <fall slew_type="abs" slew_time="20e-12" />
</clock> </clock>
<input> <input>
<rise slew_time="25e-12" slew_type="abs"/> <rise slew_type="abs" slew_time="25e-12" />
<fall slew_time="25e-12" slew_type="abs"/> <fall slew_type="abs" slew_time="25e-12" />
</input> </input>
</stimulus> </stimulus>
</openfpga_simulation_setting> </openfpga_simulation_setting>

View File

@ -53,10 +53,6 @@ e_sim_accuracy_type SimulationSetting::simulation_accuracy_type() const {
} }
float SimulationSetting::simulation_accuracy() const { float SimulationSetting::simulation_accuracy() const {
/* If fractional accuracy is selected, we give a zero accuracy */
if (SIM_ACCURACY_FRAC == simulation_accuracy_type()) {
return 0.;
}
return simulation_accuracy_; return simulation_accuracy_;
} }
@ -97,10 +93,6 @@ e_sim_accuracy_type SimulationSetting::stimuli_clock_slew_type(const e_sim_signa
} }
float SimulationSetting::stimuli_clock_slew(const e_sim_signal_type& signal_type) const { float SimulationSetting::stimuli_clock_slew(const e_sim_signal_type& signal_type) const {
/* If fractional accuracy is selected, we give a zero accuracy */
if (SIM_ACCURACY_FRAC == stimuli_clock_slew_type(signal_type)) {
return 0.;
}
return clock_slews_[signal_type]; return clock_slews_[signal_type];
} }
@ -109,10 +101,6 @@ e_sim_accuracy_type SimulationSetting::stimuli_input_slew_type(const e_sim_signa
} }
float SimulationSetting::stimuli_input_slew(const e_sim_signal_type& signal_type) const { float SimulationSetting::stimuli_input_slew(const e_sim_signal_type& signal_type) const {
/* If fractional accuracy is selected, we give a zero accuracy */
if (SIM_ACCURACY_FRAC == stimuli_input_slew_type(signal_type)) {
return 0.;
}
return input_slews_[signal_type]; return input_slews_[signal_type];
} }
@ -153,10 +141,6 @@ void SimulationSetting::set_simulation_accuracy_type(const e_sim_accuracy_type&
} }
void SimulationSetting::set_simulation_accuracy(const float& accuracy) { void SimulationSetting::set_simulation_accuracy(const float& accuracy) {
/* If fractional accuracy is selected, we do nothing */
if (SIM_ACCURACY_FRAC == simulation_accuracy_type()) {
return;
}
simulation_accuracy_ = accuracy; simulation_accuracy_ = accuracy;
} }
@ -204,10 +188,6 @@ void SimulationSetting::set_stimuli_clock_slew_type(const e_sim_signal_type& sig
void SimulationSetting::set_stimuli_clock_slew(const e_sim_signal_type& signal_type, void SimulationSetting::set_stimuli_clock_slew(const e_sim_signal_type& signal_type,
const float& clock_slew) { const float& clock_slew) {
/* If fractional accuracy is selected, we do nothing */
if (SIM_ACCURACY_FRAC == stimuli_clock_slew_type(signal_type)) {
return;
}
clock_slews_[signal_type] = clock_slew; clock_slews_[signal_type] = clock_slew;
} }
@ -219,10 +199,6 @@ void SimulationSetting::set_stimuli_input_slew_type(const e_sim_signal_type& sig
void SimulationSetting::set_stimuli_input_slew(const e_sim_signal_type& signal_type, void SimulationSetting::set_stimuli_input_slew(const e_sim_signal_type& signal_type,
const float& input_slew) { const float& input_slew) {
/* If fractional accuracy is selected, we do nothing */
if (SIM_ACCURACY_FRAC == stimuli_input_slew_type(signal_type)) {
return;
}
input_slews_[signal_type] = input_slew; input_slews_[signal_type] = input_slew;
} }

View File

@ -32,7 +32,7 @@ enum e_sim_accuracy_type {
NUM_SIM_ACCURACY_TYPES NUM_SIM_ACCURACY_TYPES
}; };
/* Strings correspond to each accuracy type */ /* Strings correspond to each accuracy type */
constexpr std::array<const char*, NUM_SIM_ACCURACY_TYPES> SIM_ACCUARCY_TYPE_STRING = {{"frac", "abs"}}; constexpr std::array<const char*, NUM_SIM_ACCURACY_TYPES> SIM_ACCURACY_TYPE_STRING = {{"frac", "abs"}};
/******************************************************************** /********************************************************************
* A data structure to describe simulation settings * A data structure to describe simulation settings

View File

@ -10,6 +10,7 @@
/* Headers from readarchopenfpga library */ /* Headers from readarchopenfpga library */
#include "write_xml_circuit_library.h" #include "write_xml_circuit_library.h"
#include "write_xml_technology_library.h" #include "write_xml_technology_library.h"
#include "write_xml_simulation_setting.h"
#include "write_xml_openfpga_arch.h" #include "write_xml_openfpga_arch.h"
/******************************************************************** /********************************************************************
@ -34,5 +35,8 @@ void write_xml_openfpga_arch(const char* fname,
/* Write the circuit library */ /* Write the circuit library */
write_xml_circuit_library(fp, fname, openfpga_arch.circuit_lib); write_xml_circuit_library(fp, fname, openfpga_arch.circuit_lib);
/* Write the simulation */
write_xml_simulation_setting(fp, fname, openfpga_arch.sim_setting);
fp << "</openfpga_architecture>" << "\n"; fp << "</openfpga_architecture>" << "\n";
} }

View File

@ -0,0 +1,244 @@
/********************************************************************
* This file includes functions that outputs a simulation setting to XML format
*******************************************************************/
/* Headers from system goes first */
#include <string>
#include <algorithm>
/* Headers from vtr util library */
#include "vtr_assert.h"
#include "vtr_log.h"
#include "openfpga_digest.h"
/* Headers from readarchopenfpga library */
#include "write_xml_utils.h"
#include "write_xml_simulation_setting.h"
/********************************************************************
* A writer to output a clock setting in a simulation setting to XML format
*******************************************************************/
static
void write_xml_clock_setting(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
fp << "\t" << "<clock_setting>" << "\n";
fp << "\t\t" << "<operating";
write_xml_attribute(fp, "frequency", sim_setting.operating_clock_frequency());
if (true == sim_setting.auto_select_num_clock_cycles()) {
write_xml_attribute(fp, "num_cycles", "auto");
} else {
VTR_ASSERT_SAFE(false == sim_setting.auto_select_num_clock_cycles());
write_xml_attribute(fp, "num_cycles", std::to_string(sim_setting.num_clock_cycles()).c_str());
}
write_xml_attribute(fp, "slack", std::to_string(sim_setting.operating_clock_frequency_slack()).c_str());
fp << "/>" << "\n";
fp << "\t\t" << "<operating";
write_xml_attribute(fp, "frequency", sim_setting.programming_clock_frequency());
fp << "/>" << "\n";
fp << "\t" << "</clock_setting>" << "\n";
}
/********************************************************************
* A writer to output a simulator option in a simulation setting to XML format
*******************************************************************/
static
void write_xml_simulator_option(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
fp << "\t" << "<simulator_option>" << "\n";
fp << "\t\t" << "<operating_condition";
write_xml_attribute(fp, "temperature", sim_setting.simulation_temperature());
fp << "/>" << "\n";
fp << "\t\t" << "<output_log";
write_xml_attribute(fp, "verbose", sim_setting.verbose_output());
write_xml_attribute(fp, "captab", sim_setting.capacitance_output());
fp << "/>" << "\n";
fp << "\t\t" << "<accuracy";
write_xml_attribute(fp, "type", SIM_ACCURACY_TYPE_STRING[sim_setting.simulation_accuracy_type()]);
write_xml_attribute(fp, "value", sim_setting.simulation_accuracy());
fp << "/>" << "\n";
fp << "\t\t" << "<runtime";
write_xml_attribute(fp, "fast_simulation", sim_setting.fast_simulation());
fp << "/>" << "\n";
fp << "\t" << "</simulator_option>" << "\n";
}
/********************************************************************
* A writer to output a monte carlo simulation setting
* in a simulation setting to XML format
*******************************************************************/
static
void write_xml_monte_carlo(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
/* This is an optional setting,
* If defined, we will output the monte carlo simulation
*/
if (false == sim_setting.run_monte_carlo_simulation()) {
return;
}
fp << "\t\t" << "<monte_carlo";
write_xml_attribute(fp, "num_simulation_points", std::to_string(sim_setting.monte_carlo_simulation_points()).c_str());
fp << "/>" << "\n";
}
/********************************************************************
* A writer to output the slew measurement setting in a simulation setting to XML format
*******************************************************************/
static
void write_xml_slew_measurement(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting,
const e_sim_signal_type& signal_type) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
fp << "\t\t\t" << "<" << SIM_SIGNAL_TYPE_STRING[signal_type];
write_xml_attribute(fp, "upper_thres_pct", sim_setting.measure_slew_upper_threshold(signal_type));
write_xml_attribute(fp, "lower_thres_pct", sim_setting.measure_slew_lower_threshold(signal_type));
fp << "/>" << "\n";
}
/********************************************************************
* A writer to output the delay measurement setting in a simulation setting to XML format
*******************************************************************/
static
void write_xml_delay_measurement(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting,
const e_sim_signal_type& signal_type) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
fp << "\t\t\t" << "<" << SIM_SIGNAL_TYPE_STRING[signal_type];
write_xml_attribute(fp, "input_thres_pct", sim_setting.measure_delay_input_threshold(signal_type));
write_xml_attribute(fp, "output_thres_pct", sim_setting.measure_delay_output_threshold(signal_type));
fp << "/>" << "\n";
}
/********************************************************************
* A writer to output a measurement setting in a simulation setting to XML format
*******************************************************************/
static
void write_xml_measurement(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
fp << "\t" << "<measurement_setting>" << "\n";
fp << "\t\t" << "<slew>" << "\n";
write_xml_slew_measurement(fp, fname, sim_setting, SIM_SIGNAL_RISE);
write_xml_slew_measurement(fp, fname, sim_setting, SIM_SIGNAL_FALL);
fp << "\t\t" << "</slew>" << "\n";
fp << "\t\t" << "<delay>" << "\n";
write_xml_delay_measurement(fp, fname, sim_setting, SIM_SIGNAL_RISE);
write_xml_delay_measurement(fp, fname, sim_setting, SIM_SIGNAL_FALL);
fp << "\t\t" << "</delay>" << "\n";
fp << "\t" << "</measurement_setting>" << "\n";
}
/********************************************************************
* A writer to output a stimulus setting in a simulation setting to XML format
*******************************************************************/
static
void write_xml_stimulus(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
fp << "\t" << "<stimulus>" << "\n";
fp << "\t\t" << "<clock>" << "\n";
fp << "\t\t\t" << "<rise";
write_xml_attribute(fp, "slew_type", SIM_ACCURACY_TYPE_STRING[sim_setting.stimuli_clock_slew_type(SIM_SIGNAL_RISE)]);
write_xml_attribute(fp, "slew_time", sim_setting.stimuli_clock_slew(SIM_SIGNAL_RISE));
fp << "/>" << "\n";
fp << "\t\t\t" << "<fall";
write_xml_attribute(fp, "slew_type", SIM_ACCURACY_TYPE_STRING[sim_setting.stimuli_clock_slew_type(SIM_SIGNAL_FALL)]);
write_xml_attribute(fp, "slew_time", sim_setting.stimuli_clock_slew(SIM_SIGNAL_FALL));
fp << "/>" << "\n";
fp << "\t\t" << "</clock>" << "\n";
fp << "\t\t" << "<input>" << "\n";
fp << "\t\t\t" << "<rise";
write_xml_attribute(fp, "slew_type", SIM_ACCURACY_TYPE_STRING[sim_setting.stimuli_input_slew_type(SIM_SIGNAL_RISE)]);
write_xml_attribute(fp, "slew_time", sim_setting.stimuli_input_slew(SIM_SIGNAL_RISE));
fp << "/>" << "\n";
fp << "\t\t\t" << "<fall";
write_xml_attribute(fp, "slew_type", SIM_ACCURACY_TYPE_STRING[sim_setting.stimuli_input_slew_type(SIM_SIGNAL_FALL)]);
write_xml_attribute(fp, "slew_time", sim_setting.stimuli_input_slew(SIM_SIGNAL_FALL));
fp << "/>" << "\n";
fp << "\t\t" << "</input>" << "\n";
fp << "\t" << "</stimulus>" << "\n";
}
/********************************************************************
* A writer to output a simulation setting to XML format
*******************************************************************/
void write_xml_simulation_setting(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting) {
/* Validate the file stream */
openfpga::check_file_stream(fname, fp);
/* Write the root node <openfpga_simulation_setting>
*/
fp << "<openfpga_simulation_setting>" << "\n";
/* Write clock settings */
write_xml_clock_setting(fp, fname, sim_setting);
/* Write simulator option */
write_xml_simulator_option(fp, fname, sim_setting);
/* Write monte carlo simulation setting */
write_xml_monte_carlo(fp, fname, sim_setting);
/* Write measurement setting */
write_xml_measurement(fp, fname, sim_setting);
/* Write stimuli setting */
write_xml_stimulus(fp, fname, sim_setting);
/* Write the root node <openfpga_simulation_setting> */
fp << "</openfpga_simulation_setting>" << "\n";
}

View File

@ -0,0 +1,17 @@
#ifndef WRITE_XML_SIMULATION_SETTING_H
#define WRITE_XML_SIMULATION_SETTING_H
/********************************************************************
* Include header files that are required by function declaration
*******************************************************************/
#include <fstream>
#include "simulation_setting.h"
/********************************************************************
* Function declaration
*******************************************************************/
void write_xml_simulation_setting(std::fstream& fp,
const char* fname,
const SimulationSetting& sim_setting);
#endif