diff --git a/vpr/src/place/analytical_placement/PartialPlacement.cpp b/vpr/src/place/analytical_placement/PartialPlacement.cpp index f8f3cb919ad..3f75a730ca3 100644 --- a/vpr/src/place/analytical_placement/PartialPlacement.cpp +++ b/vpr/src/place/analytical_placement/PartialPlacement.cpp @@ -2,13 +2,14 @@ #include "PartialPlacement.h" #include #include -#include +#include +#include #include #include +#include #include #include #include "globals.h" -#include "vpr_constraints_uxsdcxx.h" #include "vpr_context.h" #include "vpr_types.h" #include "vtr_assert.h" @@ -267,3 +268,42 @@ void PartialPlacement::unicode_art(){ VTR_LOG("unicode_art end\n"); fflush(stderr); } + +bool PartialPlacement::export_to_flat_placement_file(std::string file_name) { + // https://doi.org/10.1145/3665283.3665300 + // Primitive Name /t X /t Y /t Subtile /t Site + std::ofstream flat_placement_file; + flat_placement_file.open(file_name, std::ios::out); + if (!flat_placement_file) { + VTR_LOG_ERROR("Failed to open the flat placement file '%s' to export the PartialPlacement.\n", + file_name.c_str()); + return false; + } + + // FIXME: Are sites just unique IDs per molecule or do they need to start at + // 0 per tile? + size_t site_idx = 0; + for (size_t node_id = 0; node_id < num_nodes; node_id++) { + int mol_pos_x = std::floor(node_loc_x[node_id]); + int mol_pos_y = std::floor(node_loc_y[node_id]); + // FIXME: What is a subtile? + int mol_subtile = 0; + t_pack_molecule* mol = node_id_to_mol[node_id]; + for (AtomBlockId block_id : mol->atom_block_ids) { + // Primitive's name + flat_placement_file << atom_netlist.block_name(block_id) << '\t'; + // Primitive's cluster coordinates + flat_placement_file << mol_pos_x << '\t' << mol_pos_y << '\t'; + flat_placement_file << mol_subtile << '\t'; + // Primitive site index + flat_placement_file << site_idx << '\n'; + } + // Increment the site index per molecule so each molecule has a unique + // index. + site_idx++; + } + + flat_placement_file.close(); + return true; +} + diff --git a/vpr/src/place/analytical_placement/PartialPlacement.h b/vpr/src/place/analytical_placement/PartialPlacement.h index 2fead721815..2a4bef8bfb6 100644 --- a/vpr/src/place/analytical_placement/PartialPlacement.h +++ b/vpr/src/place/analytical_placement/PartialPlacement.h @@ -60,6 +60,10 @@ class PartialPlacement { void unicode_art(); + // Export the PartialPlacement to a file following the VIPER Flat Placement + // File Format: https://doi.org/10.1145/3665283.3665300 + bool export_to_flat_placement_file(std::string file_name); + inline void print_stats() { VTR_LOG("Number of moveable nodes: %zu\n", num_moveable_nodes); VTR_LOG("Number of fixed nodes: %zu\n", num_nodes - num_moveable_nodes); diff --git a/vpr/src/place/analytical_placement/analytical_placement_flow.cpp b/vpr/src/place/analytical_placement/analytical_placement_flow.cpp index 653051f5031..3004591643d 100644 --- a/vpr/src/place/analytical_placement/analytical_placement_flow.cpp +++ b/vpr/src/place/analytical_placement/analytical_placement_flow.cpp @@ -101,6 +101,10 @@ void run_analytical_placement_flow() { } // p_placement.unicode_art(); } + + // Export to a flat placement file. + p_placement.export_to_flat_placement_file("flat_placement_file.txt"); + FullLegalizer().legalize(p_placement); }