From 88a96673e34697ffb288ca51dbced17cf4d18b21 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 17 Jan 2020 16:44:57 -0700 Subject: [PATCH 1/6] rename some methods in technology library and start building associated XML parser --- .../libarchopenfpga/arch/sample_arch.xml | 46 +- .../libarchopenfpga/src/openfpga_arch.h | 2 + .../src/read_xml_openfpga_arch.cpp | 9 +- .../src/technology_library.cpp | 484 +++++++++--------- .../libarchopenfpga/src/technology_library.h | 193 ++++--- .../src/technology_library_fwd.h | 4 +- 6 files changed, 368 insertions(+), 370 deletions(-) diff --git a/libopenfpga/libarchopenfpga/arch/sample_arch.xml b/libopenfpga/libarchopenfpga/arch/sample_arch.xml index 09a4833d2..100be50eb 100644 --- a/libopenfpga/libarchopenfpga/arch/sample_arch.xml +++ b/libopenfpga/libarchopenfpga/arch/sample_arch.xml @@ -9,32 +9,34 @@ --> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/libopenfpga/libarchopenfpga/src/openfpga_arch.h b/libopenfpga/libarchopenfpga/src/openfpga_arch.h index f33260218..c5320e051 100644 --- a/libopenfpga/libarchopenfpga/src/openfpga_arch.h +++ b/libopenfpga/libarchopenfpga/src/openfpga_arch.h @@ -2,6 +2,7 @@ #define OPENFPGA_ARCH_H #include "circuit_library.h" +#include "technology_library.h" /* namespace openfpga begins */ namespace openfpga { @@ -11,6 +12,7 @@ namespace openfpga { */ struct Arch { CircuitLibrary circuit_lib; + TechnologyLibrary tech_lib; }; } /* namespace openfpga ends */ diff --git a/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp b/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp index e596f11c5..af66f78ad 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp @@ -13,6 +13,7 @@ #include "arch_error.h" #include "read_xml_util.h" +#include "read_xml_technology_library.h" #include "read_xml_circuit_library.h" #include "read_xml_openfpga_arch.h" @@ -33,12 +34,12 @@ openfpga::Arch read_xml_openfpga_arch(const char* arch_file_name) { loc_data = pugiutil::load_xml(doc, arch_file_name); /* First node should be */ - auto xml_circuit_settings = get_single_child(doc, "openfpga_architecture", loc_data); + auto xml_openfpga_arch = get_single_child(doc, "openfpga_architecture", loc_data); /* Parse circuit_models to circuit library * under the node */ - auto xml_circuit_models = get_single_child(xml_circuit_settings, "circuit_library", loc_data); + auto xml_circuit_models = get_single_child(xml_openfpga_arch, "circuit_library", loc_data); openfpga_arch.circuit_lib = read_xml_circuit_library(xml_circuit_models, loc_data); /* Build the internal links for the circuit library */ @@ -47,6 +48,10 @@ openfpga::Arch read_xml_openfpga_arch(const char* arch_file_name) { /* Build the timing graph inside the circuit library */ openfpga_arch.circuit_lib.build_timing_graphs(); + /* Parse technology library */ + auto xml_tech_lib = get_single_child(xml_openfpga_arch, "technology_library", loc_data); + openfpga_arch.tech_lib = read_xml_technology_library(xml_tech_lib, loc_data); + /* Second node should be */ auto xml_simulation_settings = get_single_child(doc, "openfpga_simulation_setting", loc_data); diff --git a/libopenfpga/libarchopenfpga/src/technology_library.cpp b/libopenfpga/libarchopenfpga/src/technology_library.cpp index 519fa0897..db71b50c5 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/technology_library.cpp @@ -16,20 +16,20 @@ TechnologyLibrary::TechnologyLibrary() { /************************************************************************ * Public Accessors : aggregates ***********************************************************************/ -TechnologyLibrary::technology_device_range TechnologyLibrary::devices() const { - return vtr::make_range(device_ids_.begin(), device_ids_.end()); +TechnologyLibrary::technology_model_range TechnologyLibrary::models() const { + return vtr::make_range(model_ids_.begin(), model_ids_.end()); } TechnologyLibrary::technology_variation_range TechnologyLibrary::variations() const { return vtr::make_range(variation_ids_.begin(), variation_ids_.end()); } -/* Find technology devices in the same type (defined by users) and return a list of ids */ -std::vector TechnologyLibrary::devices_by_type(const enum e_tech_lib_device_type& type) const { - std::vector type_ids; - for (auto id : devices()) { +/* Find technology models in the same type (defined by users) and return a list of ids */ +std::vector TechnologyLibrary::models_by_type(const enum e_tech_lib_model_type& type) const { + std::vector type_ids; + for (auto id : models()) { /* Skip unmatched types */ - if (type != device_type(id)) { + if (type != model_type(id)) { continue; } /* Matched type, update the vector */ @@ -39,170 +39,170 @@ std::vector TechnologyLibrary::devices_by_type(const enum e_ } /************************************************************************ - * Public Accessors : Basic data query on technology devices + * Public Accessors : Basic data query on technology models ***********************************************************************/ -/* Access the name of a technology device */ -std::string TechnologyLibrary::device_name(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - return device_names_[device_id]; +/* Access the name of a technology model */ +std::string TechnologyLibrary::model_name(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + return model_names_[model_id]; } -/* Access the id of a technology device by name, +/* Access the id of a technology model by name, * If the name is valid, we return a valid id * Otherwise, return an invalid id */ -TechnologyDeviceId TechnologyLibrary::device(const std::string& name) const { - std::map::const_iterator it = device_name2ids_.find(name); - if (it != device_name2ids_.end()) { - return TechnologyDeviceId::INVALID(); +TechnologyModelId TechnologyLibrary::model(const std::string& name) const { + std::map::const_iterator it = model_name2ids_.find(name); + if (it != model_name2ids_.end()) { + return TechnologyModelId::INVALID(); } - return device_name2ids_.at(name); + return model_name2ids_.at(name); } -/* Access the type of a technology device */ -enum e_tech_lib_device_type TechnologyLibrary::device_type(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - return device_types_[device_id]; +/* Access the type of a technology model */ +enum e_tech_lib_model_type TechnologyLibrary::model_type(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + return model_types_[model_id]; } -/* Access the model type of a technology device */ -enum e_tech_lib_model_type TechnologyLibrary::device_model_type(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - return device_model_types_[device_id]; +/* Access the model type of a technology model */ +enum e_tech_lib_type TechnologyLibrary::model_lib_type(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + return model_lib_types_[model_id]; } -/* Access the process corner name of a technology device */ -std::string TechnologyLibrary::device_corner(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - return device_corners_[device_id]; +/* Access the process corner name of a technology model */ +std::string TechnologyLibrary::model_corner(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + return model_corners_[model_id]; } -/* Access the model reference name of a technology device */ -std::string TechnologyLibrary::device_model_ref(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - return device_model_refs_[device_id]; +/* Access the model reference name of a technology model */ +std::string TechnologyLibrary::model_ref(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + return model_refs_[model_id]; } -/* Access the path of library for a technology device */ -std::string TechnologyLibrary::device_lib_path(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - return device_lib_paths_[device_id]; +/* Access the path of library for a technology model */ +std::string TechnologyLibrary::model_lib_path(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + return model_lib_paths_[model_id]; } -/* Access the VDD of a technology device - * Note: This is ONLY applicable to transistor device +/* Access the VDD of a technology model + * Note: This is ONLY applicable to transistor model */ -float TechnologyLibrary::device_vdd(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - return device_vdds_[device_id]; +float TechnologyLibrary::model_vdd(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + return model_vdds_[model_id]; } -/* Access the width ratio between PMOS and NMOS for a technology device - * Note: This is ONLY applicable to transistor device +/* Access the width ratio between PMOS and NMOS for a technology model + * Note: This is ONLY applicable to transistor model */ -float TechnologyLibrary::device_pn_ratio(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - return device_pn_ratios_[device_id]; +float TechnologyLibrary::model_pn_ratio(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + return model_pn_ratios_[model_id]; } /************************************************************************ * Public Accessors : Basic data query on transistors ***********************************************************************/ -/* Access the model name of a transistor (either PMOS or NMOS) for a technology device - * Note: This is ONLY applicable to transistor device +/* Access the model name of a transistor (either PMOS or NMOS) for a technology model + * Note: This is ONLY applicable to transistor model */ -std::string TechnologyLibrary::transistor_model_name(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - return transistor_model_names_[device_id][transistor_type]; +std::string TechnologyLibrary::transistor_model_name(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + return transistor_model_names_[model_id][transistor_type]; } -/* Access the channel length of a transistor (either PMOS or NMOS) for a technology device - * Note: This is ONLY applicable to transistor device +/* Access the channel length of a transistor (either PMOS or NMOS) for a technology model + * Note: This is ONLY applicable to transistor model */ -float TechnologyLibrary::transistor_model_chan_length(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - return transistor_model_chan_lengths_[device_id][transistor_type]; +float TechnologyLibrary::transistor_model_chan_length(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + return transistor_model_chan_lengths_[model_id][transistor_type]; } -/* Access the minimum width of a transistor (either PMOS or NMOS) for a technology device - * Note: This is ONLY applicable to transistor device +/* Access the minimum width of a transistor (either PMOS or NMOS) for a technology model + * Note: This is ONLY applicable to transistor model */ -float TechnologyLibrary::transistor_model_min_width(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - return transistor_model_min_widths_[device_id][transistor_type]; +float TechnologyLibrary::transistor_model_min_width(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + return transistor_model_min_widths_[model_id][transistor_type]; } -/* Access the minimum width of a transistor (either PMOS or NMOS) for a technology device - * Note: This is ONLY applicable to transistor device +/* Access the minimum width of a transistor (either PMOS or NMOS) for a technology model + * Note: This is ONLY applicable to transistor model */ -TechnologyVariationId TechnologyLibrary::transistor_model_variation(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - return transistor_model_variation_ids_[device_id][transistor_type]; +TechnologyVariationId TechnologyLibrary::transistor_model_variation(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + return transistor_model_variation_ids_[model_id][transistor_type]; } /************************************************************************ - * Public Accessors : Basic data query on RRAM devices + * Public Accessors : Basic data query on RRAM models ***********************************************************************/ -/* Access the Low Resistence of a RRAM for a technology device - * Note: This is ONLY applicable to RRAM device +/* Access the Low Resistence of a RRAM for a technology model + * Note: This is ONLY applicable to RRAM model */ -float TechnologyLibrary::rram_rlrs(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device_id)); - return rram_resistances_[device_id].x(); +float TechnologyLibrary::rram_rlrs(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model_id)); + return rram_resistances_[model_id].x(); } -/* Access the High Resistence of a RRAM for a technology device - * Note: This is ONLY applicable to RRAM device +/* Access the High Resistence of a RRAM for a technology model + * Note: This is ONLY applicable to RRAM model */ -float TechnologyLibrary::rram_rhrs(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to transistor device */ - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device_id)); - return rram_resistances_[device_id].y(); +float TechnologyLibrary::rram_rhrs(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to transistor model */ + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model_id)); + return rram_resistances_[model_id].y(); } -/* Access the Variation id of a RRAM for a technology device - * Note: This is ONLY applicable to RRAM device +/* Access the Variation id of a RRAM for a technology model + * Note: This is ONLY applicable to RRAM model */ -TechnologyVariationId TechnologyLibrary::rram_variation(const TechnologyDeviceId& device_id) const { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - /* This is only applicable to RRAM device */ - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device_id)); - return rram_variation_ids_[device_id]; +TechnologyVariationId TechnologyLibrary::rram_variation(const TechnologyModelId& model_id) const { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + /* This is only applicable to RRAM model */ + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model_id)); + return rram_variation_ids_[model_id]; } /************************************************************************ @@ -243,29 +243,29 @@ size_t TechnologyLibrary::variation_num_sigma(const TechnologyVariationId& varia } /************************************************************************ - * Public Mutators: device-related + * Public Mutators: model-related ***********************************************************************/ -/* Add a new device to the library, return an id +/* Add a new model to the library, return an id * This function will check if the name has already been used inside the data structure. * If used, it will return an invalid id */ -TechnologyDeviceId TechnologyLibrary::add_device(const std::string& name) { - std::map::iterator it = device_name2ids_.find(name); - if (it != device_name2ids_.end()) { - return TechnologyDeviceId::INVALID(); +TechnologyModelId TechnologyLibrary::add_model(const std::string& name) { + std::map::iterator it = model_name2ids_.find(name); + if (it != model_name2ids_.end()) { + return TechnologyModelId::INVALID(); } /* This is a legal name. we can create a new id */ - TechnologyDeviceId device = TechnologyDeviceId(device_ids_.size()); - device_ids_.push_back(device); - device_names_.push_back(name); - device_types_.emplace_back(NUM_TECH_LIB_DEVICE_TYPES); - device_model_types_.emplace_back(NUM_TECH_LIB_MODEL_TYPES); - device_corners_.emplace_back(); - device_model_refs_.emplace_back(); - device_lib_paths_.emplace_back(); - device_vdds_.push_back(-1); - device_pn_ratios_.push_back(-1); + TechnologyModelId model = TechnologyModelId(model_ids_.size()); + model_ids_.push_back(model); + model_names_.push_back(name); + model_types_.emplace_back(NUM_TECH_LIB_MODEL_TYPES); + model_lib_types_.emplace_back(NUM_TECH_LIB_TYPES); + model_corners_.emplace_back(); + model_refs_.emplace_back(); + model_lib_paths_.emplace_back(); + model_vdds_.push_back(-1); + model_pn_ratios_.push_back(-1); transistor_model_names_.emplace_back(); transistor_model_chan_lengths_.emplace_back(); @@ -278,171 +278,171 @@ TechnologyDeviceId TechnologyLibrary::add_device(const std::string& name) { rram_variation_ids_.emplace_back(); /* Register in the name-to-id map */ - device_name2ids_[name] = device; + model_name2ids_[name] = model; - return device; + return model; } -/* Set the device type of a device in the library */ -void TechnologyLibrary::set_device_type(const TechnologyDeviceId& device_id, - const e_tech_lib_device_type& type) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - device_types_[device_id] = type; +/* Set the model type of a model in the library */ +void TechnologyLibrary::set_model_type(const TechnologyModelId& model_id, + const e_tech_lib_model_type& type) { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + model_types_[model_id] = type; return; } -/* Set the model type of a device in the library */ -void TechnologyLibrary::set_device_model_type(const TechnologyDeviceId& device_id, - const e_tech_lib_model_type& model_type) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - device_model_types_[device_id] = model_type; +/* Set the model type of a device model in the library */ +void TechnologyLibrary::set_model_lib_type(const TechnologyModelId& model_id, + const e_tech_lib_type& model_lib_type) { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + model_lib_types_[model_id] = model_lib_type; return; } -/* Set the process corner of a device in the library */ -void TechnologyLibrary::set_device_corner(const TechnologyDeviceId& device_id, +/* Set the process corner of a model in the library */ +void TechnologyLibrary::set_model_corner(const TechnologyModelId& model_id, const std::string& corner) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - device_corners_[device_id] = corner; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + model_corners_[model_id] = corner; return; } -/* Set the string used to model reference of a device in the library */ -void TechnologyLibrary::set_device_model_ref(const TechnologyDeviceId& device_id, - const std::string& model_ref) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - device_model_refs_[device_id] = model_ref; +/* Set the string used to model reference of a model in the library */ +void TechnologyLibrary::set_model_ref(const TechnologyModelId& model_id, + const std::string& model_ref) { + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + model_refs_[model_id] = model_ref; return; } -/* Set the library file path of a device in the library */ -void TechnologyLibrary::set_device_lib_path(const TechnologyDeviceId& device_id, +/* Set the library file path of a model in the library */ +void TechnologyLibrary::set_model_lib_path(const TechnologyModelId& model_id, const std::string& lib_path) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - device_lib_paths_[device_id] = lib_path; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + model_lib_paths_[model_id] = lib_path; return; } -/* Set the operating voltage of a device in the library +/* Set the operating voltage of a model in the library * This is ONLY applicable to transistors */ -void TechnologyLibrary::set_device_vdd(const TechnologyDeviceId& device_id, +void TechnologyLibrary::set_model_vdd(const TechnologyModelId& model_id, const float& vdd) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - device_vdds_[device_id] = vdd; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + model_vdds_[model_id] = vdd; return; } -/* Set the width ratio between PMOS and NMOS of a device in the library +/* Set the width ratio between PMOS and NMOS of a model in the library * This is ONLY applicable to transistors */ -void TechnologyLibrary::set_device_pn_ratio(const TechnologyDeviceId& device_id, +void TechnologyLibrary::set_model_pn_ratio(const TechnologyModelId& model_id, const float& pn_ratio) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - device_pn_ratios_[device_id] = pn_ratio; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + model_pn_ratios_[model_id] = pn_ratio; return; } /************************************************************************ * Public Mutators: transistor-related ***********************************************************************/ -/* Set the model name for either PMOS or NMOS of a device in the library +/* Set the model name for either PMOS or NMOS of a model in the library * This is ONLY applicable to transistors */ -void TechnologyLibrary::set_transistor_model_name(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, +void TechnologyLibrary::set_transistor_model_name(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const std::string& model_name) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - transistor_model_names_[device_id][transistor_type] = model_name; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + transistor_model_names_[model_id][transistor_type] = model_name; return; } -/* Set the channel length for either PMOS or NMOS of a device in the library +/* Set the channel length for either PMOS or NMOS of a model in the library * This is ONLY applicable to transistors */ -void TechnologyLibrary::set_transistor_model_chan_length(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, +void TechnologyLibrary::set_transistor_model_chan_length(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const float& chan_length) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - transistor_model_chan_lengths_[device_id][transistor_type] = chan_length; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + transistor_model_chan_lengths_[model_id][transistor_type] = chan_length; return; } -/* Set the minimum width for either PMOS or NMOS of a device in the library +/* Set the minimum width for either PMOS or NMOS of a model in the library * This is ONLY applicable to transistors */ -void TechnologyLibrary::set_transistor_model_min_width(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, +void TechnologyLibrary::set_transistor_model_min_width(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const float& min_width) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - transistor_model_min_widths_[device_id][transistor_type] = min_width; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + transistor_model_min_widths_[model_id][transistor_type] = min_width; return; } -/* Set the variation name for either PMOS or NMOS of a device in the library +/* Set the variation name for either PMOS or NMOS of a model in the library * This is ONLY applicable to transistors */ -void TechnologyLibrary::set_transistor_model_variation_name(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, +void TechnologyLibrary::set_transistor_model_variation_name(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const std::string& variation_name) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_TRANSISTOR == device_type(device_id)); - transistor_model_variation_names_[device_id][transistor_type] = variation_name; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_TRANSISTOR == model_type(model_id)); + transistor_model_variation_names_[model_id][transistor_type] = variation_name; return; } /************************************************************************ * Public Mutators: RRAM-related ***********************************************************************/ -/* Set the Low Resistance State (LRS) resistance for a RRAM device in the library - * This is ONLY applicable to RRAM devices +/* Set the Low Resistance State (LRS) resistance for a RRAM model in the library + * This is ONLY applicable to RRAM models */ -void TechnologyLibrary::set_rram_rlrs(const TechnologyDeviceId& device_id, +void TechnologyLibrary::set_rram_rlrs(const TechnologyModelId& model_id, const float& rlrs) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device_id)); - rram_resistances_[device_id].set_x(rlrs); + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model_id)); + rram_resistances_[model_id].set_x(rlrs); return; } -/* Set the High Resistance State (HRS) resistance for a RRAM device in the library - * This is ONLY applicable to RRAM devices +/* Set the High Resistance State (HRS) resistance for a RRAM model in the library + * This is ONLY applicable to RRAM models */ -void TechnologyLibrary::set_rram_rhrs(const TechnologyDeviceId& device_id, +void TechnologyLibrary::set_rram_rhrs(const TechnologyModelId& model_id, const float& rhrs) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device_id)); - rram_resistances_[device_id].set_y(rhrs); + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model_id)); + rram_resistances_[model_id].set_y(rhrs); return; } -/* Set the variation name for a RRAM device in the library - * This is ONLY applicable to RRAM devices +/* Set the variation name for a RRAM model in the library + * This is ONLY applicable to RRAM models */ -void TechnologyLibrary::set_rram_variation_name(const TechnologyDeviceId& device_id, +void TechnologyLibrary::set_rram_variation_name(const TechnologyModelId& model_id, const std::string& variation_name) { - /* validate the device_id */ - VTR_ASSERT(valid_device_id(device_id)); - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device_id)); - rram_variation_names_[device_id] = variation_name; + /* validate the model_id */ + VTR_ASSERT(valid_model_id(model_id)); + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model_id)); + rram_variation_names_[model_id] = variation_name; return; } @@ -490,31 +490,31 @@ void TechnologyLibrary::set_variation_num_sigma(const TechnologyVariationId& var /************************************************************************ * Public mutators: linkers ***********************************************************************/ -/* This function builds the links between devices and variations, +/* This function builds the links between models and variations, * which have been defined in the technology library */ -void TechnologyLibrary::link_devices_to_variations() { - for (const TechnologyDeviceId& device : devices()) { +void TechnologyLibrary::link_models_to_variations() { + for (const TechnologyModelId& model : models()) { /* For transistors, find the variation name for each model and build a link */ - if (TECH_LIB_DEVICE_TRANSISTOR == device_type(device)) { + if (TECH_LIB_MODEL_TRANSISTOR == model_type(model)) { /* PMOS transistor, if a variation name is specified, we try to build a link * Otherwise, we assign any invalid id */ - const std::string& pmos_var_name = transistor_model_variation_names_[device][TECH_LIB_TRANSISTOR_PMOS]; - transistor_model_variation_ids_[device][TECH_LIB_TRANSISTOR_PMOS] = variation(pmos_var_name); + const std::string& pmos_var_name = transistor_model_variation_names_[model][TECH_LIB_TRANSISTOR_PMOS]; + transistor_model_variation_ids_[model][TECH_LIB_TRANSISTOR_PMOS] = variation(pmos_var_name); /* NMOS transistor, if a variation name is specified, we try to build a link * Otherwise, we assign any invalid id */ - const std::string& nmos_var_name = transistor_model_variation_names_[device][TECH_LIB_TRANSISTOR_NMOS]; - transistor_model_variation_ids_[device][TECH_LIB_TRANSISTOR_NMOS] = variation(nmos_var_name); + const std::string& nmos_var_name = transistor_model_variation_names_[model][TECH_LIB_TRANSISTOR_NMOS]; + transistor_model_variation_ids_[model][TECH_LIB_TRANSISTOR_NMOS] = variation(nmos_var_name); /* Finish for transistors, go to the next */ continue; } - /* Reach here it means an RRAM device, we find the variation name and try to build a link */ - VTR_ASSERT(TECH_LIB_DEVICE_RRAM == device_type(device)); - const std::string& rram_var_name = rram_variation_names_[device]; - rram_variation_ids_[device] = variation(rram_var_name); + /* Reach here it means an RRAM model, we find the variation name and try to build a link */ + VTR_ASSERT(TECH_LIB_MODEL_RRAM == model_type(model)); + const std::string& rram_var_name = rram_variation_names_[model]; + rram_variation_ids_[model] = variation(rram_var_name); /* Finish for RRAMs, go to the next */ } } @@ -523,8 +523,8 @@ void TechnologyLibrary::link_devices_to_variations() { * Internal invalidators/validators ***********************************************************************/ /* Validators */ -bool TechnologyLibrary::valid_device_id(const TechnologyDeviceId& device_id) const { - return ( size_t(device_id) < device_ids_.size() ) && ( device_id == device_ids_[device_id] ); +bool TechnologyLibrary::valid_model_id(const TechnologyModelId& model_id) const { + return ( size_t(model_id) < model_ids_.size() ) && ( model_id == model_ids_[model_id] ); } bool TechnologyLibrary::valid_variation_id(const TechnologyVariationId& variation_id) const { diff --git a/libopenfpga/libarchopenfpga/src/technology_library.h b/libopenfpga/libarchopenfpga/src/technology_library.h index cc1030198..3bf51c2e8 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.h +++ b/libopenfpga/libarchopenfpga/src/technology_library.h @@ -25,33 +25,33 @@ * PTM is the Predictive Technology Model provided by the Arizona * State University (ASU). Available at ptm.asu.edu *******************************************************************/ -enum e_tech_lib_model_type { +enum e_tech_lib_type { TECH_LIB_MODEL_INDUSTRY, TECH_LIB_MODEL_ACADEMIA, - NUM_TECH_LIB_MODEL_TYPES + NUM_TECH_LIB_TYPES }; /* Strings correspond to each technology library type */ -constexpr std::array TECH_LIB_MODEL_TYPE_STRING = {{"industry", "academia"}}; +constexpr std::array TECH_LIB_TYPE_STRING = {{"industry", "academia"}}; /******************************************************************** - * Types of device which may be defined in a technology library + * Types of model which may be defined in a technology library * 1. transistor * 2. RRAM *******************************************************************/ -enum e_tech_lib_device_type { - TECH_LIB_DEVICE_TRANSISTOR, - TECH_LIB_DEVICE_RRAM, - NUM_TECH_LIB_DEVICE_TYPES +enum e_tech_lib_model_type { + TECH_LIB_MODEL_TRANSISTOR, + TECH_LIB_MODEL_RRAM, + NUM_TECH_LIB_MODEL_TYPES }; /* Strings correspond to transistor type */ -constexpr std::array TECH_LIB_DEVICE_TYPE_STRING = {{"transistor", "rram"}}; +constexpr std::array TECH_LIB_MODEL_TYPE_STRING = {{"transistor", "rram"}}; /******************************************************************** * Types of transistors which may be defined in a technology library * 1. NMOS transistor * 2. PMOS transistor *******************************************************************/ -enum e_tech_lib_trans_type { +enum e_tech_lib_transistor_type { TECH_LIB_TRANSISTOR_PMOS, TECH_LIB_TRANSISTOR_NMOS, NUM_TECH_LIB_TRANSISTOR_TYPES @@ -59,18 +59,6 @@ enum e_tech_lib_trans_type { /* Strings correspond to transistor type */ constexpr std::array TECH_LIB_TRANSISTOR_TYPE_STRING = {{"pmos", "nmos"}}; -/******************************************************************** - * Process corners supported - *******************************************************************/ -enum e_process_corner { - TECH_LIB_CORNER_FF, - TECH_LIB_CORNER_TT, - TECH_LIB_CORNER_SS, - NUM_TECH_LIB_CORNER_TYPES -}; -/* Strings correspond to process corner type */ -constexpr std::array TECH_LIB_CORNER_TYPE_STRING = {{"FF", "TT", "SS"}}; - /******************************************************************** * A data structure to describe technology library * @@ -80,146 +68,146 @@ constexpr std::array TECH_LIB_CORNER_TYP * TechnologyLibrary tech_lib; * // call your builder for technology library * // Build the internal links for the technology library - * tech_lib.link_device_to_variation(); + * tech_lib.link_model_to_variation(); * *******************************************************************/ class TechnologyLibrary { public: /* Types */ - typedef vtr::vector::const_iterator technology_device_iterator; + typedef vtr::vector::const_iterator technology_model_iterator; typedef vtr::vector::const_iterator technology_variation_iterator; /* Create range */ - typedef vtr::Range technology_device_range; + typedef vtr::Range technology_model_range; typedef vtr::Range technology_variation_range; public: /* Constructors */ TechnologyLibrary(); public: /* Accessors: aggregates */ - technology_device_range devices() const; + technology_model_range models() const; technology_variation_range variations() const; - std::vector devices_by_type(const enum e_tech_lib_device_type& type) const; - public: /* Public Accessors: Basic data query on devices */ - std::string device_name(const TechnologyDeviceId& device_id) const; - TechnologyDeviceId device(const std::string& name) const; - enum e_tech_lib_device_type device_type(const TechnologyDeviceId& device_id) const; - enum e_tech_lib_model_type device_model_type(const TechnologyDeviceId& device_id) const; - std::string device_corner(const TechnologyDeviceId& device_id) const; - std::string device_model_ref(const TechnologyDeviceId& device_id) const; - std::string device_lib_path(const TechnologyDeviceId& device_id) const; - float device_vdd(const TechnologyDeviceId& device_id) const; - float device_pn_ratio(const TechnologyDeviceId& device_id) const; + std::vector models_by_type(const enum e_tech_lib_model_type& type) const; + public: /* Public Accessors: Basic data query on models */ + std::string model_name(const TechnologyModelId& model_id) const; + TechnologyModelId model(const std::string& name) const; + enum e_tech_lib_model_type model_type(const TechnologyModelId& model_id) const; + enum e_tech_lib_type model_lib_type(const TechnologyModelId& model_id) const; + std::string model_corner(const TechnologyModelId& model_id) const; + std::string model_ref(const TechnologyModelId& model_id) const; + std::string model_lib_path(const TechnologyModelId& model_id) const; + float model_vdd(const TechnologyModelId& model_id) const; + float model_pn_ratio(const TechnologyModelId& model_id) const; public: /* Public Accessors: Basic data query on transistors */ - std::string transistor_model_name(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const; - float transistor_model_chan_length(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const; - float transistor_model_min_width(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const; - TechnologyVariationId transistor_model_variation(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type) const; - public: /* Public Accessors: Basic data query on RRAM devices */ - float rram_rlrs(const TechnologyDeviceId& device_id) const; - float rram_rhrs(const TechnologyDeviceId& device_id) const; - TechnologyVariationId rram_variation(const TechnologyDeviceId& device_id) const; + std::string transistor_model_name(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const; + float transistor_model_chan_length(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const; + float transistor_model_min_width(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const; + TechnologyVariationId transistor_model_variation(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type) const; + public: /* Public Accessors: Basic data query on RRAM models */ + float rram_rlrs(const TechnologyModelId& model_id) const; + float rram_rhrs(const TechnologyModelId& model_id) const; + TechnologyVariationId rram_variation(const TechnologyModelId& model_id) const; public: /* Public Accessors: Basic data query on variations */ std::string variation_name(const TechnologyVariationId& variation_id) const; TechnologyVariationId variation(const std::string& name) const; float variation_abs_value(const TechnologyVariationId& variation_id) const; size_t variation_num_sigma(const TechnologyVariationId& variation_id) const; - public: /* Public Mutators: device-related */ - TechnologyDeviceId add_device(const std::string& name); - void set_device_type(const TechnologyDeviceId& device_id, - const e_tech_lib_device_type& type); - void set_device_model_type(const TechnologyDeviceId& device_id, - const e_tech_lib_model_type& model_type); - void set_device_corner(const TechnologyDeviceId& device_id, + public: /* Public Mutators: model-related */ + TechnologyModelId add_model(const std::string& name); + void set_model_type(const TechnologyModelId& model_id, + const e_tech_lib_model_type& type); + void set_model_lib_type(const TechnologyModelId& model_id, + const e_tech_lib_type& lib_type); + void set_model_corner(const TechnologyModelId& model_id, const std::string& corner); - void set_device_model_ref(const TechnologyDeviceId& device_id, + void set_model_ref(const TechnologyModelId& model_id, const std::string& model_ref); - void set_device_lib_path(const TechnologyDeviceId& device_id, + void set_model_lib_path(const TechnologyModelId& model_id, const std::string& lib_path); - void set_device_vdd(const TechnologyDeviceId& device_id, + void set_model_vdd(const TechnologyModelId& model_id, const float& vdd); - void set_device_pn_ratio(const TechnologyDeviceId& device_id, + void set_model_pn_ratio(const TechnologyModelId& model_id, const float& pn_ratio); public: /* Public Mutators: transistor-related */ - void set_transistor_model_name(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, + void set_transistor_model_name(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const std::string& model_name); - void set_transistor_model_chan_length(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, + void set_transistor_model_chan_length(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const float& chan_length); - void set_transistor_model_min_width(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, + void set_transistor_model_min_width(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const float& min_width); - void set_transistor_model_variation_name(const TechnologyDeviceId& device_id, - const e_tech_lib_trans_type& transistor_type, + void set_transistor_model_variation_name(const TechnologyModelId& model_id, + const e_tech_lib_transistor_type& transistor_type, const std::string& variation_name); public: /* Public Mutators: RRAM-related */ - void set_rram_rlrs(const TechnologyDeviceId& device_id, + void set_rram_rlrs(const TechnologyModelId& model_id, const float& rlrs); - void set_rram_rhrs(const TechnologyDeviceId& device_id, + void set_rram_rhrs(const TechnologyModelId& model_id, const float& rhrs); - void set_rram_variation_name(const TechnologyDeviceId& device_id, + void set_rram_variation_name(const TechnologyModelId& model_id, const std::string& variation_name); public: /* Public Mutators: variation-related */ TechnologyVariationId add_variation(const std::string& name); void set_variation_abs_value(const TechnologyVariationId& variation_id, const float& abs_value); void set_variation_num_sigma(const TechnologyVariationId& variation_id, const size_t& num_sigma); public: /* Public Mutators: linkers */ - void link_devices_to_variations(); + void link_models_to_variations(); public: /* Public invalidators/validators */ - bool valid_device_id(const TechnologyDeviceId& device_id) const; + bool valid_model_id(const TechnologyModelId& model_id) const; bool valid_variation_id(const TechnologyVariationId& variation_id) const; private: /* Internal data */ /* Transistor-related fundamental information */ - /* Unique identifier for each device - * A device could be either transistors (1 pair of PMOS and NMOS) or RRAMs + /* Unique identifier for each model + * A model could be either transistors (1 pair of PMOS and NMOS) or RRAMs */ - vtr::vector device_ids_; + vtr::vector model_ids_; - /* Unique name for each device. This is defined by XML file */ - vtr::vector device_names_; + /* Unique name for each model. This is defined by XML file */ + vtr::vector model_names_; - /* Type of each device, either transistors or RRAMs */ - vtr::vector device_types_; + /* Type of each model, either transistors or RRAMs */ + vtr::vector model_types_; - /* Type of models of each device, either industry or academia + /* Type of models of each model, either industry or academia * This will lead to different ways when include these models * For industry models, we use .lib to include library * For academia models, we use .include to include library */ - vtr::vector device_model_types_; + vtr::vector model_lib_types_; - /* Name of process corner to be used for each device + /* Name of process corner to be used for each model * Users can define any string for the process corner they are going to use * But the corner name should be consistent with their library files * When this is enabled, the corner name will be added when * include the models * For example, for a industry model, .lib */ - vtr::vector device_corners_; + vtr::vector model_corners_; - /* The string used to instanciate the device models + /* The string used to instanciate the model models * This will really depend on the type of models * For most industry models, we can use 'M' to instanciate a transisitor * For some academia models, we have to use 'X' to do so */ - vtr::vector device_model_refs_; + vtr::vector model_refs_; /* The path to the transistor models * This is going to be the when include the library files * See the example in the comments about process corner */ - vtr::vector device_lib_paths_; + vtr::vector model_lib_paths_; - /* Operating voltage for the devices. Unit: [V] */ - vtr::vector device_vdds_; + /* Operating voltage for the models. Unit: [V] */ + vtr::vector model_vdds_; - /* The width ratio between PMOS and NMOS for a device group + /* The width ratio between PMOS and NMOS for a model group * This really depend the transistor technology * We recommend users to characterize driving strengths of * PMOS and NMOS using SPICE simulators */ - vtr::vector device_pn_ratios_; + vtr::vector model_pn_ratios_; /* The model name is the name that is defined in your library file. * For example, your NMOS transistor may be defined as @@ -230,38 +218,39 @@ class TechnologyLibrary { * PMOS data will be stored in the first element of the array * NMOS data will be stored in the second element of the array */ - vtr::vector> transistor_model_names_; + vtr::vector> transistor_model_names_; /* The channel length of a transistor. * This should be defined by your technology vendor * For example, a 22nm technology, the channel length is around 22nm */ - vtr::vector> transistor_model_chan_lengths_; + vtr::vector> transistor_model_chan_lengths_; /* The minimum width of a transistor. * This should be defined by your technology vendor */ - vtr::vector> transistor_model_min_widths_; + vtr::vector> transistor_model_min_widths_; /* The variation name and id binded to PMOS and NMOS transistor * We expect users to provide the exact name of variation defined in this technology library - * the name and id will be automatically matched by using function link_device_to_variation() + * the name and id will be automatically matched by using function link_model_to_variation() */ - vtr::vector> transistor_model_variation_names_; - vtr::vector> transistor_model_variation_ids_; + vtr::vector> transistor_model_variation_names_; + vtr::vector> transistor_model_variation_ids_; /* ReRAM-related fundamental information: * Low Resistance State (LRS) resistance will be stored in the x() part of vtr::Point * High Resistance State (HRS) resistance will be stored in the y() part of vtr::Point + * Unit: [Ohm] */ - vtr::vector> rram_resistances_; + vtr::vector> rram_resistances_; /* The variation name and id binded to this RRAM * We expect users to provide the exact name of variation defined in this technology library - * the name and id will be automatically matched by using function link_device_to_variation() + * the name and id will be automatically matched by using function link_model_to_variation() */ - vtr::vector rram_variation_names_; - vtr::vector rram_variation_ids_; + vtr::vector rram_variation_names_; + vtr::vector rram_variation_ids_; /* Unique identifier for each process variation */ vtr::vector variation_ids_; @@ -275,7 +264,7 @@ class TechnologyLibrary { vtr::vector variation_num_sigmas_; /* Fast name-to-id lookup */ - std::map device_name2ids_; + std::map model_name2ids_; std::map variation_name2ids_; }; diff --git a/libopenfpga/libarchopenfpga/src/technology_library_fwd.h b/libopenfpga/libarchopenfpga/src/technology_library_fwd.h index 4055ff4f2..b222fab1d 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library_fwd.h +++ b/libopenfpga/libarchopenfpga/src/technology_library_fwd.h @@ -12,10 +12,10 @@ #include "vtr_strong_id.h" -struct technology_device_id_tag; +struct technology_model_id_tag; struct technology_variation_id_tag; -typedef vtr::StrongId TechnologyDeviceId; +typedef vtr::StrongId TechnologyModelId; typedef vtr::StrongId TechnologyVariationId; /* Short declaration of class */ From d58186507cb2db46e17ca9fb1e8afc7b54e4c1b6 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 17 Jan 2020 17:15:58 -0700 Subject: [PATCH 2/6] add XML parsing for device model library settings --- libopenfpga/libarchopenfpga/arch/sample_arch.xml | 6 +++--- libopenfpga/libarchopenfpga/src/technology_library.cpp | 2 +- libopenfpga/libarchopenfpga/src/technology_library.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libopenfpga/libarchopenfpga/arch/sample_arch.xml b/libopenfpga/libarchopenfpga/arch/sample_arch.xml index 100be50eb..a5f5c9adf 100644 --- a/libopenfpga/libarchopenfpga/arch/sample_arch.xml +++ b/libopenfpga/libarchopenfpga/arch/sample_arch.xml @@ -11,13 +11,13 @@ - + - - + + diff --git a/libopenfpga/libarchopenfpga/src/technology_library.cpp b/libopenfpga/libarchopenfpga/src/technology_library.cpp index db71b50c5..e3680465d 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/technology_library.cpp @@ -321,7 +321,7 @@ void TechnologyLibrary::set_model_ref(const TechnologyModelId& model_id, /* Set the library file path of a model in the library */ void TechnologyLibrary::set_model_lib_path(const TechnologyModelId& model_id, - const std::string& lib_path) { + const std::string& lib_path) { /* validate the model_id */ VTR_ASSERT(valid_model_id(model_id)); model_lib_paths_[model_id] = lib_path; diff --git a/libopenfpga/libarchopenfpga/src/technology_library.h b/libopenfpga/libarchopenfpga/src/technology_library.h index 3bf51c2e8..a38acade3 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.h +++ b/libopenfpga/libarchopenfpga/src/technology_library.h @@ -26,8 +26,8 @@ * State University (ASU). Available at ptm.asu.edu *******************************************************************/ enum e_tech_lib_type { - TECH_LIB_MODEL_INDUSTRY, - TECH_LIB_MODEL_ACADEMIA, + TECH_LIB_INDUSTRY, + TECH_LIB_ACADEMIA, NUM_TECH_LIB_TYPES }; /* Strings correspond to each technology library type */ From de0bcc96fb2053c6614bda565c543a431771c248 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 17 Jan 2020 17:16:32 -0700 Subject: [PATCH 3/6] add missing file about XML parsers for technology library --- .../src/read_xml_technology_library.cpp | 165 ++++++++++++++++++ .../src/read_xml_technology_library.h | 17 ++ 2 files changed, 182 insertions(+) create mode 100644 libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp create mode 100644 libopenfpga/libarchopenfpga/src/read_xml_technology_library.h diff --git a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp new file mode 100644 index 000000000..dea93822e --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp @@ -0,0 +1,165 @@ +/******************************************************************** + * This file includes the top-level function of this library + * which reads an XML modeling OpenFPGA architecture to the associated + * data structures + *******************************************************************/ +#include + +/* Headers from pugi XML library */ +#include "pugixml.hpp" +#include "pugixml_util.hpp" + +/* Headers from vtr util library */ +#include "vtr_assert.h" + +/* Headers from libarchfpga */ +#include "arch_error.h" +#include "read_xml_util.h" + +#include "read_xml_technology_library.h" + +/******************************************************************** + * Convert string to the enumerate of device model type + *******************************************************************/ +static +e_tech_lib_model_type string_to_device_model_type(const std::string& type_string) { + if (std::string("transistor") == type_string) { + return TECH_LIB_MODEL_TRANSISTOR; + } + + if (std::string("rram") == type_string) { + return TECH_LIB_MODEL_RRAM; + } + + return NUM_TECH_LIB_MODEL_TYPES; +} + +/******************************************************************** + * Convert string to the enumerate of technology library type + *******************************************************************/ +static +e_tech_lib_type string_to_tech_lib_type(const std::string& type_string) { + if (std::string("industry") == type_string) { + return TECH_LIB_INDUSTRY; + } + + if (std::string("academia") == type_string) { + return TECH_LIB_ACADEMIA; + } + + return NUM_TECH_LIB_TYPES; +} + +/******************************************************************** + * Parse XML codes of a to an object of technology library + *******************************************************************/ +static +void read_xml_device_model_lib_settings(pugi::xml_node& xml_device_model_lib, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib, + TechnologyModelId& device_model) { + /* Parse the type of model library */ + const char* type_attr = get_attribute(xml_device_model_lib, "type", loc_data).value(); + /* Translate the type of design technology to enumerate */ + e_tech_lib_type device_model_lib_type = string_to_tech_lib_type(std::string(type_attr)); + + if (NUM_TECH_LIB_TYPES == device_model_lib_type) { + archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_device_model_lib), + "Invalid 'type' attribute '%s'\n", + type_attr); + } + + tech_lib.set_model_lib_type(device_model, device_model_lib_type); + + /* Parse the type of process corner, this is ONLY applicable to industry library */ + if (TECH_LIB_INDUSTRY == tech_lib.model_lib_type(device_model)) { + tech_lib.set_model_corner(device_model, get_attribute(xml_device_model_lib, "corner", loc_data).as_string()); + } + + /* Parse the model reference */ + tech_lib.set_model_ref(device_model, get_attribute(xml_device_model_lib, "ref", loc_data).as_string()); + + /* Parse the lib path */ + tech_lib.set_model_lib_path(device_model, get_attribute(xml_device_model_lib, "path", loc_data).as_string()); +} + +/******************************************************************** + * Parse XML codes of a to an object of technology library + *******************************************************************/ +static +void read_xml_device_model(pugi::xml_node& xml_device_model, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib) { + /* Get the name of this device_model node and add a device to the technology library */ + TechnologyModelId device_model = tech_lib.add_model(get_attribute(xml_device_model, "name", loc_data).as_string()); + + /* Find the type of device model*/ + const char* type_attr = get_attribute(xml_device_model, "type", loc_data).value(); + /* Translate the type of design technology to enumerate */ + e_tech_lib_model_type device_model_type = string_to_device_model_type(std::string(type_attr)); + + if (NUM_TECH_LIB_MODEL_TYPES == device_model_type) { + archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_device_model), + "Invalid 'type' attribute '%s'\n", + type_attr); + } + + tech_lib.set_model_type(device_model, device_model_type); + + /* Model library -relate attributes */ + auto xml_device_model_lib = get_single_child(xml_device_model, "lib", loc_data); + read_xml_device_model_lib_settings(xml_device_model_lib, loc_data, tech_lib, device_model); + +} + +/******************************************************************** + * Parse XML codes of a to an object of technology library + *******************************************************************/ +static +void read_xml_device_lib(pugi::xml_node& xml_device_lib, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib) { + /* Iterate over the children under this node, + * each child should be named after + */ + for (pugi::xml_node xml_device_model : xml_device_lib.children()) { + /* Error out if the XML child has an invalid name! */ + if (xml_device_model.name() != std::string("device_model")) { + bad_tag(xml_device_model, loc_data, xml_device_lib, {"device_model"}); + } + read_xml_device_model(xml_device_model, loc_data, tech_lib); + } +} + +/******************************************************************** + * Parse XML codes about to an object of technology library + *******************************************************************/ +TechnologyLibrary read_xml_technology_library(pugi::xml_node& Node, + const pugiutil::loc_data& loc_data) { + TechnologyLibrary tech_lib; + + /* Iterate over the children under this node, + * There should be only two child nodes + * 1. device_library + * 2. variation_library + */ + size_t num_device_lib = count_children(Node, "device_library", loc_data); + if (1 != num_device_lib) { + archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node), + "Expect only 1 defined under "); + } + + pugi::xml_node xml_device_lib = get_first_child(Node, "device_library", loc_data); + read_xml_device_lib(xml_device_lib, loc_data, tech_lib); + + size_t num_variation_lib = count_children(Node, "variation_library", loc_data); + if (1 != num_variation_lib) { + archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node), + "Expect only 1 defined under "); + } + + pugi::xml_node xml_variation_lib = get_first_child(Node, "variation_library", loc_data); + + return tech_lib; +} + diff --git a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.h b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.h new file mode 100644 index 000000000..bbb65c122 --- /dev/null +++ b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.h @@ -0,0 +1,17 @@ +#ifndef READ_XML_TECHNOLOGY_LIBRARY_H +#define READ_XML_TECHNOLOGY_LIBRARY_H + +/******************************************************************** + * Include header files that are required by function declaration + *******************************************************************/ +#include "pugixml_util.hpp" +#include "pugixml.hpp" +#include "technology_library.h" + +/******************************************************************** + * Function declaration + *******************************************************************/ +TechnologyLibrary read_xml_technology_library(pugi::xml_node& Node, + const pugiutil::loc_data& loc_data); + +#endif From d48a888804994bbd11853b7330fdaa90b3da50dc Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 17 Jan 2020 17:22:09 -0700 Subject: [PATCH 4/6] add XML parsing for design parameters in technology library --- .../src/read_xml_technology_library.cpp | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp index dea93822e..47bbce8e2 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp @@ -51,7 +51,8 @@ e_tech_lib_type string_to_tech_lib_type(const std::string& type_string) { } /******************************************************************** - * Parse XML codes of a to an object of technology library + * Parse XML codes of a under a device model definiton + * to an object of technology library *******************************************************************/ static void read_xml_device_model_lib_settings(pugi::xml_node& xml_device_model_lib, @@ -83,6 +84,22 @@ void read_xml_device_model_lib_settings(pugi::xml_node& xml_device_model_lib, tech_lib.set_model_lib_path(device_model, get_attribute(xml_device_model_lib, "path", loc_data).as_string()); } +/******************************************************************** + * Parse XML codes of design parameters under a device model + * to an object of technology library + *******************************************************************/ +static +void read_xml_device_model_design_settings(pugi::xml_node& xml_device_model_design, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib, + TechnologyModelId& device_model) { + /* Parse the vdd to be used in circuit design */ + tech_lib.set_model_vdd(device_model, get_attribute(xml_device_model_design, "vdd", loc_data).as_float(0.)); + + /* Parse the width ratio between PMOS and NMOS transistor */ + tech_lib.set_model_pn_ratio(device_model, get_attribute(xml_device_model_design, "pn_ratio", loc_data).as_float(0.)); +} + /******************************************************************** * Parse XML codes of a to an object of technology library *******************************************************************/ @@ -109,7 +126,12 @@ void read_xml_device_model(pugi::xml_node& xml_device_model, /* Model library -relate attributes */ auto xml_device_model_lib = get_single_child(xml_device_model, "lib", loc_data); read_xml_device_model_lib_settings(xml_device_model_lib, loc_data, tech_lib, device_model); - + + /* Model design -relate attributes, this is ONLY applicable to transistor models */ + if (TECH_LIB_MODEL_TRANSISTOR == tech_lib.model_type(device_model)) { + auto xml_device_model_design = get_single_child(xml_device_model, "design", loc_data); + read_xml_device_model_design_settings(xml_device_model_design, loc_data, tech_lib, device_model); + } } /******************************************************************** From e54760c677fe77463379cae89bad67972421ea10 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 17 Jan 2020 17:32:42 -0700 Subject: [PATCH 5/6] add XML parsing for transistors and RRAM parameters in technology library --- .../src/read_xml_technology_library.cpp | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp index 47bbce8e2..6db188744 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp @@ -100,6 +100,50 @@ void read_xml_device_model_design_settings(pugi::xml_node& xml_device_model_desi tech_lib.set_model_pn_ratio(device_model, get_attribute(xml_device_model_design, "pn_ratio", loc_data).as_float(0.)); } +/******************************************************************** + * Parse XML codes of transistor models under a device model + * to an object of technology library + *******************************************************************/ +static +void read_xml_device_transistor(pugi::xml_node& xml_device_transistor, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib, + TechnologyModelId& device_model, + const e_tech_lib_transistor_type& transistor_type) { + /* Parse the transistor model name */ + tech_lib.set_transistor_model_name(device_model, transistor_type, + get_attribute(xml_device_transistor, "name", loc_data).as_string()); + + /* Parse the transistor channel length */ + tech_lib.set_transistor_model_chan_length(device_model, transistor_type, + get_attribute(xml_device_transistor, "chan_length", loc_data).as_float(0.)); + + /* Parse the transistor minimum width */ + tech_lib.set_transistor_model_min_width(device_model, transistor_type, + get_attribute(xml_device_transistor, "min_width", loc_data).as_float(0.)); + + /* Parse the transistor variation name */ + tech_lib.set_transistor_model_variation_name(device_model, transistor_type, + get_attribute(xml_device_transistor, "variation", loc_data).as_string()); +} + +/******************************************************************** + * Parse XML codes of RRAM models under a device model + * to an object of technology library + *******************************************************************/ +static +void read_xml_device_rram(pugi::xml_node& xml_device_rram, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib, + TechnologyModelId& device_model) { + /* Parse the LRS and HRS resistance */ + tech_lib.set_rram_rlrs(device_model, get_attribute(xml_device_rram, "rlrs", loc_data).as_float(0.)); + tech_lib.set_rram_rhrs(device_model, get_attribute(xml_device_rram, "rhrs", loc_data).as_float(0.)); + + /* Parse the RRAM variation name */ + tech_lib.set_rram_variation_name(device_model, get_attribute(xml_device_rram, "variation", loc_data).as_string()); +} + /******************************************************************** * Parse XML codes of a to an object of technology library *******************************************************************/ @@ -132,6 +176,21 @@ void read_xml_device_model(pugi::xml_node& xml_device_model, auto xml_device_model_design = get_single_child(xml_device_model, "design", loc_data); read_xml_device_model_design_settings(xml_device_model_design, loc_data, tech_lib, device_model); } + + /* Transistor -relate attributes, this is ONLY applicable to transistor models */ + if (TECH_LIB_MODEL_TRANSISTOR == tech_lib.model_type(device_model)) { + auto xml_device_model_pmos = get_single_child(xml_device_model, "pmos", loc_data); + read_xml_device_transistor(xml_device_model_pmos, loc_data, tech_lib, device_model, TECH_LIB_TRANSISTOR_PMOS); + + auto xml_device_model_nmos = get_single_child(xml_device_model, "nmos", loc_data); + read_xml_device_transistor(xml_device_model_nmos, loc_data, tech_lib, device_model, TECH_LIB_TRANSISTOR_NMOS); + } + + /* RRAM -relate attributes, this is ONLY applicable to RRAM models */ + if (TECH_LIB_MODEL_RRAM == tech_lib.model_type(device_model)) { + auto xml_device_rram = get_single_child(xml_device_model, "rram", loc_data); + read_xml_device_rram(xml_device_rram, loc_data, tech_lib, device_model); + } } /******************************************************************** From 8f2936af54633ca0bac4f03104ad2faecef719da Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 17 Jan 2020 17:43:55 -0700 Subject: [PATCH 6/6] finish XML parser for technology library --- .../libarchopenfpga/arch/sample_arch.xml | 8 ++--- .../src/read_xml_openfpga_arch.cpp | 2 ++ .../src/read_xml_technology_library.cpp | 34 +++++++++++++++++++ .../src/technology_library.cpp | 1 + 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libopenfpga/libarchopenfpga/arch/sample_arch.xml b/libopenfpga/libarchopenfpga/arch/sample_arch.xml index a5f5c9adf..09dff4a9b 100644 --- a/libopenfpga/libarchopenfpga/arch/sample_arch.xml +++ b/libopenfpga/libarchopenfpga/arch/sample_arch.xml @@ -32,10 +32,10 @@ - - - - + + + + diff --git a/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp b/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp index af66f78ad..8b7506f36 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_openfpga_arch.cpp @@ -51,6 +51,8 @@ openfpga::Arch read_xml_openfpga_arch(const char* arch_file_name) { /* Parse technology library */ auto xml_tech_lib = get_single_child(xml_openfpga_arch, "technology_library", loc_data); openfpga_arch.tech_lib = read_xml_technology_library(xml_tech_lib, loc_data); + /* Build the internal link for technology library */ + openfpga_arch.tech_lib.link_models_to_variations(); /* Second node should be */ auto xml_simulation_settings = get_single_child(doc, "openfpga_simulation_setting", loc_data); diff --git a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp index 6db188744..f7e40a969 100644 --- a/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/read_xml_technology_library.cpp @@ -193,6 +193,20 @@ void read_xml_device_model(pugi::xml_node& xml_device_model, } } +/******************************************************************** + * Parse XML codes of a to an object of technology library + *******************************************************************/ +static +void read_xml_device_variation(pugi::xml_node& xml_device_variation, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib) { + /* Get the name of this variation and add it to the technology library */ + TechnologyVariationId variation = tech_lib.add_variation(get_attribute(xml_device_variation, "name", loc_data).as_string()); + + tech_lib.set_variation_abs_value(variation, get_attribute(xml_device_variation, "abs_deviation", loc_data).as_float(0.)); + tech_lib.set_variation_num_sigma(variation, get_attribute(xml_device_variation, "num_sigma", loc_data).as_int(0.)); +} + /******************************************************************** * Parse XML codes of a to an object of technology library *******************************************************************/ @@ -212,6 +226,25 @@ void read_xml_device_lib(pugi::xml_node& xml_device_lib, } } +/******************************************************************** + * Parse XML codes of a to an object of technology library + *******************************************************************/ +static +void read_xml_variation_lib(pugi::xml_node& xml_variation_lib, + const pugiutil::loc_data& loc_data, + TechnologyLibrary& tech_lib) { + /* Iterate over the children under this node, + * each child should be named after + */ + for (pugi::xml_node xml_device_variation : xml_variation_lib.children()) { + /* Error out if the XML child has an invalid name! */ + if (xml_device_variation.name() != std::string("variation")) { + bad_tag(xml_device_variation, loc_data, xml_variation_lib, {"variation"}); + } + read_xml_device_variation(xml_device_variation, loc_data, tech_lib); + } +} + /******************************************************************** * Parse XML codes about to an object of technology library *******************************************************************/ @@ -240,6 +273,7 @@ TechnologyLibrary read_xml_technology_library(pugi::xml_node& Node, } pugi::xml_node xml_variation_lib = get_first_child(Node, "variation_library", loc_data); + read_xml_variation_lib(xml_variation_lib, loc_data, tech_lib); return tech_lib; } diff --git a/libopenfpga/libarchopenfpga/src/technology_library.cpp b/libopenfpga/libarchopenfpga/src/technology_library.cpp index e3680465d..1638d13e1 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/technology_library.cpp @@ -461,6 +461,7 @@ TechnologyVariationId TechnologyLibrary::add_variation(const std::string& name) /* This is a legal name. we can create a new id */ TechnologyVariationId variation = TechnologyVariationId(variation_ids_.size()); + variation_ids_.push_back(variation); variation_names_.push_back(name); variation_abs_values_.push_back(0.); variation_num_sigmas_.push_back(size_t(-1));