|
| 1 | +#include "connection_box.h" |
| 2 | +#include "vtr_assert.h" |
| 3 | +#include "globals.h" |
| 4 | + |
| 5 | +ConnectionBoxes::ConnectionBoxes() |
| 6 | + : size_(std::make_pair(0, 0)) { |
| 7 | +} |
| 8 | + |
| 9 | +size_t ConnectionBoxes::num_connection_box_types() const { |
| 10 | + return boxes_.size(); |
| 11 | +} |
| 12 | + |
| 13 | +std::pair<size_t, size_t> ConnectionBoxes::connection_box_grid_size() const { |
| 14 | + return size_; |
| 15 | +} |
| 16 | + |
| 17 | +const ConnectionBox* ConnectionBoxes::get_connection_box(ConnectionBoxId box) const { |
| 18 | + if (bool(box)) { |
| 19 | + return nullptr; |
| 20 | + } |
| 21 | + |
| 22 | + size_t index = size_t(box); |
| 23 | + if (index >= boxes_.size()) { |
| 24 | + return nullptr; |
| 25 | + } |
| 26 | + |
| 27 | + return &boxes_.at(index); |
| 28 | +} |
| 29 | + |
| 30 | +bool ConnectionBoxes::find_connection_box(int inode, |
| 31 | + ConnectionBoxId* box_id, |
| 32 | + std::pair<size_t, size_t>* box_location) const { |
| 33 | + VTR_ASSERT(box_id != nullptr); |
| 34 | + VTR_ASSERT(box_location != nullptr); |
| 35 | + |
| 36 | + const auto& conn_box_loc = ipin_map_[inode]; |
| 37 | + if (conn_box_loc.box_id == ConnectionBoxId::INVALID()) { |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + *box_id = conn_box_loc.box_id; |
| 42 | + *box_location = conn_box_loc.box_location; |
| 43 | + return true; |
| 44 | +} |
| 45 | + |
| 46 | +// Clear IPIN map and set connection box grid size and box ids. |
| 47 | +void ConnectionBoxes::reset_boxes(std::pair<size_t, size_t> size, |
| 48 | + const std::vector<ConnectionBox> boxes) { |
| 49 | + clear(); |
| 50 | + |
| 51 | + size_ = size; |
| 52 | + boxes_ = boxes; |
| 53 | +} |
| 54 | + |
| 55 | +void ConnectionBoxes::resize_nodes(size_t rr_node_size) { |
| 56 | + ipin_map_.resize(rr_node_size); |
| 57 | + canonical_loc_map_.resize(rr_node_size, |
| 58 | + std::make_pair(-1, -1)); |
| 59 | +} |
| 60 | + |
| 61 | +void ConnectionBoxes::clear() { |
| 62 | + ipin_map_.clear(); |
| 63 | + size_ = std::make_pair(0, 0); |
| 64 | + boxes_.clear(); |
| 65 | + canonical_loc_map_.clear(); |
| 66 | + sink_to_ipin_.clear(); |
| 67 | +} |
| 68 | + |
| 69 | +void ConnectionBoxes::add_connection_box(int inode, ConnectionBoxId box_id, std::pair<size_t, size_t> box_location) { |
| 70 | + // Ensure that box location is in bounds |
| 71 | + VTR_ASSERT(box_location.first < size_.first); |
| 72 | + VTR_ASSERT(box_location.second < size_.second); |
| 73 | + |
| 74 | + // Bounds check box_id |
| 75 | + VTR_ASSERT(bool(box_id)); |
| 76 | + VTR_ASSERT(size_t(box_id) < boxes_.size()); |
| 77 | + |
| 78 | + // Make sure sink map will not be invalidated upon insertion. |
| 79 | + VTR_ASSERT(sink_to_ipin_.size() == 0); |
| 80 | + |
| 81 | + ipin_map_[inode] = ConnBoxLoc(box_location, box_id); |
| 82 | +} |
| 83 | + |
| 84 | +void ConnectionBoxes::add_canonical_loc(int inode, std::pair<size_t, size_t> loc) { |
| 85 | + VTR_ASSERT(loc.first < size_.first); |
| 86 | + VTR_ASSERT(loc.second < size_.second); |
| 87 | + canonical_loc_map_[inode] = loc; |
| 88 | +} |
| 89 | + |
| 90 | +const std::pair<size_t, size_t>* ConnectionBoxes::find_canonical_loc(int inode) const { |
| 91 | + const auto& canon_loc = canonical_loc_map_[inode]; |
| 92 | + if (canon_loc.first == size_t(-1)) { |
| 93 | + return nullptr; |
| 94 | + } |
| 95 | + |
| 96 | + return &canon_loc; |
| 97 | +} |
| 98 | + |
| 99 | +void ConnectionBoxes::create_sink_back_ref() { |
| 100 | + const auto& device_ctx = g_vpr_ctx.device(); |
| 101 | + |
| 102 | + sink_to_ipin_.resize(device_ctx.rr_nodes.size(), {{0, 0, 0, 0}, 0}); |
| 103 | + |
| 104 | + for (size_t i = 0; i < device_ctx.rr_nodes.size(); ++i) { |
| 105 | + const auto& ipin_node = device_ctx.rr_nodes[i]; |
| 106 | + if (ipin_node.type() != IPIN) { |
| 107 | + continue; |
| 108 | + } |
| 109 | + |
| 110 | + if (ipin_map_[i].box_id == ConnectionBoxId::INVALID()) { |
| 111 | + continue; |
| 112 | + } |
| 113 | + |
| 114 | + for (auto edge : ipin_node.edges()) { |
| 115 | + int sink_inode = ipin_node.edge_sink_node(edge); |
| 116 | + VTR_ASSERT(device_ctx.rr_nodes[sink_inode].type() == SINK); |
| 117 | + VTR_ASSERT(sink_to_ipin_[sink_inode].ipin_count < 4); |
| 118 | + auto& sink_to_ipin = sink_to_ipin_[sink_inode]; |
| 119 | + sink_to_ipin.ipin_nodes[sink_to_ipin.ipin_count++] = i; |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +const SinkToIpin& ConnectionBoxes::find_sink_connection_boxes( |
| 125 | + int inode) const { |
| 126 | + return sink_to_ipin_[inode]; |
| 127 | +} |
0 commit comments