Skip to content
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

[AP] Added AP Flow to VPR #2746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion libs/libvtrutil/src/vpr_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ enum e_vpr_error {
VPR_ERROR_ARCH,
VPR_ERROR_PACK,
VPR_ERROR_PLACE,
VPR_ERROR_AP,
VPR_ERROR_ROUTE,
VPR_ERROR_TIMING,
VPR_ERROR_POWER,
VPR_ERROR_SDC,

// File parsing errors
VPR_ERROR_NET_F, // Error while parsing the packed netlist file
VPR_ERROR_PLACE_F, // Error while parsning the placement file
VPR_ERROR_PLACE_F, // Error while parsing the placement file
VPR_ERROR_BLIF_F, // Error while parsing the blif file
VPR_ERROR_IC_NETLIST_F, // Error while parsing the interchange netlist file

Expand Down
9 changes: 5 additions & 4 deletions utils/fasm/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ int main(int argc, const char **argv) {
/* Read options, architecture, and circuit netlist */
vpr_init(argc, argv, &Options, &vpr_setup, &Arch);

vpr_setup.PackerOpts.doPacking = STAGE_LOAD;
vpr_setup.PlacerOpts.doPlacement = STAGE_LOAD;
vpr_setup.RouterOpts.doRouting = STAGE_LOAD;
vpr_setup.PackerOpts.doPacking = STAGE_LOAD;
vpr_setup.PlacerOpts.doPlacement = STAGE_LOAD;
vpr_setup.APOpts.doAP = STAGE_SKIP;
vpr_setup.RouterOpts.doRouting = STAGE_LOAD;
vpr_setup.RouterOpts.read_rr_edge_metadata = true;
vpr_setup.AnalysisOpts.doAnalysis = STAGE_SKIP;
vpr_setup.AnalysisOpts.doAnalysis = STAGE_SKIP;

bool flow_succeeded = false;
flow_succeeded = vpr_flow(vpr_setup, Arch);
Expand Down
9 changes: 5 additions & 4 deletions utils/fasm/test/test_fasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ TEST_CASE("fasm_integration_test", "[fasm]") {
vpr_init(sizeof(argv)/sizeof(argv[0]), argv,
&options, &vpr_setup, &arch);

vpr_setup.PackerOpts.doPacking = STAGE_LOAD;
vpr_setup.PlacerOpts.doPlacement = STAGE_LOAD;
vpr_setup.RouterOpts.doRouting = STAGE_LOAD;
vpr_setup.PackerOpts.doPacking = STAGE_LOAD;
vpr_setup.PlacerOpts.doPlacement = STAGE_LOAD;
vpr_setup.APOpts.doAP = STAGE_SKIP;
vpr_setup.RouterOpts.doRouting = STAGE_LOAD;
vpr_setup.RouterOpts.read_rr_edge_metadata = true;
vpr_setup.AnalysisOpts.doAnalysis = STAGE_SKIP;
vpr_setup.AnalysisOpts.doAnalysis = STAGE_SKIP;

bool flow_succeeded = vpr_flow(vpr_setup, arch);
REQUIRE(flow_succeeded == true);
Expand Down
35 changes: 35 additions & 0 deletions vpr/src/analytical_place/analytical_placement_flow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file
* @author Alex Singer
* @date September 2024
* @brief Implementation of the Analytical Placement flow.
*/

#include "analytical_placement_flow.h"
#include "atom_netlist.h"
#include "globals.h"
#include "prepack.h"
#include "vpr_context.h"
#include "vpr_error.h"
#include "vpr_types.h"
#include "vtr_time.h"

void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
(void)vpr_setup;
// Start an overall timer for the Analytical Placement flow.
vtr::ScopedStartFinishTimer timer("Analytical Placement Flow");

// The global state used/modified by this flow.
const AtomNetlist& atom_nlist = g_vpr_ctx.atom().nlist;
const DeviceContext& device_ctx = g_vpr_ctx.device();

// Run the prepacker
Prepacker prepacker;
prepacker.init(atom_nlist, device_ctx.logical_block_types);

// AP is currently under-construction. Fail gracefully just in case this
// is somehow being called.
VPR_FATAL_ERROR(VPR_ERROR_AP,
"Analytical Placement flow not implemented yet");
}

19 changes: 19 additions & 0 deletions vpr/src/analytical_place/analytical_placement_flow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file
* @author Alex Singer
* @date September 2024
* @brief Methods for running the Analytical Placement flow.
*/

#pragma once

// Forward declarations
struct t_vpr_setup;

/**
* @brief Run the Analaytical Placement flow.
*
* @param vpr_setup The setup options provided by the user.
*/
void run_analytical_placement_flow(t_vpr_setup& vpr_setup);

23 changes: 23 additions & 0 deletions vpr/src/base/CheckSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

void CheckSetup(const t_packer_opts& PackerOpts,
const t_placer_opts& PlacerOpts,
const t_ap_opts& APOpts,
const t_router_opts& RouterOpts,
const t_server_opts& ServerOpts,
const t_det_routing_arch& RoutingArch,
Expand Down Expand Up @@ -72,6 +73,28 @@ void CheckSetup(const t_packer_opts& PackerOpts,
NUM_PL_MOVE_TYPES);
}

// Rules for doing Analytical Placement
if (APOpts.doAP) {
// Make sure that the --place option was not set.
if (PlacerOpts.doPlacement) {
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
"Cannot perform both analytical and non-analytical placement.\n");
}
// Make sure that the --pack option was not set.
if (PackerOpts.doPacking) {
VPR_FATAL_ERROR(VPR_ERROR_OTHER,
"Analytical placement should skip packing.\n");
}

// TODO: Should check that read_vpr_constraint_file is non-empty or
// check within analytical placement that the floorplanning has
// some fixed blocks somewhere. Maybe we can live without fixed
// blocks.

// FIXME: Should we enforce that the size of the device is fixed? Or is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device size isn't fixed in the constraints file; it's specified either in the arch file or can be specified on the command line.

// that defined in the constraints file?
}

if (RouterOpts.doRouting) {
if (!Timing.timing_analysis_enabled
&& (DEMAND_ONLY != RouterOpts.base_cost_type && DEMAND_ONLY_NORMALIZED_LENGTH != RouterOpts.base_cost_type)) {
Expand Down
1 change: 1 addition & 0 deletions vpr/src/base/CheckSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const int DYNAMIC_PORT_RANGE_MAX = 65535;

void CheckSetup(const t_packer_opts& PackerOpts,
const t_placer_opts& PlacerOpts,
const t_ap_opts& APOpts,
const t_router_opts& RouterOpts,
const t_server_opts& ServerOpts,
const t_det_routing_arch& RoutingArch,
Expand Down
9 changes: 9 additions & 0 deletions vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void SetupVPR(const t_options* Options,
t_netlist_opts* NetlistOpts,
t_packer_opts* PackerOpts,
t_placer_opts* PlacerOpts,
t_ap_opts* APOpts,
t_annealing_sched* AnnealSched,
t_router_opts* RouterOpts,
t_analysis_opts* AnalysisOpts,
Expand Down Expand Up @@ -244,11 +245,13 @@ void SetupVPR(const t_options* Options,
if (!Options->do_packing
&& !Options->do_legalize
&& !Options->do_placement
&& !Options->do_analytical_placement
&& !Options->do_routing
&& !Options->do_analysis) {
//run all stages if none specified
PackerOpts->doPacking = STAGE_DO;
PlacerOpts->doPlacement = STAGE_DO;
APOpts->doAP = STAGE_SKIP; // AP not default.
RouterOpts->doRouting = STAGE_DO;
AnalysisOpts->doAnalysis = STAGE_AUTO; //Deferred until implementation status known
} else {
Expand Down Expand Up @@ -276,6 +279,12 @@ void SetupVPR(const t_options* Options,
PlacerOpts->doPlacement = STAGE_DO;
}

if (Options->do_analytical_placement) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe comment why: analytical placement performs both packing & placement with an integrated algorithm.

PackerOpts->doPacking = STAGE_SKIP;
PlacerOpts->doPlacement = STAGE_SKIP;
APOpts->doAP = STAGE_DO;
}

if (Options->do_packing) {
PackerOpts->doPacking = STAGE_DO;
}
Expand Down
1 change: 1 addition & 0 deletions vpr/src/base/SetupVPR.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void SetupVPR(const t_options* Options,
t_netlist_opts* NetlistOpts,
t_packer_opts* PackerOpts,
t_placer_opts* PlacerOpts,
t_ap_opts* APOpts,
t_annealing_sched* AnnealSched,
t_router_opts* RouterOpts,
t_analysis_opts* AnalysisOpts,
Expand Down
11 changes: 11 additions & 0 deletions vpr/src/base/ShowSetup.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <fstream>
#include <tuple>

#include "vtr_assert.h"
#include "vtr_log.h"
Expand All @@ -18,6 +19,7 @@ static void ShowPackerOpts(const t_packer_opts& PackerOpts);
static void ShowNetlistOpts(const t_netlist_opts& NetlistOpts);
static void ShowPlacerOpts(const t_placer_opts& PlacerOpts,
const t_annealing_sched& AnnealSched);
static void ShowAnalyticalPlacerOpts(const t_ap_opts& APOpts);
static void ShowRouterOpts(const t_router_opts& RouterOpts);
static void ShowAnalysisOpts(const t_analysis_opts& AnalysisOpts);
static void ShowNocOpts(const t_noc_opts& NocOpts);
Expand All @@ -41,6 +43,7 @@ void ShowSetup(const t_vpr_setup& vpr_setup) {

VTR_LOG("Packer: %s\n", (vpr_setup.PackerOpts.doPacking ? "ENABLED" : "DISABLED"));
VTR_LOG("Placer: %s\n", (vpr_setup.PlacerOpts.doPlacement ? "ENABLED" : "DISABLED"));
VTR_LOG("Analytical Placer: %s\n", (vpr_setup.APOpts.doAP ? "ENABLED" : "DISABLED"));
VTR_LOG("Router: %s\n", (vpr_setup.RouterOpts.doRouting ? "ENABLED" : "DISABLED"));
VTR_LOG("Analysis: %s\n", (vpr_setup.AnalysisOpts.doAnalysis ? "ENABLED" : "DISABLED"));
VTR_LOG("\n");
Expand All @@ -55,6 +58,9 @@ void ShowSetup(const t_vpr_setup& vpr_setup) {
if (vpr_setup.PlacerOpts.doPlacement) {
ShowPlacerOpts(vpr_setup.PlacerOpts, vpr_setup.AnnealSched);
}
if (vpr_setup.APOpts.doAP) {
ShowAnalyticalPlacerOpts(vpr_setup.APOpts);
}
if (vpr_setup.RouterOpts.doRouting) {
ShowRouterOpts(vpr_setup.RouterOpts);
}
Expand Down Expand Up @@ -608,6 +614,11 @@ static void ShowPlacerOpts(const t_placer_opts& PlacerOpts,
VTR_LOG("\n");
}

static void ShowAnalyticalPlacerOpts(const t_ap_opts& APOpts) {
(void)APOpts;
// Currently nothing to show, but will happen eventually.
}

static void ShowNetlistOpts(const t_netlist_opts& NetlistOpts) {
VTR_LOG("NetlistOpts.absorb_buffer_luts : %s\n", (NetlistOpts.absorb_buffer_luts) ? "true" : "false");
VTR_LOG("NetlistOpts.sweep_dangling_primary_ios : %s\n", (NetlistOpts.sweep_dangling_primary_ios) ? "true" : "false");
Expand Down
5 changes: 5 additions & 0 deletions vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,11 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
.action(argparse::Action::STORE_TRUE)
.default_value("off");

stage_grp.add_argument<bool, ParseOnOff>(args.do_analytical_placement, "--analytical_place")
.help("Run analytical placement")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expand on this .help. Should say analytical placement uses an integrated packing & placement algorithm.

(Reason to explain this: otherwise it would make more sense for us to just have another set of placement options, but not a different stage).

.action(argparse::Action::STORE_TRUE)
.default_value("off");

stage_grp.add_argument<bool, ParseOnOff>(args.do_routing, "--route")
.help("Run routing")
.action(argparse::Action::STORE_TRUE)
Expand Down
1 change: 1 addition & 0 deletions vpr/src/base/read_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct t_options {
argparse::ArgValue<bool> do_packing;
argparse::ArgValue<bool> do_legalize;
argparse::ArgValue<bool> do_placement;
argparse::ArgValue<bool> do_analytical_placement;
argparse::ArgValue<bool> do_routing;
argparse::ArgValue<bool> do_analysis;
argparse::ArgValue<bool> do_power;
Expand Down
28 changes: 26 additions & 2 deletions vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "place_constraints.h"
#include "place_util.h"
#include "timing_fail_error.h"
#include "analytical_placement_flow.h"

#include "vpr_constraints_writer.h"

Expand Down Expand Up @@ -285,6 +286,7 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a
&vpr_setup->NetlistOpts,
&vpr_setup->PackerOpts,
&vpr_setup->PlacerOpts,
&vpr_setup->APOpts,
&vpr_setup->AnnealSched,
&vpr_setup->RouterOpts,
&vpr_setup->AnalysisOpts,
Expand All @@ -307,6 +309,7 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a
/* Verify settings don't conflict or otherwise not make sense */
CheckSetup(vpr_setup->PackerOpts,
vpr_setup->PlacerOpts,
vpr_setup->APOpts,
vpr_setup->RouterOpts,
vpr_setup->ServerOpts,
vpr_setup->RoutingArch, vpr_setup->Segments, vpr_setup->Timing, arch->Chans);
Expand Down Expand Up @@ -402,6 +405,14 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
return false; //Unimplementable
}
}

{ // Analytical Place
if (vpr_setup.APOpts.doAP == STAGE_DO) {
// TODO: Make this return a bool if the placement was successful or not.
run_analytical_placement_flow(vpr_setup);
}
}

bool is_flat = vpr_setup.RouterOpts.flat_routing;
const Netlist<>& router_net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom().nlist : (const Netlist<>&)g_vpr_ctx.clustering().clb_nlist;
RouteStatus route_status;
Expand Down Expand Up @@ -1354,6 +1365,7 @@ void vpr_setup_vpr(t_options* Options,
t_netlist_opts* NetlistOpts,
t_packer_opts* PackerOpts,
t_placer_opts* PlacerOpts,
t_ap_opts* APOpts,
t_annealing_sched* AnnealSched,
t_router_opts* RouterOpts,
t_analysis_opts* AnalysisOpts,
Expand All @@ -1379,6 +1391,7 @@ void vpr_setup_vpr(t_options* Options,
NetlistOpts,
PackerOpts,
PlacerOpts,
APOpts,
AnnealSched,
RouterOpts,
AnalysisOpts,
Expand All @@ -1403,14 +1416,22 @@ void vpr_check_arch(const t_arch& Arch) {
///@brief Verify settings don't conflict or otherwise not make sense
void vpr_check_setup(const t_packer_opts& PackerOpts,
const t_placer_opts& PlacerOpts,
const t_ap_opts& APOpts,
const t_router_opts& RouterOpts,
const t_server_opts& ServerOpts,
const t_det_routing_arch& RoutingArch,
const std::vector<t_segment_inf>& Segments,
const t_timing_inf& Timing,
const t_chan_width_dist& Chans) {
CheckSetup(PackerOpts, PlacerOpts, RouterOpts, ServerOpts, RoutingArch,
Segments, Timing, Chans);
CheckSetup(PackerOpts,
PlacerOpts,
APOpts,
RouterOpts,
ServerOpts,
RoutingArch,
Segments,
Timing,
Chans);
}

///@brief Show current setup
Expand Down Expand Up @@ -1634,6 +1655,9 @@ void vpr_print_error(const VprError& vpr_error) {
case VPR_ERROR_PLACE:
error_type = "Placement";
break;
case VPR_ERROR_AP:
error_type = "Analytical Placement";
break;
case VPR_ERROR_ROUTE:
error_type = "Routing";
break;
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/base/vpr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void vpr_setup_vpr(t_options* Options,
t_netlist_opts* NetlistOpts,
t_packer_opts* PackerOpts,
t_placer_opts* PlacerOpts,
t_ap_opts* APOpts,
t_annealing_sched* AnnealSched,
t_router_opts* RouterOpts,
t_analysis_opts* AnalysisOpts,
Expand All @@ -200,6 +201,7 @@ void vpr_check_arch(const t_arch& Arch);
///@brief Verify settings don't conflict or otherwise not make sense
void vpr_check_setup(const t_packer_opts& PackerOpts,
const t_placer_opts& PlacerOpts,
const t_ap_opts& APOpts,
const t_router_opts& RouterOpts,
const t_server_opts& ServerOpts,
const t_det_routing_arch& RoutingArch,
Expand Down
21 changes: 21 additions & 0 deletions vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,26 @@ struct t_placer_opts {
bool enable_analytic_placer;
};


/******************************************************************
* Analytical Placer data types
*******************************************************************/

/**
* @brief Various options for the Analytical Placer.
*
* @param doAnalyticalPlacement
* True if analytical placement is supposed to be done in the CAD
* flow. False if otherwise.
*/
struct t_ap_opts {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we've got lots of types in this file already, but I wonder if the t_ap_ops should go in the analytical_place directory (maybe ap_types.h) instead? Don't worry about it if that would be a big refactor or be more trouble than it is worth due to being inconsistent with other opts.

e_stage_action doAP;
};

/******************************************************************
* Router data types
*******************************************************************/

/* All the parameters controlling the router's operation are in this *
* structure. *
* first_iter_pres_fac: Present sharing penalty factor used for the *
Expand Down Expand Up @@ -1712,6 +1732,7 @@ struct t_vpr_setup {
t_netlist_opts NetlistOpts; ///<Options for packer
t_packer_opts PackerOpts; ///<Options for packer
t_placer_opts PlacerOpts; ///<Options for placer
t_ap_opts APOpts; ///<Options for analytical placer
t_annealing_sched AnnealSched; ///<Placement option annealing schedule
t_router_opts RouterOpts; ///<router options
t_analysis_opts AnalysisOpts; ///<Analysis options
Expand Down
Loading