1
- #include " globals.h"
2
- #include " load_flat_place.h"
3
- #include " clustered_netlist_utils.h"
1
+ /* *
2
+ * @file
3
+ * @author Alex Singer
4
+ * @date January 2025
5
+ * @brief Implementation of utility functions for reading and writing flat
6
+ * placements.
7
+ */
4
8
9
+ #include " load_flat_place.h"
5
10
6
- /* @brief Prints flat placement file entries for the atoms in one placed cluster. */
7
- static void print_flat_cluster (FILE* fp, ClusterBlockId iblk,
8
- std::vector<AtomBlockId>& atoms);
11
+ #include < unordered_set>
12
+ #include " clustered_netlist.h"
13
+ #include " globals.h"
14
+ #include " vpr_context.h"
15
+ #include " vpr_types.h"
9
16
10
- static void print_flat_cluster (FILE* fp, ClusterBlockId iblk,
11
- std::vector<AtomBlockId>& atoms) {
12
- const auto & atom_ctx = g_vpr_ctx.atom ();
13
- const auto & block_locs = g_vpr_ctx.placement ().block_locs ();
17
+ /* *
18
+ * @brief Prints flat placement file entries for the atoms in one placed cluster.
19
+ */
20
+ static void print_flat_cluster (FILE* fp,
21
+ ClusterBlockId blk_id,
22
+ const vtr::vector_map<ClusterBlockId, t_block_loc> &block_locs,
23
+ const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) {
24
+ // Atom context used to get the atom_pb for each atom in the cluster.
25
+ // NOTE: This is only used for getting the flat site index.
26
+ const AtomContext& atom_ctx = g_vpr_ctx.atom ();
14
27
15
- t_pl_loc loc = block_locs[iblk]. loc ;
16
- size_t bnum = size_t (iblk) ;
28
+ // Get the location of this cluster.
29
+ const t_pl_loc& blk_loc = block_locs[blk_id]. loc ;
17
30
18
- for (AtomBlockId atom : atoms) {
31
+ // Print a line for each atom.
32
+ for (AtomBlockId atom : atoms_lookup[blk_id]) {
33
+ // Get the atom pb graph node.
19
34
t_pb_graph_node* atom_pbgn = atom_ctx.lookup .atom_pb (atom)->pb_graph_node ;
20
- fprintf (fp, " %s %d %d %d %d #%zu %s\n " , atom_ctx.nlist .block_name (atom).c_str (),
21
- loc.x , loc.y , loc.sub_tile ,
22
- atom_pbgn->flat_site_index ,
23
- bnum,
24
- atom_pbgn->pb_type ->name );
35
+
36
+ // Print the flat placement information for this atom.
37
+ fprintf (fp, " %s %d %d %d %d #%zu %s\n " ,
38
+ atom_ctx.nlist .block_name (atom).c_str (),
39
+ blk_loc.x , blk_loc.y , blk_loc.sub_tile ,
40
+ atom_pbgn->flat_site_index ,
41
+ static_cast <size_t >(blk_id),
42
+ atom_pbgn->pb_type ->name );
25
43
}
26
44
}
27
45
28
- /* prints a flat placement file */
29
- void print_flat_placement (const char * flat_place_file) {
30
- const auto & block_locs = g_vpr_ctx. placement (). block_locs ();
31
-
32
- FILE* fp;
33
-
34
- ClusterAtomsLookup atoms_lookup;
35
- auto & cluster_ctx = g_vpr_ctx. clustering () ;
36
-
37
- if (!block_locs. empty ()) {
38
- fp = fopen (flat_place_file , " w" );
39
- for (ClusterBlockId iblk : cluster_ctx. clb_nlist . blocks ()) {
40
- auto atoms = atoms_lookup. atoms_in_cluster (iblk);
41
- print_flat_cluster (fp, iblk, atoms);
42
- }
43
- fclose (fp);
46
+ /* Writes a flat placement file */
47
+ void write_flat_placement (const char * flat_place_file_path,
48
+ const ClusteredNetlist& cluster_netlist,
49
+ const vtr::vector_map<ClusterBlockId, t_block_loc> &block_locs,
50
+ const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) {
51
+ // Only print a flat placement if the clusters have been placed.
52
+ if (block_locs. empty ())
53
+ return ;
54
+
55
+ // Create a file in write mode for the flat placement.
56
+ FILE* fp = fopen (flat_place_file_path , " w" );
57
+
58
+ // For each cluster, write out the atoms in the cluster at this cluster's
59
+ // location.
60
+ for (ClusterBlockId iblk : cluster_netlist. blocks ()) {
61
+ print_flat_cluster (fp, iblk, block_locs, atoms_lookup );
44
62
}
45
63
64
+ // Close the file.
65
+ fclose (fp);
46
66
}
47
67
48
68
/* ingests and legalizes a flat placement file */
@@ -55,3 +75,4 @@ bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
55
75
56
76
return false ;
57
77
}
78
+
0 commit comments