diff --git a/libopenfpga/libarchopenfpga/src/technology_library.cpp b/libopenfpga/libarchopenfpga/src/technology_library.cpp index e1f289c75..519fa0897 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.cpp +++ b/libopenfpga/libarchopenfpga/src/technology_library.cpp @@ -48,8 +48,16 @@ std::string TechnologyLibrary::device_name(const TechnologyDeviceId& device_id) return device_names_[device_id]; } -/* Access the id of a technology device by name */ +/* Access the id of a technology device 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(); + } + return device_name2ids_.at(name); } @@ -207,8 +215,16 @@ std::string TechnologyLibrary::variation_name(const TechnologyVariationId& varia return variation_names_[variation_id]; } -/* Access the id of a technology variation by name */ +/* Access the id of a technology variation by name + * If the name is valid, we return a valid id + * Otherwise, return an invalid id + */ TechnologyVariationId TechnologyLibrary::variation(const std::string& name) const { + std::map::const_iterator it = variation_name2ids_.find(name); + if (it != variation_name2ids_.end()) { + return TechnologyVariationId::INVALID(); + } + return variation_name2ids_.at(name); } @@ -471,6 +487,38 @@ void TechnologyLibrary::set_variation_num_sigma(const TechnologyVariationId& var return; } +/************************************************************************ + * Public mutators: linkers + ***********************************************************************/ +/* This function builds the links between devices and variations, + * which have been defined in the technology library + */ +void TechnologyLibrary::link_devices_to_variations() { + for (const TechnologyDeviceId& device : devices()) { + /* For transistors, find the variation name for each model and build a link */ + if (TECH_LIB_DEVICE_TRANSISTOR == device_type(device)) { + /* 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); + + /* 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); + /* 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); + /* Finish for RRAMs, go to the next */ + } +} + /************************************************************************ * Internal invalidators/validators ***********************************************************************/ diff --git a/libopenfpga/libarchopenfpga/src/technology_library.h b/libopenfpga/libarchopenfpga/src/technology_library.h index ae78da00b..bd0b40607 100644 --- a/libopenfpga/libarchopenfpga/src/technology_library.h +++ b/libopenfpga/libarchopenfpga/src/technology_library.h @@ -52,12 +52,12 @@ constexpr std::array TECH_LIB_DEVICE_TYP * 2. PMOS transistor *******************************************************************/ enum e_tech_lib_trans_type { - TECH_LIB_TRANS_PMOS, - TECH_LIB_TRANS_NMOS, - NUM_TECH_LIB_TRANS_TYPES + TECH_LIB_TRANSISTOR_PMOS, + TECH_LIB_TRANSISTOR_NMOS, + NUM_TECH_LIB_TRANSISTOR_TYPES }; /* Strings correspond to transistor type */ -constexpr std::array TECH_LIB_TRANS_TYPE_STRING = {{"pmos", "nmos"}}; +constexpr std::array TECH_LIB_TRANSISTOR_TYPE_STRING = {{"pmos", "nmos"}}; /******************************************************************** * Process corners supported @@ -155,6 +155,8 @@ class TechnologyLibrary { 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(); public: /* Public invalidators/validators */ bool valid_device_id(const TechnologyDeviceId& device_id) const; bool valid_variation_id(const TechnologyVariationId& variation_id) const;