12
12
13
13
#include " vpr_constraints_uxsdcxx_interface.h"
14
14
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
+
15
53
struct VprConstraintsContextTypes : public uxsd ::DefaultVprConstraintsContextTypes {
16
54
using AddAtomReadContext = void *;
17
55
using AddRegionReadContext = void *;
@@ -58,9 +96,38 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
58
96
virtual inline void set_add_atom_name_pattern (const char * name_pattern, void *& /* ctx*/ ) final {
59
97
auto & atom_ctx = g_vpr_ctx.atom ();
60
98
std::string atom_name = name_pattern;
99
+
100
+ auto atom_name_regex = std::regex (atom_name);
101
+
102
+ atoms_.clear ();
103
+
61
104
atom_id_ = atom_ctx.nlist .find_block (name_pattern);
62
105
63
- if (atom_id_ == AtomBlockId::INVALID ()) {
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
+ */
112
+ if (atom_id_ != AtomBlockId::INVALID ()) {
113
+ atoms_.push_back (atom_id_);
114
+ } else {
115
+ /* If the atom name returns an invalid ID, it might be a regular expression, so loop through the atoms blocks
116
+ * and see if any block names match atom_name_regex.
117
+ */
118
+ for (auto block_id : atom_ctx.nlist .blocks ()) {
119
+ auto block_name = atom_ctx.nlist .block_name (block_id);
120
+
121
+ if (std::regex_search (block_name, atom_name_regex)) {
122
+ atoms_.push_back (block_id);
123
+ }
124
+ }
125
+ }
126
+
127
+ /* If the atoms_ vector is empty by this point, no atoms were found that matched the name,
128
+ * so the name is invalid.
129
+ */
130
+ if (atoms_.empty ()) {
64
131
VTR_LOG_WARN (" Atom %s was not found, skipping atom.\n " , name_pattern);
65
132
}
66
133
}
@@ -128,8 +195,8 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
128
195
virtual inline void finish_partition_add_atom (void *& /* ctx*/ ) final {
129
196
PartitionId part_id (num_partitions_);
130
197
131
- if (atom_id_ != AtomBlockId::INVALID () ) {
132
- constraints_.add_constrained_atom (atom_id_ , part_id);
198
+ for ( unsigned int i = 0 ; i < atoms_. size (); i++ ) {
199
+ constraints_.add_constrained_atom (atoms_[i] , part_id);
133
200
}
134
201
}
135
202
@@ -211,6 +278,11 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
211
278
212
279
virtual inline void set_vpr_constraints_tool_name (const char * /* tool_name*/ , void *& /* ctx*/ ) final {}
213
280
281
+ virtual inline void set_vpr_constraints_constraints_comment (const char * /* constraints_comment*/ , void *& /* ctx*/ ) final {}
282
+
283
+ virtual inline const char * get_vpr_constraints_constraints_comment (void *& /* ctx*/ ) final {
284
+ return temp_.c_str ();
285
+ }
214
286
virtual inline void * init_vpr_constraints_partition_list (void *& /* ctx*/ ) final {
215
287
return nullptr ;
216
288
}
@@ -227,13 +299,22 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
227
299
228
300
// temp data for loads
229
301
const std::function<void (const char *)>* report_error_;
302
+
303
+ // temp data structures to be loaded during file reading
230
304
Region loaded_region;
231
305
Partition loaded_partition;
232
306
PartitionRegion loaded_part_region;
233
307
VprConstraints constraints_;
308
+
309
+ // temp string used when a method must return a const char*
234
310
std::string temp_;
311
+
312
+ // used to count the number of partitions read in from the file
235
313
int num_partitions_ = 0 ;
314
+
315
+ // used when reading in atom names and regular expressions for atoms
236
316
AtomBlockId atom_id_;
317
+ std::vector<AtomBlockId> atoms_;
237
318
};
238
319
239
320
#endif /* VPR_CONSTRAINTS_SERIALIZER_H_ */
0 commit comments