Skip to content

Commit 94e5a05

Browse files
committed
Add architecture ID to .net files and verify when loading .net files
The ID is the SHA256 digest of the architecture file. Since it is based on the file contents it is robust to file path changes.
1 parent eeddcd0 commit 94e5a05

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

vpr/SRC/base/read_netlist.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void set_atom_pin_mapping(const AtomBlockId atom_blk, const AtomPortId at
7676
* num_nets - number of nets in netlist
7777
* net_list - nets in netlist [0..num_nets - 1]
7878
*/
79-
void read_netlist(const char *net_file, const t_arch* /*arch*/,
79+
void read_netlist(const char *net_file, const t_arch* arch,
8080
int *L_num_blocks, struct s_block *block_list[],
8181
t_netlist* clb_nlist) {
8282
clock_t begin = clock();
@@ -128,6 +128,23 @@ void read_netlist(const char *net_file, const t_arch* /*arch*/,
128128
top_instance.value());
129129
}
130130

131+
auto architecture_id = top.attribute("architecture_id");
132+
if (architecture_id) {
133+
//Netlist file has an architecture id, make sure it is
134+
//consistent with the loaded architecture file.
135+
//
136+
//Note that we currently don't require that the architecture_id exists,
137+
//to remain compatible with old .net files
138+
std::string arch_id = architecture_id.value();
139+
if (arch_id != arch->architecture_id) {
140+
//TODO: make this configurable as warning or error
141+
vpr_throw(VPR_ERROR_NET_F, netlist_file_name, loc_data.line(top),
142+
"Netlist was generated from a different architecture file (loaded architecture ID: %s, netlist file architecture ID: %s)",
143+
arch->architecture_id,
144+
arch_id.c_str());
145+
}
146+
}
147+
131148
//Collect top level I/Os
132149
auto top_inputs = pugiutil::get_single_child(top, "inputs", loc_data);
133150
circuit_inputs = vtr::split(top_inputs.text().get());

vpr/SRC/base/vpr_api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ void free_arch(t_arch* Arch) {
695695
}
696696
free(Arch->Directs);
697697

698+
free(Arch->architecture_id);
699+
698700
free(Arch->model_library[0].name);
699701
free(Arch->model_library[0].outputs->name);
700702
delete[] Arch->model_library[0].outputs;

vpr/SRC/pack/cluster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void do_clustering(const t_arch *arch, t_pack_molecule *molecule_head,
713713

714714
block = clb;
715715

716-
output_clustering(clb, num_clb, intra_lb_routing, global_clocks, is_clock, out_fname, false);
716+
output_clustering(clb, num_clb, intra_lb_routing, global_clocks, is_clock, arch->architecture_id, out_fname, false);
717717

718718
block = NULL;
719719
for(int irt = 0; irt < (int) intra_lb_routing.size(); irt++){

vpr/SRC/pack/output_clustering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ static void print_stats(t_block *clb, int num_clusters) {
579579
}
580580

581581
void output_clustering(t_block *clb, int num_clusters, const vector < vector <t_intra_lb_net> * > &intra_lb_routing, bool global_clocks,
582-
const std::unordered_set<AtomNetId>& is_clock, const char *out_fname, bool skip_clustering) {
582+
const std::unordered_set<AtomNetId>& is_clock, const std::string& architecture_id, const char *out_fname, bool skip_clustering) {
583583

584584
/*
585585
* This routine dumps out the output netlist in a format suitable for *
@@ -604,8 +604,8 @@ void output_clustering(t_block *clb, int num_clusters, const vector < vector <t_
604604

605605
fpout = fopen(out_fname, "w");
606606

607-
fprintf(fpout, "<block name=\"%s\" instance=\"FPGA_packed_netlist[0]\">\n",
608-
out_fname);
607+
fprintf(fpout, "<block name=\"%s\" instance=\"FPGA_packed_netlist[0]\" architecture_id=\"%s\">\n",
608+
out_fname, architecture_id.c_str());
609609
fprintf(fpout, "\t<inputs>\n\t\t");
610610

611611
column = 2 * TAB_LENGTH; /* Organize whitespace to ident data inside block */

vpr/SRC/pack/output_clustering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#include "pack_types.h"
77

88
void output_clustering(t_block *clb, int num_clusters, const std::vector<std::vector <t_intra_lb_net>*> &intra_lb_routing, bool global_clocks,
9-
const std::unordered_set<AtomNetId>& is_clock, const char *out_fname, bool skip_clustering);
9+
const std::unordered_set<AtomNetId>& is_clock, const std::string& architecture_id, const char *out_fname, bool skip_clustering);
1010

1111
#endif

vpr/SRC/pack/pack.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ using namespace std;
1919
#include "pack.h"
2020
#include "read_blif.h"
2121
#include "cluster.h"
22-
#include "output_clustering.h"
2322
#include "ReadOptions.h"
2423

2524
/* #define DUMP_PB_GRAPH 1 */

0 commit comments

Comments
 (0)