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+ * (primitive-level) placements.
7+ */
48
9+ #include " load_flat_place.h"
510
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"
916
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
19+ * cluster.
20+ *
21+ * @param fp
22+ * File pointer to the file the cluster is printed to.
23+ * @param blk_id
24+ * The ID of the cluster block to print.
25+ * @param block_locs
26+ * The locations of all cluster blocks.
27+ * @param atoms_lookup
28+ * A lookup between all clusters and the atom blocks that they
29+ * contain.
30+ */
31+ static void print_flat_cluster (FILE* fp,
32+ ClusterBlockId blk_id,
33+ const vtr::vector_map<ClusterBlockId, t_block_loc> &block_locs,
34+ const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) {
35+ // Atom context used to get the atom_pb for each atom in the cluster.
36+ // NOTE: This is only used for getting the flat site index.
37+ const AtomContext& atom_ctx = g_vpr_ctx.atom ();
1438
15- t_pl_loc loc = block_locs[iblk]. loc ;
16- size_t bnum = size_t (iblk) ;
39+ // Get the location of this cluster.
40+ const t_pl_loc& blk_loc = block_locs[blk_id]. loc ;
1741
18- for (AtomBlockId atom : atoms) {
42+ // Print a line for each atom.
43+ for (AtomBlockId atom : atoms_lookup[blk_id]) {
44+ // Get the atom pb graph node.
1945 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 );
46+
47+ // Print the flat placement information for this atom.
48+ fprintf (fp, " %s %d %d %d %d #%zu %s\n " ,
49+ atom_ctx.nlist .block_name (atom).c_str (),
50+ blk_loc.x , blk_loc.y , blk_loc.sub_tile ,
51+ atom_pbgn->flat_site_index ,
52+ static_cast <size_t >(blk_id),
53+ atom_pbgn->pb_type ->name );
2554 }
2655}
2756
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);
57+ void write_flat_placement (const char * flat_place_file_path,
58+ const ClusteredNetlist& cluster_netlist,
59+ const vtr::vector_map<ClusterBlockId, t_block_loc> &block_locs,
60+ const vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) {
61+ // Writes the flat placement to the given flat_place_file_path.
62+
63+ // Only print a flat placement if the clusters have been placed.
64+ if (block_locs.empty ())
65+ return ;
66+
67+ // Create a file in write mode for the flat placement.
68+ FILE* fp = fopen (flat_place_file_path, " w" );
69+
70+ // For each cluster, write out the atoms in the cluster at this cluster's
71+ // location.
72+ for (ClusterBlockId iblk : cluster_netlist.blocks ()) {
73+ print_flat_cluster (fp, iblk, block_locs, atoms_lookup);
4474 }
4575
76+ // Close the file.
77+ fclose (fp);
4678}
4779
4880/* ingests and legalizes a flat placement file */
@@ -55,3 +87,4 @@ bool load_flat_placement(t_vpr_setup& vpr_setup, const t_arch& arch) {
5587
5688 return false ;
5789}
90+
0 commit comments