From 7688c0570f47adeb7d215cbb716d38b0fca9df83 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Tue, 21 Sep 2021 15:08:08 -0700 Subject: [PATCH] [Engine] Support coordinate definition in fabric key file format; Now QL memory bank can accept fabric key --- libopenfpga/libfabrickey/src/fabric_key.cpp | 20 +++++++++++++++++++ libopenfpga/libfabrickey/src/fabric_key.h | 12 +++++++++++ .../libfabrickey/src/read_xml_fabric_key.cpp | 13 ++++++++++++ .../libfabrickey/src/write_xml_fabric_key.cpp | 6 ++++++ .../src/fabric/build_top_module_memory.cpp | 3 ++- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/libopenfpga/libfabrickey/src/fabric_key.cpp b/libopenfpga/libfabrickey/src/fabric_key.cpp index dfe445c75..d15c86e56 100644 --- a/libopenfpga/libfabrickey/src/fabric_key.cpp +++ b/libopenfpga/libfabrickey/src/fabric_key.cpp @@ -54,6 +54,12 @@ std::string FabricKey::key_alias(const FabricKeyId& key_id) const { return key_alias_[key_id]; } +vtr::Point FabricKey::key_coordinate(const FabricKeyId& key_id) const { + /* validate the key_id */ + VTR_ASSERT(valid_key_id(key_id)); + return key_coordinates_[key_id]; +} + bool FabricKey::empty() const { return 0 == key_ids_.size(); } @@ -124,6 +130,7 @@ void FabricKey::reserve_keys(const size_t& num_keys) { key_values_.reserve(num_keys); key_regions_.reserve(num_keys); key_alias_.reserve(num_keys); + key_coordinates_.reserve(num_keys); } FabricKeyId FabricKey::create_key() { @@ -134,6 +141,7 @@ FabricKeyId FabricKey::create_key() { key_values_.emplace_back(); key_regions_.emplace_back(FabricRegionId::INVALID()); key_alias_.emplace_back(); + key_coordinates_.emplace_back(vtr::Point(-1, -1)); return key; } @@ -162,6 +170,14 @@ void FabricKey::set_key_alias(const FabricKeyId& key_id, key_alias_[key_id] = alias; } +void FabricKey::set_key_coordinate(const FabricKeyId& key_id, + const vtr::Point& coord) { + /* validate the key_id */ + VTR_ASSERT(valid_key_id(key_id)); + + key_coordinates_[key_id] = coord; +} + /************************************************************************ * Internal invalidators/validators ***********************************************************************/ @@ -173,3 +189,7 @@ bool FabricKey::valid_region_id(const FabricRegionId& region_id) const { bool FabricKey::valid_key_id(const FabricKeyId& key_id) const { return ( size_t(key_id) < key_ids_.size() ) && ( key_id == key_ids_[key_id] ); } + +bool FabricKey::valid_key_coordinate(const vtr::Point& coord) const { + return coord.x() > -1 && coord.y() > -1; +} diff --git a/libopenfpga/libfabrickey/src/fabric_key.h b/libopenfpga/libfabrickey/src/fabric_key.h index 0ca1d252d..6e9025f9e 100644 --- a/libopenfpga/libfabrickey/src/fabric_key.h +++ b/libopenfpga/libfabrickey/src/fabric_key.h @@ -10,6 +10,7 @@ /* Headers from vtrutil library */ #include "vtr_vector.h" +#include "vtr_geometry.h" #include "fabric_key_fwd.h" @@ -58,6 +59,9 @@ class FabricKey { /* Access the alias of a key */ std::string key_alias(const FabricKeyId& key_id) const; + /* Access the coordinate of a key */ + vtr::Point key_coordinate(const FabricKeyId& key_id) const; + /* Check if there are any keys */ bool empty() const; @@ -93,9 +97,14 @@ class FabricKey { void set_key_alias(const FabricKeyId& key_id, const std::string& alias); + void set_key_coordinate(const FabricKeyId& key_id, + const vtr::Point& coord); + public: /* Public invalidators/validators */ bool valid_region_id(const FabricRegionId& region_id) const; bool valid_key_id(const FabricKeyId& key_id) const; + /* Identify if key coordinate is acceptable to fabric key convention */ + bool valid_key_coordinate(const vtr::Point& coord) const; private: /* Internal data */ /* Unique ids for each region */ vtr::vector region_ids_; @@ -112,6 +121,9 @@ class FabricKey { /* Values for each key */ vtr::vector key_values_; + /* Values for each key */ + vtr::vector> key_coordinates_; + /* Region for each key */ vtr::vector key_regions_; diff --git a/libopenfpga/libfabrickey/src/read_xml_fabric_key.cpp b/libopenfpga/libfabrickey/src/read_xml_fabric_key.cpp index 24e0d8255..b9e83787f 100644 --- a/libopenfpga/libfabrickey/src/read_xml_fabric_key.cpp +++ b/libopenfpga/libfabrickey/src/read_xml_fabric_key.cpp @@ -60,6 +60,19 @@ void read_xml_region_key(pugi::xml_node& xml_component_key, fabric_key.set_key_name(FabricKeyId(id), name); fabric_key.set_key_value(FabricKeyId(id), value); fabric_key.add_key_to_region(fabric_region, FabricKeyId(id)); + + /* Parse coordinates */ + vtr::Point coord; + coord.set_x(get_attribute(xml_component_key, "column", loc_data, pugiutil::ReqOpt::OPTIONAL).as_int(-1)); + coord.set_y(get_attribute(xml_component_key, "row", loc_data, pugiutil::ReqOpt::OPTIONAL).as_int(-1)); + /* Require positive coordinate all the time */ + if (!fabric_key.valid_key_coordinate(coord)) { + archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_component_key), + "Invalid coordinate '(%d, %d)' which contain negative numbers\n", + coord.x(), coord.y()); + } else { + fabric_key.set_key_coordinate(FabricKeyId(id), coord); + } } /******************************************************************** diff --git a/libopenfpga/libfabrickey/src/write_xml_fabric_key.cpp b/libopenfpga/libfabrickey/src/write_xml_fabric_key.cpp index ea12d75a1..aa38c8140 100644 --- a/libopenfpga/libfabrickey/src/write_xml_fabric_key.cpp +++ b/libopenfpga/libfabrickey/src/write_xml_fabric_key.cpp @@ -52,6 +52,12 @@ int write_xml_fabric_component_key(std::fstream& fp, write_xml_attribute(fp, "alias", fabric_key.key_alias(component_key).c_str()); } + vtr::Point coord = fabric_key.key_coordinate(component_key); + if (fabric_key.valid_key_coordinate(coord)) { + write_xml_attribute(fp, "column", coord.x()); + write_xml_attribute(fp, "row", coord.y()); + } + fp << "/>" << "\n"; return 0; diff --git a/openfpga/src/fabric/build_top_module_memory.cpp b/openfpga/src/fabric/build_top_module_memory.cpp index c9ee2b722..ca78f8e88 100644 --- a/openfpga/src/fabric/build_top_module_memory.cpp +++ b/openfpga/src/fabric/build_top_module_memory.cpp @@ -636,7 +636,8 @@ int load_top_module_memory_modules_from_fabric_key(ModuleManager& module_manager /* Now we can add the child to configurable children of the top module */ module_manager.add_configurable_child(top_module, instance_info.first, - instance_info.second); + instance_info.second, + fabric_key.key_coordinate(key)); module_manager.add_configurable_child_to_region(top_module, top_module_config_region, instance_info.first,