Skip to content

Commit 397ad0f

Browse files
committed
Added some comments and updated some VTRLOG messages
1 parent 0d51b9b commit 397ad0f

File tree

6 files changed

+63
-12
lines changed

6 files changed

+63
-12
lines changed

vpr/src/base/ShowSetup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void ShowSetup(const t_vpr_setup& vpr_setup) {
3131
VTR_LOG("Circuit placement file: %s\n", vpr_setup.FileNameOpts.PlaceFile.c_str());
3232
VTR_LOG("Circuit routing file: %s\n", vpr_setup.FileNameOpts.RouteFile.c_str());
3333
VTR_LOG("Circuit SDC file: %s\n", vpr_setup.Timing.SDCFile.c_str());
34-
VTR_LOG("Vpr Constraints file: %s\n", vpr_setup.FileNameOpts.read_vpr_constraints_file.c_str());
34+
VTR_LOG("Vpr floorplanning constraints file: %s\n", vpr_setup.FileNameOpts.read_vpr_constraints_file.c_str());
3535
VTR_LOG("\n");
3636

3737
VTR_LOG("Packer: %s\n", (vpr_setup.PackerOpts.doPacking ? "ENABLED" : "DISABLED"));

vpr/src/base/constraints_load.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void print_region(FILE* fp, Region region) {
2323

2424
void print_partition(FILE* fp, Partition part) {
2525
std::string name = part.get_name();
26-
fprintf(fp, "\npartition_name: %s\n", name.c_str());
26+
fprintf(fp, "partition_name: %s\n", name.c_str());
2727

2828
PartitionRegion pr = part.get_part_region();
2929

@@ -51,6 +51,7 @@ void print_constraints(FILE* fp, VprConstraints constraints, int num_parts) {
5151

5252
temp_part = constraints.get_partition(part_id);
5353

54+
fprintf(fp, "\npartition_id: %zu\n", size_t(part_id));
5455
print_partition(fp, temp_part);
5556

5657
atoms = constraints.get_part_atoms(part_id);

vpr/src/base/read_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
13821382
.show_in(argparse::ShowIn::HELP_ONLY);
13831383

13841384
file_grp.add_argument(args.read_vpr_constraints_file, "--read_vpr_constraints")
1385-
.help("Reads the constraints data from the constraints file.")
1385+
.help("Reads the floorplanning constraints from the specified XML file.")
13861386
.show_in(argparse::ShowIn::HELP_ONLY);
13871387

13881388
file_grp.add_argument(args.read_router_lookahead, "--read_router_lookahead")

vpr/src/base/vpr_constraints_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void load_vpr_constraints_file(const char* read_vpr_constraints_name) {
2727
} else {
2828
VTR_LOG_WARN(
2929
"VPR constraints file '%s' may be in incorrect format. "
30-
"Expecting .xml format\n",
30+
"Expecting .xml format. Not reading file.\n",
3131
read_vpr_constraints_name);
3232
}
3333

vpr/src/base/vpr_constraints_reader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* Defines the function used to load a vpr constraints file written in xml format into vpr*/
1+
/* Defines the function used to load a vpr constraints file written in XML format into vpr
2+
* The functions loads up the VprConstraints, Partition, Region, and PartitionRegion data structures
3+
* according to the data provided in the XML file*/
24

35
#ifndef VPR_CONSTRAINTS_READER_H_
46
#define VPR_CONSTRAINTS_READER_H_

vpr/src/base/vpr_constraints_serializer.h

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,44 @@
1212

1313
#include "vpr_constraints_uxsdcxx_interface.h"
1414

15+
/**
16+
* @file
17+
* @brief The reading of vpr floorplanning constraints is now done via uxsdcxx and the 'vpr_constraints.xsd' file.
18+
* The interface between the generated code and VPR is provided by VprConstraintsBase, which is in the
19+
* file 'vpr/src/base/gen/vpr_constraints_uxsdcxx_interface.h'.
20+
* This file implements the virtual functions from VprConstraintsBase.
21+
*
22+
* Overview
23+
* ========
24+
* 'vpr_constraints.xsd' is an XML schema that specifies the desired format for a VPR constraints file.
25+
* If this schema is changed, the following files must be regenerated: 'vpr/src/base/gen/vpr_constraints_uxsdcxx.h' and
26+
* 'vpr/src/base/gen/vpr_constraints_uxsdcxx_interface.h'.
27+
*
28+
* Instructions to Update the Files
29+
* ================================
30+
*
31+
* 1. Clone https://github.com/duck2/uxsdcxx/
32+
* 2. Run 'python3 -mpip install --user -r requirements.txt'
33+
* 3. Run 'python3 uxsdcxx.py vpr/src/base/vpr_constraints.xsd'
34+
* 4. Copy 'vpr_constraints_uxsdcxx.h' and 'vpr_constraints_uxsdcxx_interface.h' to vpr/src/base/gen
35+
* 5. Run 'make format'
36+
* 6. Update 'vpr/src/base/vpr_constraints_serializer.h' (this file) by adding or changing functions as needed.
37+
* If the schema has changed, the compiler will complain that virtual functions are missing if they are
38+
* not implemented here.
39+
*
40+
* Functions in this file
41+
* ======================
42+
*
43+
* This file implements all the functions that are necessary for the load/read interface of uxsdcxx. These are start_load, finish_load,
44+
* error_encountered, and any function starting with 'set', 'add', 'preallocate' or 'finish'. Some of the load functions (ex. finish_load and
45+
* the preallocate functions) have been stubbed out because the load could be successfully completed without implementing them.
46+
*
47+
* The functions related to the write interface have also been stubbed out because writing vpr_constraints XML files is not needed at this time.
48+
* These functions can be implemented to make the write interface if needed.
49+
*
50+
* For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md'
51+
*/
52+
1553
struct VprConstraintsContextTypes : public uxsd::DefaultVprConstraintsContextTypes {
1654
using AddAtomReadContext = void*;
1755
using AddRegionReadContext = void*;
@@ -61,11 +99,16 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
6199

62100
auto atom_name_regex = std::regex(atom_name);
63101

64-
std::vector<AtomBlockId> clear_atoms;
65-
atoms_ = clear_atoms;
102+
atoms_.clear();
66103

67104
atom_id_ = atom_ctx.nlist.find_block(name_pattern);
68105

106+
/* The constraints file may either provide a specific atom name or a regex.
107+
* If the a valid atom ID is found for the atom name, then a specific atom name
108+
* must have been read in from the file. The if condition checks for this case.
109+
* The else statement checks for atoms that may match a regex.
110+
* This code may get slow if many regexes are given in the file.
111+
*/
69112
if (atom_id_ != AtomBlockId::INVALID()) {
70113
atoms_.push_back(atom_id_);
71114
} else {
@@ -75,8 +118,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
75118
for (auto block_id : atom_ctx.nlist.blocks()) {
76119
auto block_name = atom_ctx.nlist.block_name(block_id);
77120

78-
if (std::regex_match(block_name, atom_name_regex)) {
79-
VTR_LOG("Matched block %s with ID %d to regex\n", block_name.c_str(), block_id);
121+
if (std::regex_search(block_name, atom_name_regex)) {
80122
atoms_.push_back(block_id);
81123
}
82124
}
@@ -154,9 +196,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
154196
PartitionId part_id(num_partitions_);
155197

156198
for (unsigned int i = 0; i < atoms_.size(); i++) {
157-
if (atoms_[i] != AtomBlockId::INVALID()) {
158-
constraints_.add_constrained_atom(atoms_[i], part_id);
159-
}
199+
constraints_.add_constrained_atom(atoms_[i], part_id);
160200
}
161201
}
162202

@@ -259,12 +299,20 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
259299

260300
//temp data for loads
261301
const std::function<void(const char*)>* report_error_;
302+
303+
//temp data structures to be loaded during file reading
262304
Region loaded_region;
263305
Partition loaded_partition;
264306
PartitionRegion loaded_part_region;
265307
VprConstraints constraints_;
308+
309+
//temp string used when a method must return a const char*
266310
std::string temp_;
311+
312+
//used to count the number of partitions read in from the file
267313
int num_partitions_ = 0;
314+
315+
//used when reading in atom names and regular expressions for atoms
268316
AtomBlockId atom_id_;
269317
std::vector<AtomBlockId> atoms_;
270318
};

0 commit comments

Comments
 (0)