diff --git a/openfpga/src/annotation/device_rr_gsb.cpp b/openfpga/src/annotation/device_rr_gsb.cpp new file mode 100644 index 000000000..9152f209c --- /dev/null +++ b/openfpga/src/annotation/device_rr_gsb.cpp @@ -0,0 +1,452 @@ +/************************************************************************ + * Member functions for class DeviceRRGSB + ***********************************************************************/ +#include "vtr_log.h" +#include "vtr_assert.h" +#include "device_rr_gsb.h" + +/* namespace openfpga begins */ +namespace openfpga { + +/************************************************************************ + * Constructors + ***********************************************************************/ + +/************************************************************************ + * Public accessors + ***********************************************************************/ +/* get the max coordinate of the switch block array */ +vtr::Point DeviceRRGSB::get_gsb_range() const { + size_t max_y = 0; + /* Get the largest size of sub-arrays */ + for (size_t x = 0; x < rr_gsb_.size(); ++x) { + max_y = std::max(max_y, rr_gsb_[x].size()); + } + + vtr::Point coordinate(rr_gsb_.size(), max_y); + return coordinate; +} + +/* Get a rr switch block in the array with a coordinate */ +const RRGSB DeviceRRGSB::get_gsb(const vtr::Point& coordinate) const { + VTR_ASSERT(validate_coordinate(coordinate)); + return rr_gsb_[coordinate.x()][coordinate.y()]; +} + +/* Get a rr switch block in the array with a coordinate */ +const RRGSB DeviceRRGSB::get_gsb(const size_t& x, const size_t& y) const { + vtr::Point coordinate(x, y); + return get_gsb(coordinate); +} + +/* get the number of unique mirrors of switch blocks */ +size_t DeviceRRGSB::get_num_cb_unique_module(const t_rr_type& cb_type) const { + VTR_ASSERT (validate_cb_type(cb_type)); + switch(cb_type) { + case CHANX: + return cbx_unique_module_.size(); + case CHANY: + return cby_unique_module_.size(); + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } +} + +/* get the number of unique mirrors of switch blocks */ +size_t DeviceRRGSB::get_num_sb_unique_module() const { + return sb_unique_module_.size(); +} + +/* get the number of unique mirrors of switch blocks */ +size_t DeviceRRGSB::get_num_gsb_unique_module() const { + return gsb_unique_module_.size(); +} + +/* Get a rr switch block which a unique mirror */ +const RRGSB DeviceRRGSB::get_sb_unique_module(const size_t& index) const { + VTR_ASSERT (validate_sb_unique_module_index(index)); + + return rr_gsb_[sb_unique_module_[index].x()][sb_unique_module_[index].y()]; +} + +/* Get a rr switch block which a unique mirror */ +const RRGSB& DeviceRRGSB::get_cb_unique_module(const t_rr_type& cb_type, const size_t& index) const { + VTR_ASSERT (validate_cb_unique_module_index(cb_type, index)); + VTR_ASSERT (validate_cb_type(cb_type)); + switch(cb_type) { + case CHANX: + return rr_gsb_[cbx_unique_module_[index].x()][cbx_unique_module_[index].y()]; + case CHANY: + return rr_gsb_[cby_unique_module_[index].x()][cby_unique_module_[index].y()]; + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } +} + +/* Give a coordinate of a rr switch block, and return its unique mirror */ +const RRGSB& DeviceRRGSB::get_cb_unique_module(const t_rr_type& cb_type, const vtr::Point& coordinate) const { + VTR_ASSERT(validate_cb_type(cb_type)); + VTR_ASSERT(validate_coordinate(coordinate)); + size_t cb_unique_module_id; + + switch(cb_type) { + case CHANX: + cb_unique_module_id = cbx_unique_module_id_[coordinate.x()][coordinate.y()]; + break; + case CHANY: + cb_unique_module_id = cby_unique_module_id_[coordinate.x()][coordinate.y()]; + break; + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } + + return get_cb_unique_module(cb_type, cb_unique_module_id); +} + +/* Give a coordinate of a rr switch block, and return its unique mirror */ +const RRGSB DeviceRRGSB::get_sb_unique_module(const vtr::Point& coordinate) const { + VTR_ASSERT(validate_coordinate(coordinate)); + size_t sb_unique_module_id = sb_unique_module_id_[coordinate.x()][coordinate.y()]; + return get_sb_unique_module(sb_unique_module_id); +} + +/************************************************************************ + * Public mutators + ***********************************************************************/ + +/* Pre-allocate the rr_switch_block array that the device requires */ +void DeviceRRGSB::reserve(const vtr::Point& coordinate) { + rr_gsb_.resize(coordinate.x()); + + gsb_unique_module_id_.resize(coordinate.x()); + + sb_unique_module_id_.resize(coordinate.x()); + + cbx_unique_module_id_.resize(coordinate.x()); + cby_unique_module_id_.resize(coordinate.x()); + + for (size_t x = 0; x < coordinate.x(); ++x) { + rr_gsb_[x].resize(coordinate.y()); + + gsb_unique_module_id_[x].resize(coordinate.y()); + + sb_unique_module_id_[x].resize(coordinate.y()); + + cbx_unique_module_id_[x].resize(coordinate.y()); + cby_unique_module_id_[x].resize(coordinate.y()); + } +} + +/* Resize rr_switch_block array is needed*/ +void DeviceRRGSB::resize_upon_need(const vtr::Point& coordinate) { + if (coordinate.x() + 1 > rr_gsb_.size()) { + rr_gsb_.resize(coordinate.x() + 1); + + sb_unique_module_id_.resize(coordinate.x() + 1); + + cbx_unique_module_id_.resize(coordinate.x() + 1); + cby_unique_module_id_.resize(coordinate.x() + 1); + } + + if (coordinate.y() + 1 > rr_gsb_[coordinate.x()].size()) { + rr_gsb_[coordinate.x()].resize(coordinate.y() + 1); + sb_unique_module_id_[coordinate.x()].resize(coordinate.y() + 1); + + cbx_unique_module_id_[coordinate.x()].resize(coordinate.y() + 1); + cby_unique_module_id_[coordinate.x()].resize(coordinate.y() + 1); + } +} + +/* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ +void DeviceRRGSB::add_rr_gsb(const vtr::Point& coordinate, + const RRGSB& rr_gsb) { + /* Resize upon needs*/ + resize_upon_need(coordinate); + + /* Add the switch block into array */ + rr_gsb_[coordinate.x()][coordinate.y()] = rr_gsb; +} + +/* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ +void DeviceRRGSB::build_cb_unique_module(const RRGraph& rr_graph, const t_rr_type& cb_type) { + /* Make sure a clean start */ + clear_cb_unique_module(cb_type); + + for (size_t ix = 0; ix < rr_gsb_.size(); ++ix) { + for (size_t iy = 0; iy < rr_gsb_[ix].size(); ++iy) { + bool is_unique_module = true; + vtr::Point gsb_coordinate(ix, iy); + + /* Bypass non-exist CB */ + if ( false == rr_gsb_[ix][iy].is_cb_exist(cb_type) ) { + continue; + } + + /* Traverse the unique_mirror list and check it is an mirror of another */ + for (size_t id = 0; id < get_num_cb_unique_module(cb_type); ++id) { + const RRGSB& unique_module = get_cb_unique_module(cb_type, id); + if (true == rr_gsb_[ix][iy].is_cb_mirror(rr_graph, unique_module, cb_type)) { + /* This is a mirror, raise the flag and we finish */ + is_unique_module = false; + /* Record the id of unique mirror */ + set_cb_unique_module_id(cb_type, gsb_coordinate, id); + break; + } + } + /* Add to list if this is a unique mirror*/ + if (true == is_unique_module) { + add_cb_unique_module(cb_type, gsb_coordinate); + /* Record the id of unique mirror */ + set_cb_unique_module_id(cb_type, gsb_coordinate, get_num_cb_unique_module(cb_type) - 1); + } + } + } +} + +/* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ +void DeviceRRGSB::build_sb_unique_module(const RRGraph& rr_graph) { + /* Make sure a clean start */ + clear_sb_unique_module(); + + /* Build the unique module */ + for (size_t ix = 0; ix < rr_gsb_.size(); ++ix) { + for (size_t iy = 0; iy < rr_gsb_[ix].size(); ++iy) { + bool is_unique_module = true; + vtr::Point sb_coordinate(ix, iy); + + /* Traverse the unique_mirror list and check it is an mirror of another */ + for (size_t id = 0; id < get_num_sb_unique_module(); ++id) { + /* Check if the two modules have the same submodules, + * if so, these two modules are the same, indicating the sb is not unique. + * else the sb is unique + */ + const RRGSB& unique_module = get_sb_unique_module(id); + if (true == rr_gsb_[ix][iy].is_sb_mirror(rr_graph, unique_module)) { + /* This is a mirror, raise the flag and we finish */ + is_unique_module = false; + /* Record the id of unique mirror */ + sb_unique_module_id_[ix][iy] = id; + break; + } + } + /* Add to list if this is a unique mirror*/ + if (true == is_unique_module) { + sb_unique_module_.push_back(sb_coordinate); + /* Record the id of unique mirror */ + sb_unique_module_id_[ix][iy] = sb_unique_module_.size() - 1; + } + } + } +} + +/* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ + +/* Find repeatable GSB block in the array */ +void DeviceRRGSB::build_gsb_unique_module() { + /* Make sure a clean start */ + clear_gsb_unique_module(); + + for (size_t ix = 0; ix < rr_gsb_.size(); ++ix) { + for (size_t iy = 0; iy < rr_gsb_[ix].size(); ++iy) { + bool is_unique_module = true; + vtr::Point gsb_coordinate(ix, iy); + + /* Traverse the unique_mirror list and check it is an mirror of another */ + for (size_t id = 0; id < get_num_gsb_unique_module(); ++id) { + /* We have alreay built sb and cb unique module list + * We just need to check if the unique module id of SBs, CBX and CBY are the same or not + */ + const vtr::Point& gsb_unique_module_coordinate = gsb_unique_module_[id]; + if ((sb_unique_module_id_[ix][iy] == sb_unique_module_id_[gsb_unique_module_coordinate.x()][gsb_unique_module_coordinate.y()]) + && (cbx_unique_module_id_[ix][iy] == cbx_unique_module_id_[gsb_unique_module_coordinate.x()][gsb_unique_module_coordinate.y()]) + && (cby_unique_module_id_[ix][iy] == cby_unique_module_id_[gsb_unique_module_coordinate.x()][gsb_unique_module_coordinate.y()])) { + /* This is a mirror, raise the flag and we finish */ + is_unique_module = false; + /* Record the id of unique mirror */ + gsb_unique_module_id_[ix][iy] = id; + break; + } + } + /* Add to list if this is a unique mirror*/ + if (true == is_unique_module) { + add_gsb_unique_module(gsb_coordinate); + /* Record the id of unique mirror */ + gsb_unique_module_id_[ix][iy] = get_num_gsb_unique_module() - 1; + } + } + } +} + +void DeviceRRGSB::build_unique_module(const RRGraph& rr_graph) { + build_sb_unique_module(rr_graph); + + build_cb_unique_module(rr_graph, CHANX); + build_cb_unique_module(rr_graph, CHANY); + + build_gsb_unique_module(); +} + +void DeviceRRGSB::add_gsb_unique_module(const vtr::Point& coordinate) { + gsb_unique_module_.push_back(coordinate); +} + +void DeviceRRGSB::add_cb_unique_module(const t_rr_type& cb_type, const vtr::Point& coordinate) { + VTR_ASSERT (validate_cb_type(cb_type)); + switch(cb_type) { + case CHANX: + cbx_unique_module_.push_back(coordinate); + return; + case CHANY: + cby_unique_module_.push_back(coordinate); + return; + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } +} + +void DeviceRRGSB::set_cb_unique_module_id(const t_rr_type& cb_type, const vtr::Point& coordinate, size_t id) { + VTR_ASSERT(validate_cb_type(cb_type)); + size_t x = coordinate.x(); + size_t y = coordinate.y(); + switch(cb_type) { + case CHANX: + cbx_unique_module_id_[x][y] = id; + return; + case CHANY: + cby_unique_module_id_[x][y] = id; + return; + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } +} + +/************************************************************************ + * Public clean-up functions: + ***********************************************************************/ +/* clean the content */ +void DeviceRRGSB::clear() { + clear_gsb(); + + clear_gsb_unique_module(); + clear_gsb_unique_module_id(); + + /* clean unique module lists */ + clear_cb_unique_module(CHANX); + clear_cb_unique_module_id(CHANX); + + clear_cb_unique_module(CHANY); + clear_cb_unique_module_id(CHANY); + + clear_sb_unique_module(); + clear_sb_unique_module_id(); +} + +void DeviceRRGSB::clear_gsb() { + /* clean gsb array */ + for (size_t x = 0; x < rr_gsb_.size(); ++x) { + rr_gsb_[x].clear(); + } + rr_gsb_.clear(); +} + +void DeviceRRGSB::clear_gsb_unique_module_id() { + /* clean rr_switch_block array */ + for (size_t x = 0; x < rr_gsb_.size(); ++x) { + gsb_unique_module_id_[x].clear(); + } +} + +void DeviceRRGSB::clear_sb_unique_module_id() { + /* clean rr_switch_block array */ + for (size_t x = 0; x < rr_gsb_.size(); ++x) { + sb_unique_module_id_[x].clear(); + } +} + +void DeviceRRGSB::clear_cb_unique_module_id(const t_rr_type& cb_type) { + VTR_ASSERT (validate_cb_type(cb_type)); + switch(cb_type) { + case CHANX: + for (size_t x = 0; x < rr_gsb_.size(); ++x) { + cbx_unique_module_id_[x].clear(); + } + return; + case CHANY: + for (size_t x = 0; x < rr_gsb_.size(); ++x) { + cby_unique_module_id_[x].clear(); + } + return; + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } +} + +/* clean the content related to unique_mirrors */ +void DeviceRRGSB::clear_gsb_unique_module() { + /* clean unique mirror */ + gsb_unique_module_.clear(); +} + +/* clean the content related to unique_mirrors */ +void DeviceRRGSB::clear_sb_unique_module() { + /* clean unique mirror */ + sb_unique_module_.clear(); +} + +void DeviceRRGSB::clear_cb_unique_module(const t_rr_type& cb_type) { + VTR_ASSERT (validate_cb_type(cb_type)); + switch(cb_type) { + case CHANX: + cbx_unique_module_.clear(); + return; + case CHANY: + cby_unique_module_.clear(); + return; + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } +} + +/************************************************************************ + * Internal validators + ***********************************************************************/ +/* Validate if the (x,y) is the range of this device */ +bool DeviceRRGSB::validate_coordinate(const vtr::Point& coordinate) const { + if (coordinate.x() >= rr_gsb_.capacity()) { + return false; + } + return (coordinate.y() < rr_gsb_[coordinate.x()].capacity()); +} + +/* Validate if the index in the range of unique_mirror vector*/ +bool DeviceRRGSB::validate_sb_unique_module_index(const size_t& index) const { + return (index < sb_unique_module_.size()); +} + +bool DeviceRRGSB::validate_cb_unique_module_index(const t_rr_type& cb_type, const size_t& index) const { + VTR_ASSERT(validate_cb_type(cb_type)); + switch(cb_type) { + case CHANX: + return (index < cbx_unique_module_.size()); + case CHANY: + return (index < cby_unique_module_.size()); + default: + VTR_LOG_ERROR("Invalid type of connection block!\n"); + exit(1); + } + + return false; +} + +bool DeviceRRGSB::validate_cb_type(const t_rr_type& cb_type) const { + return ((CHANX == cb_type) || (CHANY == cb_type)); +} + +} /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/device_rr_gsb.h b/openfpga/src/annotation/device_rr_gsb.h index e801417bc..624492124 100644 --- a/openfpga/src/annotation/device_rr_gsb.h +++ b/openfpga/src/annotation/device_rr_gsb.h @@ -4,8 +4,17 @@ /******************************************************************** * Include header files required by the data structure definition *******************************************************************/ +/* Header files from vtrutil library */ +#include "vtr_geometry.h" + +/* Header files from vpr library */ +#include "rr_graph_obj.h" + #include "rr_gsb.h" +/* namespace openfpga begins */ +namespace openfpga { + /******************************************************************** * Object Device Routing Resource Switch Block * This includes: @@ -18,87 +27,58 @@ class DeviceRRGSB { public: /* Contructors */ public: /* Accessors */ - DeviceCoordinator get_gsb_range() const; /* get the max coordinator of the switch block array */ - const RRGSB get_gsb(const DeviceCoordinator& coordinator) const; /* Get a rr switch block in the array with a coordinator */ - const RRGSB get_gsb(size_t x, size_t y) const; /* Get a rr switch block in the array with a coordinator */ + vtr::Point get_gsb_range() const; /* get the max coordinate of the switch block array */ + const RRGSB get_gsb(const vtr::Point& coordinate) const; /* Get a rr switch block in the array with a coordinate */ + const RRGSB get_gsb(const size_t& x, const size_t& y) const; /* Get a rr switch block in the array with a coordinate */ size_t get_num_gsb_unique_module() const; /* get the number of unique mirrors of GSB */ - size_t get_num_sb_unique_submodule(enum e_side side, size_t seg_index) const; /* get the number of unique mirrors of switch blocks */ size_t get_num_sb_unique_module() const; /* get the number of unique mirrors of switch blocks */ - size_t get_num_cb_unique_module(t_rr_type cb_type) const; /* get the number of unique mirrors of CBs */ - size_t get_sb_unique_submodule_id(DeviceCoordinator& coordinator, enum e_side side, size_t seg_id) const; - const RRGSB get_sb_unique_submodule(size_t index, enum e_side side, size_t seg_id) const; /* Get a rr switch block which a unique mirror */ - const RRGSB get_sb_unique_submodule(DeviceCoordinator& coordinator, enum e_side side, size_t seg_id) const; /* Get a rr switch block which a unique mirror */ - const RRGSB get_sb_unique_module(size_t index) const; /* Get a rr switch block which a unique mirror */ - const RRGSB get_sb_unique_module(const DeviceCoordinator& coordinator) const; /* Get a rr switch block which a unique mirror */ - const RRGSB& get_cb_unique_module(t_rr_type cb_type, size_t index) const; /* Get a rr switch block which a unique mirror */ - const RRGSB& get_cb_unique_module(t_rr_type cb_type, const DeviceCoordinator& coordinator) const; - size_t get_max_num_sides() const; /* Get the maximum number of sides across the switch blocks */ - size_t get_num_segments() const; /* Get the size of segment_ids */ - size_t get_segment_id(size_t index) const; /* Get a segment id */ - bool is_two_sb_share_same_submodules(DeviceCoordinator& src, DeviceCoordinator& des) const; + const RRGSB get_sb_unique_module(const size_t& index) const; /* Get a rr switch block which a unique mirror */ + const RRGSB get_sb_unique_module(const vtr::Point& coordinate) const; /* Get a rr switch block which a unique mirror */ + const RRGSB& get_cb_unique_module(const t_rr_type& cb_type, const size_t& index) const; /* Get a rr switch block which a unique mirror */ + const RRGSB& get_cb_unique_module(const t_rr_type& cb_type, const vtr::Point& coordinate) const; + size_t get_num_cb_unique_module(const t_rr_type& cb_type) const; /* get the number of unique mirrors of CBs */ public: /* Mutators */ - void set_sb_num_reserved_conf_bits(DeviceCoordinator& coordinator, size_t num_reserved_conf_bits); /* TODO: TOBE DEPRECATED!!! conf_bits should be initialized when creating a switch block!!! */ - void set_sb_conf_bits_lsb(DeviceCoordinator& coordinator, size_t conf_bits_lsb); /* TODO: TOBE DEPRECATED!!! conf_bits should be initialized when creating a switch block!!! */ - void set_sb_conf_bits_msb(DeviceCoordinator& coordinator, size_t conf_bits_msb); /* TODO: TOBE DEPRECATED!!! conf_bits should be initialized when creating a switch block!!! */ - void set_cb_num_reserved_conf_bits(DeviceCoordinator& coordinator, t_rr_type cb_type, size_t num_reserved_conf_bits); /* TODO: TOBE DEPRECATED!!! conf_bits should be initialized when creating a switch block!!! */ - void set_cb_conf_bits_lsb(DeviceCoordinator& coordinator, t_rr_type cb_type, size_t conf_bits_lsb); /* TODO: TOBE DEPRECATED!!! conf_bits should be initialized when creating a switch block!!! */ - void set_cb_conf_bits_msb(DeviceCoordinator& coordinator, t_rr_type cb_type, size_t conf_bits_msb); /* TODO: TOBE DEPRECATED!!! conf_bits should be initialized when creating a switch block!!! */ - void reserve(DeviceCoordinator& coordinator); /* Pre-allocate the rr_switch_block array that the device requires */ - void reserve_sb_unique_submodule_id(DeviceCoordinator& coordinator); /* Pre-allocate the rr_sb_unique_module_id matrix that the device requires */ - void resize_upon_need(const DeviceCoordinator& coordinator); /* Resize the rr_switch_block array if needed */ - void add_rr_gsb(const DeviceCoordinator& coordinator, const RRGSB& rr_gsb); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ - void build_unique_module(); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ + void reserve(const vtr::Point& coordinate); /* Pre-allocate the rr_switch_block array that the device requires */ + void reserve_sb_unique_submodule_id(const vtr::Point& coordinate); /* Pre-allocate the rr_sb_unique_module_id matrix that the device requires */ + void resize_upon_need(const vtr::Point& coordinate); /* Resize the rr_switch_block array if needed */ + void add_rr_gsb(const vtr::Point& coordinate, const RRGSB& rr_gsb); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ + void build_unique_module(const RRGraph& rr_graph); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ void clear(); /* clean the content */ private: /* Internal cleaners */ void clear_gsb(); /* clean the content */ - void clear_cb_unique_module(t_rr_type cb_type); /* clean the content */ - void clear_cb_unique_module_id(t_rr_type cb_type); /* clean the content */ + void clear_cb_unique_module(const t_rr_type& cb_type); /* clean the content */ + void clear_cb_unique_module_id(const t_rr_type& cb_type); /* clean the content */ void clear_sb_unique_module(); /* clean the content */ void clear_sb_unique_module_id(); /* clean the content */ - void clear_sb_unique_submodule(); /* clean the content */ - void clear_sb_unique_submodule_id(); /* clean the content */ void clear_gsb_unique_module(); /* clean the content */ void clear_gsb_unique_module_id(); /* clean the content */ - void clear_segment_ids(); private: /* Validators */ - bool validate_coordinator(const DeviceCoordinator& coordinator) const; /* Validate if the (x,y) is the range of this device */ - bool validate_coordinator_edge(DeviceCoordinator& coordinator) const; /* Validate if the (x,y) is the range of this device but takes into consideration the fact that edges are 1 off */ - bool validate_side(enum e_side side) const; /* validate if side is in the range of unique_side_module_ */ - bool validate_sb_unique_module_index(size_t index) const; /* Validate if the index in the range of unique_mirror vector*/ - bool validate_cb_unique_module_index(t_rr_type cb_type, size_t index) const; /* Validate if the index in the range of unique_mirror vector*/ - bool validate_sb_unique_submodule_index(size_t index, enum e_side side, size_t seg_index) const; /* Validate if the index in the range of unique_module vector */ - bool validate_segment_index(size_t index) const; - bool validate_cb_type(t_rr_type cb_type) const; + bool validate_coordinate(const vtr::Point& coordinate) const; /* Validate if the (x,y) is the range of this device */ + bool validate_side(const e_side& side) const; /* validate if side is in the range of unique_side_module_ */ + bool validate_sb_unique_module_index(const size_t& index) const; /* Validate if the index in the range of unique_mirror vector*/ + bool validate_cb_unique_module_index(const t_rr_type& cb_type, const size_t& index) const; /* Validate if the index in the range of unique_mirror vector*/ + bool validate_cb_type(const t_rr_type& cb_type) const; private: /* Internal builders */ - void build_segment_ids(); /* build a map of segment_ids */ - void add_gsb_unique_module(const DeviceCoordinator& coordinator); - void add_sb_unique_side_submodule(DeviceCoordinator& coordinator, const RRGSB& rr_sb, enum e_side side); - void add_sb_unique_side_segment_submodule(DeviceCoordinator& coordinator, const RRGSB& rr_sb, enum e_side side, size_t seg_id); - void add_cb_unique_module(t_rr_type cb_type, const DeviceCoordinator& coordinator); - void set_cb_unique_module_id(t_rr_type, const DeviceCoordinator& coordinator, size_t id); - void build_sb_unique_submodule(); /* Add a switch block to the array, which will automatically identify and update the lists of unique side module */ - void build_sb_unique_module(); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ - void build_cb_unique_module(t_rr_type cb_type); /* Add a switch block to the array, which will automatically identify and update the lists of unique side module */ + void add_gsb_unique_module(const vtr::Point& coordinate); + void add_cb_unique_module(const t_rr_type& cb_type, const vtr::Point& coordinate); + void set_cb_unique_module_id(const t_rr_type& cb_type, const vtr::Point& coordinate, size_t id); + void build_sb_unique_module(const RRGraph& rr_graph); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ + void build_cb_unique_module(const RRGraph& rr_graph, const t_rr_type& cb_type); /* Add a switch block to the array, which will automatically identify and update the lists of unique side module */ void build_gsb_unique_module(); /* Add a switch block to the array, which will automatically identify and update the lists of unique mirrors and rotatable mirrors */ private: /* Internal Data */ - std::vector< std::vector > rr_gsb_; + std::vector> rr_gsb_; - std::vector< std::vector > gsb_unique_module_id_; /* A map from rr_gsb to its unique mirror */ - std::vector gsb_unique_module_; + std::vector> gsb_unique_module_id_; /* A map from rr_gsb to its unique mirror */ + std::vector> gsb_unique_module_; - std::vector< std::vector > sb_unique_module_id_; /* A map from rr_gsb to its unique mirror */ - std::vector sb_unique_module_; + std::vector> sb_unique_module_id_; /* A map from rr_gsb to its unique mirror */ + std::vector> sb_unique_module_; - std::vector< std::vector< std::vector< std::vector > > > sb_unique_submodule_id_; /* A map from rr_switch_block to its unique_side_module [0..x][0..y][0..num_sides][num_seg-1]*/ - std::vector< std::vector > > sb_unique_submodule_; /* For each side of switch block, we identify a list of unique modules based on its connection. This is a matrix [0..num_sides-1][0..num_seg-1][0..num_module], num_sides will the max number of sides of all the rr_switch_blocks */ + std::vector> cbx_unique_module_id_; /* A map from rr_gsb to its unique mirror */ + std::vector> cbx_unique_module_; /* For each side of connection block, we identify a list of unique modules based on its connection. This is a matrix [0..num_module] */ - std::vector< std::vector > cbx_unique_module_id_; /* A map from rr_gsb to its unique mirror */ - std::vector cbx_unique_module_; /* For each side of connection block, we identify a list of unique modules based on its connection. This is a matrix [0..num_module] */ - - std::vector< std::vector > cby_unique_module_id_; /* A map from rr_gsb to its unique mirror */ - std::vector cby_unique_module_; /* For each side of connection block, we identify a list of unique modules based on its connection. This is a matrix [0..num_module] */ - - std::vector segment_ids_; + std::vector> cby_unique_module_id_; /* A map from rr_gsb to its unique mirror */ + std::vector> cby_unique_module_; /* For each side of connection block, we identify a list of unique modules based on its connection. This is a matrix [0..num_module] */ }; } /* End namespace openfpga*/ diff --git a/openfpga/src/annotation/rr_chan.cpp b/openfpga/src/annotation/rr_chan.cpp index 84540758e..b85d1b917 100644 --- a/openfpga/src/annotation/rr_chan.cpp +++ b/openfpga/src/annotation/rr_chan.cpp @@ -24,7 +24,9 @@ RRChan::RRChan() { node_segments_.resize(0); } -/* Accessors */ +/************************************************************************ + * Accessors + ***********************************************************************/ t_rr_type RRChan::get_type() const { return type_; } @@ -142,7 +144,9 @@ std::vector RRChan::get_node_ids_by_segment_ids(const RRSegmentId& seg return node_list; } -/* Mutators */ +/************************************************************************ + * Mutators + ***********************************************************************/ void RRChan::set(const RRChan& rr_chan) { /* Ensure a clean start */ this->clear(); @@ -186,7 +190,7 @@ void RRChan::clear() { } /************************************************************************ - * Internal functions + * Internal validators ***********************************************************************/ /* for type, only valid type is CHANX and CHANY */ bool RRChan::valid_type(const t_rr_type& type) const { diff --git a/openfpga/src/annotation/rr_gsb.cpp b/openfpga/src/annotation/rr_gsb.cpp index 54b9fa8f2..6b8cd5236 100644 --- a/openfpga/src/annotation/rr_gsb.cpp +++ b/openfpga/src/annotation/rr_gsb.cpp @@ -661,8 +661,10 @@ vtr::Point RRGSB::get_grid_coordinate() const { return ret; } -/* Public mutators */ +/************************************************************************ + * Public Mutators + ***********************************************************************/ /* get a copy from a source */ void RRGSB::set(const RRGSB& src) { /* Copy coordinate */ @@ -740,6 +742,9 @@ void RRGSB::add_opin_node(const RRNodeId& node, const e_side& node_side) { opin_node_[size_t(node_side)].push_back(node); } +/************************************************************************ + * Public Mutators: clean-up functions + ***********************************************************************/ /* Reset the RRGSB to pristine state */ void RRGSB::clear() { /* Clean all the vectors */ @@ -786,7 +791,9 @@ void RRGSB::clear_one_side(const e_side& node_side) { clear_opin_nodes(node_side); } -/* Internal functions for validation */ +/************************************************************************ + * Internal Accessors: identify mirrors + ***********************************************************************/ /* check if two rr_nodes have a similar set of drive_rr_nodes * for each drive_rr_node: @@ -944,6 +951,10 @@ size_t RRGSB::get_track_id_first_short_connection(const RRGraph& rr_graph, const return size_t(-1); } + +/************************************************************************ + * Internal validators + ***********************************************************************/ /* Validate if the number of sides are consistent among internal data arrays ! */ bool RRGSB::validate_num_sides() const { size_t num_sides = chan_node_direction_.size();