Skip to content

Commit

Permalink
[AP] Added Export for Flat Placement File
Browse files Browse the repository at this point in the history
Added the ability to export PartialPlacements to the flat placement file
format defined by VIPER:
verilog-to-routing#2670
  • Loading branch information
AlexandreSinger committed Jul 30, 2024
1 parent 74c7c7a commit 00d6bfb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
44 changes: 42 additions & 2 deletions vpr/src/place/analytical_placement/PartialPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#include "PartialPlacement.h"
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <ios>
#include <limits>
#include <map>
#include <string>
#include <unordered_set>
#include <vector>
#include "globals.h"
#include "vpr_constraints_uxsdcxx.h"
#include "vpr_context.h"
#include "vpr_types.h"
#include "vtr_assert.h"
Expand Down Expand Up @@ -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;
}

4 changes: 4 additions & 0 deletions vpr/src/place/analytical_placement/PartialPlacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 00d6bfb

Please sign in to comment.