Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 65 additions & 4 deletions libs/libarchfpga/src/device_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ class DeviceGrid {
const std::string& name() const { return name_; }

///@brief Return the number of layers(number of dies)
inline int get_num_layers() const {
return (int)grid_.dim_size(0);
inline size_t get_num_layers() const {
return grid_.dim_size(0);
}

///@brief Return the width of the grid at the specified layer
size_t width() const { return grid_.dim_size(1); }
///@brief Return the height of the grid at the specified layer
Expand All @@ -54,7 +53,8 @@ class DeviceGrid {
void clear();

/**
* @brief Return the number of instances of the specified tile type on the specified layer. If the layer_num is -1, return the total number of instances of the specified tile type on all layers.
* @brief Return the number of instances of the specified tile type on the specified layer.
* If the layer_num is -1, return the total number of instances of the specified tile type on all layers.
* @note This function should be used if count_instances() is called in the constructor.
*/
size_t num_instances(t_physical_tile_type_ptr type, int layer_num) const;
Expand Down Expand Up @@ -84,6 +84,15 @@ class DeviceGrid {
return get_width_offset(tile_loc) == 0 && get_height_offset(tile_loc) == 0;
}

///@brief Given a location, return the root location (bottom-left corner) of the tile instance
inline t_physical_tile_loc get_root_location(const t_physical_tile_loc& tile_loc) const {
t_physical_tile_loc root_loc;
root_loc.layer_num = tile_loc.layer_num;
root_loc.x = tile_loc.x - get_width_offset(tile_loc);
root_loc.y = tile_loc.y - get_height_offset(tile_loc);
return root_loc;
}

///@brief Returns a rectangle which represents the bounding box of the tile at the given location.
inline vtr::Rect<int> get_tile_bb(const t_physical_tile_loc& tile_loc) const {
t_physical_tile_type_ptr tile_type = get_physical_type(tile_loc);
Expand All @@ -96,6 +105,58 @@ class DeviceGrid {
return {{tile_xlow, tile_ylow}, {tile_xhigh, tile_yhigh}};
}

// Forward const-iterator over (layer, x, y)
class loc_const_iterator {
public:
using value_type = t_physical_tile_loc;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;

loc_const_iterator(const DeviceGrid* g, size_t layer, size_t x, size_t y)
: g_(g) {
loc_.layer_num = static_cast<int>(layer);
loc_.x = static_cast<int>(x);
loc_.y = static_cast<int>(y);
}

value_type operator*() const { return loc_; }

// pre-increment
loc_const_iterator& operator++() {
// advance y, then x, then layer
++loc_.y;
if (loc_.y >= static_cast<int>(g_->height())) {
loc_.y = 0;
++loc_.x;
if (loc_.x >= static_cast<int>(g_->width())) {
loc_.x = 0;
++loc_.layer_num;
}
}
return *this;
}

bool operator==(const loc_const_iterator& o) const {
return loc_.x == o.loc_.x
&& loc_.y == o.loc_.y
&& loc_.layer_num == o.loc_.layer_num
&& g_ == o.g_;
}
bool operator!=(const loc_const_iterator& o) const { return !(*this == o); }

private:
const DeviceGrid* g_ = nullptr;
t_physical_tile_loc loc_{0, 0, 0};
};

/// Iterate every (layer, x, y) location
inline auto all_locations() const {
return vtr::make_range(
loc_const_iterator(this, /*layer*/ 0, /*x*/ 0, /*y*/ 0),
loc_const_iterator(this, /*layer*/ get_num_layers(), /*x*/ 0, /*y*/ 0) // end sentinel
);
}

///@brief Return the metadata of the tile at the specified location
inline const t_metadata_dict* get_metadata(const t_physical_tile_loc& tile_loc) const {
return grid_[tile_loc.layer_num][tile_loc.x][tile_loc.y].meta;
Expand Down
29 changes: 10 additions & 19 deletions libs/libarchfpga/src/physical_types_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ static std::vector<int> get_pb_pin_src_pins(t_physical_tile_type_ptr physical_ty
const t_pb_graph_pin* pin);

/**
*
* @param physical_type physical tile which pin belongs to
* @param sub_tile sub_tile in which physical tile located
* @param logical_block logical block mapped to the sub_tile
Expand Down Expand Up @@ -108,20 +107,12 @@ static t_pb_graph_pin* get_mutable_tile_pin_pb_pin(t_physical_tile_type* physica
int pin_physical_num);

/**
*
* @param physical_tile
* @param class_physical_num
* @return A vector containing all of the parent pb_graph_nodes and the pb_graph_node of the class_physical_num itself
*/
static std::vector<const t_pb_graph_node*> get_sink_hierarchical_parents(t_physical_tile_type_ptr physical_tile,
int class_physical_num);

/**
*
* @param physical_tile
* @param pin_physcial_num
* @param ref_sink_num
* @param sink_grp
* @return Return zero if the ref_sink_num is not reachable by pin_physical_num, otherwise return the number sinks in sink_grp
* reachable by pin_physical_num
*/
Expand Down Expand Up @@ -618,21 +609,21 @@ bool is_opin(int ipin, t_physical_tile_type_ptr type) {
return false;
}

bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, int num_of_avail_layer) {
if (type->is_empty()) { //if type is empty, there is no pins
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, unsigned num_of_avail_layer) {
// if type is empty, there is no pins
if (type->is_empty()) {
return false;
}
//ipin should be a valid pin in physical type

// ipin should be a valid pin in physical type
VTR_ASSERT(ipin < type->num_pins);
int pin_layer = from_layer + type->pin_layer_offset[ipin];
//if pin_offset specifies a layer that doesn't exist in arch file, we do a wrap around
unsigned pin_layer = from_layer + type->pin_layer_offset[ipin];
// if pin_offset specifies a layer that doesn't exist in arch file, we do a wrap around
pin_layer = (pin_layer < num_of_avail_layer) ? pin_layer : pin_layer % num_of_avail_layer;
if (from_layer == to_layer || pin_layer == to_layer) {
if (from_layer == to_layer || int(pin_layer) == to_layer) {
return true;
} else {
return false;
}
//not reachable

return false;
}

Expand All @@ -643,7 +634,7 @@ std::string block_type_pin_index_to_name(t_physical_tile_type_ptr type, int pin_
std::string pin_name = type->name;

int sub_tile_index, inst_num, logical_num, pb_type_idx;
std::tie<int, int, int, int, int>(pin_index, sub_tile_index, inst_num, logical_num, pb_type_idx) = get_pin_index_for_inst(type, pin_physical_num, is_flat);
std::tie(pin_index, sub_tile_index, inst_num, logical_num, pb_type_idx) = get_pin_index_for_inst(type, pin_physical_num, is_flat);
if (type->sub_tiles[sub_tile_index].capacity.total() > 1) {
pin_name += "[" + std::to_string(inst_num) + "]";
}
Expand Down
2 changes: 1 addition & 1 deletion libs/libarchfpga/src/physical_types_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
bool is_opin(int ipin, t_physical_tile_type_ptr type);

///@brief Returns true if the specified pin is located at "from_layer" and it is connected to "to_layer"
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, int num_of_avail_layer);
bool is_pin_conencted_to_layer(t_physical_tile_type_ptr type, int ipin, int from_layer, int to_layer, unsigned num_of_avail_layer);

/**
* @brief Returns the corresponding physical pin based on the input parameters:
Expand Down
6 changes: 3 additions & 3 deletions libs/libvtrutil/src/vtr_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ResultTy median(Container c) {
///@brief Returns the median of a whole container, assuming that it is already
/// sorted.
template<typename ResultTy = double, typename Container>
ResultTy median_presorted(const Container &c) {
ResultTy median_presorted(const Container& c) {
return median_presorted<ResultTy>(std::begin(c), std::end(c));
}

Expand Down Expand Up @@ -116,7 +116,7 @@ double geomean(const InputIterator first, const InputIterator last, double init

///@brief Returns the geometric mean of a whole container
template<typename Container>
double geomean(const Container &c) {
double geomean(const Container& c) {
return geomean(std::begin(c), std::end(c));
}

Expand All @@ -139,7 +139,7 @@ double arithmean(const InputIterator first, const InputIterator last, double ini

///@brief Returns the aritmatic mean of a whole container
template<typename Container>
double arithmean(const Container &c) {
double arithmean(const Container& c) {
return arithmean(std::begin(c), std::end(c));
}

Expand Down
6 changes: 3 additions & 3 deletions vpr/src/analytical_place/analytical_placement_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
} else {
if (current_loc_x != -1 && current_loc_y != -1) {
atom_loc_x = std::clamp(current_loc_x, 0.0f,
static_cast<float>(g_vpr_ctx.device().grid.width() -1));
static_cast<float>(g_vpr_ctx.device().grid.width() - 1));
atom_loc_y = std::clamp(current_loc_y, 0.0f,
static_cast<float>(g_vpr_ctx.device().grid.height() -1));
static_cast<float>(g_vpr_ctx.device().grid.height() - 1));
// If current_loc_layer or current_loc_sub_tile are unset (-1), default to layer 0 and sub_tile 0.
if (current_loc_layer == -1)
current_loc_layer = 0;
Expand Down Expand Up @@ -155,7 +155,7 @@ static void convert_flat_to_partial_placement(const FlatPlacementInfo& flat_plac
}
}
VTR_LOG("%zu of %zu molecules placed at device center (no atoms of these molecules found in flat placement).\n",
num_mols_assigned_to_center, ap_netlist.blocks().size());
num_mols_assigned_to_center, ap_netlist.blocks().size());
}

/**
Expand Down
Loading