Skip to content

Commit 9b86233

Browse files
committed
Add netlist ID (SHA256) to .net output and verify when re-loading
1 parent 94e5a05 commit 9b86233

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

vpr/SRC/base/atom_netlist.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ Container update_valid_refs(const Container& values, const vtr::vector_map<ValId
165165
*
166166
*/
167167

168-
AtomNetlist::AtomNetlist(std::string name)
168+
AtomNetlist::AtomNetlist(std::string name, std::string id)
169169
: netlist_name_(name)
170+
, netlist_id_(id)
170171
, dirty_(false) {}
171172

172173
/*
@@ -178,6 +179,10 @@ const std::string& AtomNetlist::netlist_name() const {
178179
return netlist_name_;
179180
}
180181

182+
const std::string& AtomNetlist::netlist_id() const {
183+
return netlist_id_;
184+
}
185+
181186
bool AtomNetlist::is_dirty() const {
182187
return dirty_;
183188
}

vpr/SRC/base/atom_netlist.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,9 @@ class AtomNetlist {
420420
public:
421421

422422
//Constructs a netlist
423-
// name - the name of the netlist
424-
AtomNetlist(std::string name="");
423+
// name: the name of the netlist (e.g. top-level module)
424+
// id: a unique identifier for the netlist (e.g. a secure digest of the input file)
425+
AtomNetlist(std::string name="", std::string id="");
425426

426427
public: //Public Accessors
427428
/*
@@ -430,6 +431,10 @@ class AtomNetlist {
430431
//Retrieve the name of the netlist
431432
const std::string& netlist_name() const;
432433

434+
//Retrieve the unique identifier for this netlist
435+
//This is typically a secure digest of the input file.
436+
const std::string& netlist_id() const;
437+
433438
/*
434439
* Blocks
435440
*/
@@ -838,6 +843,7 @@ class AtomNetlist {
838843

839844
//Netlist data
840845
std::string netlist_name_; //Name of the top-level netlist
846+
std::string netlist_id_; //Unique identifier for the netlist
841847
bool dirty_; //Indicates the netlist has invalid entries from remove_*() functions
842848

843849
//Block data

vpr/SRC/base/read_blif.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using namespace std;
3232
#include "vtr_log.h"
3333
#include "vtr_logic.h"
3434
#include "vtr_time.h"
35+
#include "vtr_digest.h"
3536

3637
#include "vpr_types.h"
3738
#include "vpr_error.h"
@@ -59,8 +60,9 @@ vtr::LogicValue to_vtr_logic_value(blifparse::LogicValue);
5960

6061
struct BlifAllocCallback : public blifparse::Callback {
6162
public:
62-
BlifAllocCallback(AtomNetlist& main_netlist, const t_model* user_models, const t_model* library_models)
63+
BlifAllocCallback(AtomNetlist& main_netlist, const std::string netlist_id, const t_model* user_models, const t_model* library_models)
6364
: main_netlist_(main_netlist)
65+
, netlist_id_(netlist_id)
6466
, user_arch_models_(user_models)
6567
, library_arch_models_(library_models) {}
6668

@@ -80,7 +82,7 @@ struct BlifAllocCallback : public blifparse::Callback {
8082
void begin_model(std::string model_name) override {
8183
//Create a new model, and set it's name
8284

83-
blif_models_.emplace_back(model_name);
85+
blif_models_.emplace_back(model_name, netlist_id_);
8486
blif_models_black_box_.emplace_back(false);
8587
ended_ = false;
8688
}
@@ -614,6 +616,7 @@ struct BlifAllocCallback : public blifparse::Callback {
614616
std::vector<bool> blif_models_black_box_;
615617

616618
AtomNetlist& main_netlist_; //User object we fill
619+
const std::string netlist_id_; //Unique identifier based on the contents of the blif file
617620
const t_model* user_arch_models_ = nullptr;
618621
const t_model* library_arch_models_ = nullptr;
619622

@@ -637,9 +640,12 @@ vtr::LogicValue to_vtr_logic_value(blifparse::LogicValue val) {
637640
static AtomNetlist read_blif(const char *blif_file,
638641
const t_model *user_models,
639642
const t_model *library_models) {
643+
644+
640645
AtomNetlist netlist;
646+
std::string netlist_id = vtr::secure_digest_file(blif_file);
641647

642-
BlifAllocCallback alloc_callback(netlist, user_models, library_models);
648+
BlifAllocCallback alloc_callback(netlist, netlist_id, user_models, library_models);
643649
blifparse::blif_parse_filename(blif_file, alloc_callback);
644650

645651
netlist.verify();

vpr/SRC/base/read_netlist.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ void read_netlist(const char *net_file, const t_arch* arch,
145145
}
146146
}
147147

148+
auto atom_netlist_id = top.attribute("atom_netlist_id");
149+
if (atom_netlist_id) {
150+
//Netlist file has an_atom netlist_id, make sure it is
151+
//consistent with the loaded atom netlist.
152+
//
153+
//Note that we currently don't require that the atom_netlist_id exists,
154+
//to remain compatible with old .net files
155+
std::string atom_nl_id = atom_netlist_id.value();
156+
if (atom_nl_id != g_atom_nl.netlist_id()) {
157+
//TODO: make this configurable as warning or error
158+
vpr_throw(VPR_ERROR_NET_F, netlist_file_name, loc_data.line(top),
159+
"Netlist was generated from a different atom netlist file (loaded atom netlist ID: %s, packed netlist atom netlist ID: %s)",
160+
atom_nl_id.c_str(),
161+
g_atom_nl.netlist_id().c_str());
162+
}
163+
}
164+
148165
//Collect top level I/Os
149166
auto top_inputs = pugiutil::get_single_child(top, "inputs", loc_data);
150167
circuit_inputs = vtr::split(top_inputs.text().get());

vpr/SRC/pack/output_clustering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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]\" architecture_id=\"%s\">\n",
608-
out_fname, architecture_id.c_str());
607+
fprintf(fpout, "<block name=\"%s\" instance=\"FPGA_packed_netlist[0]\" architecture_id=\"%s\" atom_netlist_id=\"%s\">\n",
608+
out_fname, architecture_id.c_str(), g_atom_nl.netlist_id().c_str());
609609
fprintf(fpout, "\t<inputs>\n\t\t");
610610

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

0 commit comments

Comments
 (0)