Skip to content

Commit 00d6bfb

Browse files
[AP] Added Export for Flat Placement File
Added the ability to export PartialPlacements to the flat placement file format defined by VIPER: verilog-to-routing#2670
1 parent 74c7c7a commit 00d6bfb

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

vpr/src/place/analytical_placement/PartialPlacement.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#include "PartialPlacement.h"
33
#include <cmath>
44
#include <cstddef>
5-
#include <cstdint>
5+
#include <fstream>
6+
#include <ios>
67
#include <limits>
78
#include <map>
9+
#include <string>
810
#include <unordered_set>
911
#include <vector>
1012
#include "globals.h"
11-
#include "vpr_constraints_uxsdcxx.h"
1213
#include "vpr_context.h"
1314
#include "vpr_types.h"
1415
#include "vtr_assert.h"
@@ -267,3 +268,42 @@ void PartialPlacement::unicode_art(){
267268
VTR_LOG("unicode_art end\n");
268269
fflush(stderr);
269270
}
271+
272+
bool PartialPlacement::export_to_flat_placement_file(std::string file_name) {
273+
// https://doi.org/10.1145/3665283.3665300
274+
// Primitive Name /t X /t Y /t Subtile /t Site
275+
std::ofstream flat_placement_file;
276+
flat_placement_file.open(file_name, std::ios::out);
277+
if (!flat_placement_file) {
278+
VTR_LOG_ERROR("Failed to open the flat placement file '%s' to export the PartialPlacement.\n",
279+
file_name.c_str());
280+
return false;
281+
}
282+
283+
// FIXME: Are sites just unique IDs per molecule or do they need to start at
284+
// 0 per tile?
285+
size_t site_idx = 0;
286+
for (size_t node_id = 0; node_id < num_nodes; node_id++) {
287+
int mol_pos_x = std::floor(node_loc_x[node_id]);
288+
int mol_pos_y = std::floor(node_loc_y[node_id]);
289+
// FIXME: What is a subtile?
290+
int mol_subtile = 0;
291+
t_pack_molecule* mol = node_id_to_mol[node_id];
292+
for (AtomBlockId block_id : mol->atom_block_ids) {
293+
// Primitive's name
294+
flat_placement_file << atom_netlist.block_name(block_id) << '\t';
295+
// Primitive's cluster coordinates
296+
flat_placement_file << mol_pos_x << '\t' << mol_pos_y << '\t';
297+
flat_placement_file << mol_subtile << '\t';
298+
// Primitive site index
299+
flat_placement_file << site_idx << '\n';
300+
}
301+
// Increment the site index per molecule so each molecule has a unique
302+
// index.
303+
site_idx++;
304+
}
305+
306+
flat_placement_file.close();
307+
return true;
308+
}
309+

vpr/src/place/analytical_placement/PartialPlacement.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class PartialPlacement {
6060

6161
void unicode_art();
6262

63+
// Export the PartialPlacement to a file following the VIPER Flat Placement
64+
// File Format: https://doi.org/10.1145/3665283.3665300
65+
bool export_to_flat_placement_file(std::string file_name);
66+
6367
inline void print_stats() {
6468
VTR_LOG("Number of moveable nodes: %zu\n", num_moveable_nodes);
6569
VTR_LOG("Number of fixed nodes: %zu\n", num_nodes - num_moveable_nodes);

vpr/src/place/analytical_placement/analytical_placement_flow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ void run_analytical_placement_flow() {
101101
}
102102
// p_placement.unicode_art();
103103
}
104+
105+
// Export to a flat placement file.
106+
p_placement.export_to_flat_placement_file("flat_placement_file.txt");
107+
104108
FullLegalizer().legalize(p_placement);
105109
}
106110

0 commit comments

Comments
 (0)