Skip to content

[Place] Moved PlaceMacros Out of BlkLocRegistry #2896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 21 additions & 9 deletions vpr/src/analytical_place/full_legalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ class APClusterPlacer {
private:
// Get the macro for the given cluster block.
t_pl_macro get_macro(ClusterBlockId clb_blk_id) {
const auto& place_macros = g_vpr_ctx.placement().blk_loc_registry().place_macros();
// Basically stolen from initial_placement.cpp:place_one_block
// TODO: Make this a cleaner interface and share the code.
int imacro = place_macros.get_imacro_from_iblk(clb_blk_id);
int imacro = place_macros_.get_imacro_from_iblk(clb_blk_id);

// If this block is part of a macro, return it.
if (imacro != -1) {
return place_macros[imacro];
return place_macros_[imacro];
}
// If not, create a "fake" macro with a single element.
t_pl_macro_member macro_member;
Expand All @@ -121,20 +120,22 @@ class APClusterPlacer {
return pl_macro;
}

const PlaceMacros& place_macros_;

public:
/**
* @brief Constructor for the APClusterPlacer
*
* Initializes internal and global state necessary to place clusters on the
* FPGA device.
*/
APClusterPlacer() {
APClusterPlacer(const PlaceMacros& place_macros)
: place_macros_(place_macros) {
// FIXME: This was stolen from place/place.cpp
// it used a static method, just taking what I think I will need.
auto& blk_loc_registry = g_vpr_ctx.mutable_placement().mutable_blk_loc_registry();
const auto& directs = g_vpr_ctx.device().arch->directs;

init_placement_context(blk_loc_registry, directs);
init_placement_context(blk_loc_registry);

// stolen from place/place.cpp:alloc_and_load_try_swap_structs
// FIXME: set cube_bb to false by hand, should be passed in.
Expand All @@ -149,7 +150,7 @@ class APClusterPlacer {
blk_loc_registry.clear_all_grid_locs();

// Deal with the placement constraints.
propagate_place_constraints(blk_loc_registry.place_macros());
propagate_place_constraints(place_macros_);

mark_fixed_blocks(blk_loc_registry);

Expand Down Expand Up @@ -384,6 +385,7 @@ void NaiveFullLegalizer::create_clusters(const PartialPlacement& p_placement) {
}

void NaiveFullLegalizer::place_clusters(const ClusteredNetlist& clb_nlist,
const PlaceMacros& place_macros,
const PartialPlacement& p_placement) {
// PLACING:
// Create a lookup from the AtomBlockId to the APBlockId
Expand All @@ -405,7 +407,7 @@ void NaiveFullLegalizer::place_clusters(const ClusteredNetlist& clb_nlist,
// Move the clusters to where they want to be first.
// TODO: The fixed clusters should probably be moved first for legality
// reasons.
APClusterPlacer ap_cluster_placer;
APClusterPlacer ap_cluster_placer(place_macros);
std::vector<ClusterBlockId> unplaced_clusters;
for (ClusterBlockId cluster_blk_id : clb_nlist.blocks()) {
// Assume that the cluster will always want to be placed wherever the
Expand Down Expand Up @@ -466,8 +468,18 @@ void NaiveFullLegalizer::legalize(const PartialPlacement& p_placement) {
// TODO: Eventually should be returned from the create_clusters method.
const ClusteredNetlist& clb_nlist = g_vpr_ctx.clustering().clb_nlist;

// Alloc and load the placement macros.
VTR_ASSERT(!g_vpr_ctx.placement().place_macros);
g_vpr_ctx.mutable_placement().place_macros = std::make_unique<PlaceMacros>(g_vpr_ctx.device().arch->directs,
g_vpr_ctx.device().physical_tile_types,
g_vpr_ctx.clustering().clb_nlist,
g_vpr_ctx.atom().nlist,
g_vpr_ctx.atom().lookup);

const PlaceMacros& place_macros = *g_vpr_ctx.placement().place_macros;

// Place the clusters based on where the atoms want to be placed.
place_clusters(clb_nlist, p_placement);
place_clusters(clb_nlist, place_macros, p_placement);

// Verify that the placement created by the full legalizer is valid.
unsigned num_placement_errors = verify_placement(g_vpr_ctx);
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/analytical_place/full_legalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AtomNetlist;
class ClusteredNetlist;
class DeviceGrid;
class PartialPlacement;
class PlaceMacros;
class Prepacker;
struct t_arch;
struct t_logical_block_type;
Expand Down Expand Up @@ -125,6 +126,7 @@ class NaiveFullLegalizer : public FullLegalizer {
* placement.
*/
void place_clusters(const ClusteredNetlist& clb_nlist,
const PlaceMacros& place_macros,
const PartialPlacement& p_placement);

};
Expand Down
9 changes: 1 addition & 8 deletions vpr/src/base/blk_loc_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net
return this->tile_pin_index(pin_id);
}

const PlaceMacros& BlkLocRegistry::place_macros() const {
return place_macros_;
}

PlaceMacros& BlkLocRegistry::mutable_place_macros() {
return place_macros_;
}

void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& location) {
const auto& device_ctx = g_vpr_ctx.device();
const auto& cluster_ctx = g_vpr_ctx.clustering();
Expand Down Expand Up @@ -289,3 +281,4 @@ t_physical_tile_loc BlkLocRegistry::get_coordinate_of_pin(ClusterPinId pin) cons

return tile_loc;
}

15 changes: 1 addition & 14 deletions vpr/src/base/blk_loc_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "vtr_vector_map.h"
#include "vpr_types.h"
#include "grid_block.h"
#include "place_macro.h"

struct t_block_loc;
struct t_pl_blocks_to_be_moved;
Expand Down Expand Up @@ -37,13 +36,6 @@ class BlkLocRegistry {
///@brief Clustered pin placement mapping with physical pin
vtr::vector_map<ClusterPinId, int> physical_pins_;

/**
* @brief Contains information about placement macros.
* A placement macro is a set of clustered blocks that must be placed
* in a way that is compliant with relative locations specified by the macro.
*/
PlaceMacros place_macros_;

/// @brief Stores ClusterBlockId of all movable clustered blocks
/// (blocks that are not locked down to a single location)
std::vector<ClusterBlockId> movable_blocks_;
Expand All @@ -67,12 +59,6 @@ class BlkLocRegistry {
///@brief Returns the physical pin of the tile, related to the given ClusterNedId, and the net pin index.
int net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const;

///@brief Returns a constant reference to placement macros.
const PlaceMacros& place_macros() const;

///@brief Returns a mutable reference to placement macros.
PlaceMacros& mutable_place_macros();

/// @brief Returns a constant reference to the vector of ClusterBlockIds of all movable clustered blocks.
const std::vector<ClusterBlockId>& movable_blocks() const { return movable_blocks_; }

Expand Down Expand Up @@ -170,3 +156,4 @@ class BlkLocRegistry {

e_expected_transaction expected_transaction_;
};

1 change: 1 addition & 0 deletions vpr/src/base/place_and_route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <algorithm>

#include "FlatPlacementInfo.h"
#include "place_macro.h"
#include "vtr_assert.h"
#include "vtr_log.h"

Expand Down
26 changes: 21 additions & 5 deletions vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
#include <cstdio>
#include <cstring>
#include <cmath>
#include <memory>
#include <vector>

#include "FlatPlacementInfo.h"
#include "cluster_util.h"
#include "physical_types.h"
#include "place_macro.h"
#include "verify_placement.h"
#include "vpr_context.h"
#include "vtr_assert.h"
Expand Down Expand Up @@ -741,7 +745,9 @@ bool vpr_load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
return true;
}

bool vpr_place_flow(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_arch& arch) {
bool vpr_place_flow(const Netlist<>& net_list,
t_vpr_setup& vpr_setup,
const t_arch& arch) {
VTR_LOG("\n");
const auto& placer_opts = vpr_setup.PlacerOpts;
const auto& filename_opts = vpr_setup.FileNameOpts;
Expand All @@ -756,7 +762,7 @@ bool vpr_place_flow(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_a
VTR_ASSERT(placer_opts.doPlacement == STAGE_LOAD);

//Load a previous placement
vpr_load_placement(vpr_setup, arch);
vpr_load_placement(vpr_setup, arch.directs);
}

post_place_sync();
Expand All @@ -781,7 +787,9 @@ bool vpr_place_flow(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_a
return true;
}

void vpr_place(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_arch& arch) {
void vpr_place(const Netlist<>& net_list,
t_vpr_setup& vpr_setup,
const t_arch& arch) {
bool is_flat = false;
if (vpr_setup.PlacerOpts.place_algorithm.is_timing_driven()) {
// Prime lookahead cache to avoid adding lookahead computation cost to
Expand Down Expand Up @@ -828,7 +836,8 @@ void vpr_place(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_arch&
block_locs);
}

void vpr_load_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
void vpr_load_placement(t_vpr_setup& vpr_setup,
const std::vector<t_direct_inf> directs) {
vtr::ScopedStartFinishTimer timer("Load Placement");

const auto& device_ctx = g_vpr_ctx.device();
Expand All @@ -837,7 +846,14 @@ void vpr_load_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
const auto& filename_opts = vpr_setup.FileNameOpts;

//Initialize placement data structures, which will be filled when loading placement
init_placement_context(blk_loc_registry, arch.directs);
init_placement_context(blk_loc_registry);

// Alloc and load the placement macros.
place_ctx.place_macros = std::make_unique<PlaceMacros>(directs,
device_ctx.physical_tile_types,
g_vpr_ctx.clustering().clb_nlist,
g_vpr_ctx.atom().nlist,
g_vpr_ctx.atom().lookup);

//Load an existing placement from a file
place_ctx.placement_id = read_place(filename_opts.NetFile.c_str(), filename_opts.PlaceFile.c_str(),
Expand Down
11 changes: 8 additions & 3 deletions vpr/src/base/vpr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ bool vpr_load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch);
/* Placement */

///@brief Perform, load or skip the placement stage
bool vpr_place_flow(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_arch& arch);
bool vpr_place_flow(const Netlist<>& net_list,
t_vpr_setup& vpr_setup,
const t_arch& arch);

///@brief Perform placement
void vpr_place(const Netlist<>& net_list, t_vpr_setup& vpr_setup, const t_arch& arch);
void vpr_place(const Netlist<>& net_list,
t_vpr_setup& vpr_setup,
const t_arch& arch);

///@brief Loads a previous placement
void vpr_load_placement(t_vpr_setup& vpr_setup, const t_arch& arch);
void vpr_load_placement(t_vpr_setup& vpr_setup,
const std::vector<t_direct_inf> directs);

/* Routing */

Expand Down
11 changes: 11 additions & 0 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mutex>

#include "FlatPlacementInfo.h"
#include "place_macro.h"
#include "user_place_constraints.h"
#include "user_route_constraints.h"
#include "vpr_types.h"
Expand Down Expand Up @@ -362,6 +363,16 @@ struct PlacementContext : public Context {
*/
void unlock_loc_vars() { VTR_ASSERT_SAFE(!loc_vars_are_accessible_); loc_vars_are_accessible_ = true; }

/**
* @brief Collection of all the placement macros in the netlist. A placement
* macro is a set of clustered blocks that must be placed in a way
* that is compliant with relative locations specified by the macro.
* Macros are used during placement and are not modified after they
* are created.
* This is created at the start of placement.
*/
std::unique_ptr<PlaceMacros> place_macros;

/**
* @brief Compressed grid space for each block type
*
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ void init_draw_coords(float clb_width, const BlkLocRegistry& blk_loc_registry) {
draw_state->draw_rr_node[inode].node_highlighted = false;
}
}
draw_coords->tile_width = clb_width;
draw_coords->set_tile_width(clb_width);
draw_coords->pin_size = 0.3;
for (const auto& type : device_ctx.physical_tile_types) {
auto num_pins = type.num_pins;
Expand Down
4 changes: 3 additions & 1 deletion vpr/src/draw/draw_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,9 @@ void draw_placement_macros(ezgl::renderer* g) {
t_draw_coords* draw_coords = get_draw_coords_vars();

const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
const auto& place_macros = draw_state->get_graphics_blk_loc_registry_ref().place_macros();

VTR_ASSERT(g_vpr_ctx.placement().place_macros);
const PlaceMacros& place_macros = *g_vpr_ctx.placement().place_macros;

for (const t_pl_macro& pl_macro : place_macros.macros()) {

Expand Down
5 changes: 5 additions & 0 deletions vpr/src/draw/draw_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ struct t_draw_coords {
///@brief constructor
t_draw_coords();

///@brief Sets the tile width
inline void set_tile_width(float new_tile_width) {
tile_width = new_tile_width;
}

///@brief returns tile width
float get_tile_width();

Expand Down
4 changes: 3 additions & 1 deletion vpr/src/draw/manual_moves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "draw_searchbar.h"
#include "buttons.h"
#include "physical_types_util.h"
#include "place_macro.h"

#ifndef NO_GRAPHICS

Expand Down Expand Up @@ -319,13 +320,14 @@ e_create_move manual_move_display_and_propose(ManualMoveGenerator& manual_move_g
t_pl_blocks_to_be_moved& blocks_affected,
e_move_type& move_type,
float rlim,
const PlaceMacros& place_macros,
const t_placer_opts& placer_opts,
const PlacerCriticalities* criticalities) {
draw_manual_moves_window("");
update_screen(ScreenUpdatePriority::MAJOR, " ", PLACEMENT, nullptr);
move_type = e_move_type::MANUAL_MOVE;
t_propose_action proposed_action{move_type, -1}; //no need to specify block type in manual move "propose_move" function
return manual_move_generator.propose_move(blocks_affected, proposed_action, rlim, placer_opts, criticalities);
return manual_move_generator.propose_move(blocks_affected, proposed_action, rlim, place_macros, placer_opts, criticalities);
}

#endif /*NO_GRAPHICS*/
3 changes: 3 additions & 0 deletions vpr/src/draw/manual_moves.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# include <algorithm>
# include <iostream>

class PlaceMacros;

/**
* @brief ManualMovesInfo struct
*
Expand Down Expand Up @@ -160,6 +162,7 @@ e_create_move manual_move_display_and_propose(ManualMoveGenerator& manual_move_g
t_pl_blocks_to_be_moved& blocks_affected,
e_move_type& move_type,
float rlim,
const PlaceMacros& place_macros,
const t_placer_opts& placer_opts,
const PlacerCriticalities* criticalities);

Expand Down
5 changes: 2 additions & 3 deletions vpr/src/place/RL_agent_util.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "RL_agent_util.h"

#include "simpleRL_move_generator.h"
#include "static_move_generator.h"
#include "manual_move_generator.h"
#include "placer_state.h"


std::pair<std::unique_ptr<MoveGenerator>, std::unique_ptr<MoveGenerator>> create_move_generators(PlacerState& placer_state,
const t_placer_opts& placer_opts,
int move_lim,
Expand Down Expand Up @@ -165,4 +164,4 @@ MoveGenerator& select_move_generator(std::unique_ptr<MoveGenerator>& move_genera
else
return *move_generator2;
}
}
}
Loading