-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsynth_cmds.cc
More file actions
364 lines (335 loc) · 10.7 KB
/
Copy pathsynth_cmds.cc
File metadata and controls
364 lines (335 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*************************************************************************
*
* Copyright (c) 2026 Rajit Manohar
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#include <stdio.h>
#include <act/passes.h>
#include <lispCli.h>
#include "all_cmds.h"
#include "flow.h"
#include <act/synth/synth.h>
#include <act/synth/engines.h>
#include <act/expropt.h>
/*************************************************************************
*
* Functions to support logic synthesis
*
*************************************************************************
*/
/* anonymous namespace to avoid lots of static */
namespace {
ActDynamicPass *getSynthPass ()
{
ActPass *p = F.act_design->pass_find ("synth");
ActDynamicPass *dp;
if (!p) {
config_read ("synth.conf");
dp = new ActDynamicPass (F.act_design, "synth",
"libactchp2prspass.so", "synthesis");
}
else {
dp = dynamic_cast<ActDynamicPass *> (p);
}
if (!dp || (dp->loaded() == false)) {
return NULL;
}
return dp;
}
bool _set_synth_defaults (ActDynamicPass *dp, const char *family)
{
const char *nm = (const char *) dp->getPtrParam ("engine_name");
if (strcmp (family , "qdi") == 0) {
if (dp->getPtrParam ("engine") == (void *) gen_ring_engine) {
warning ("qdi synthesis is a work-in-progress for maelstrom.");
}
dp->setParam ("bundled_dpath", false);
dp->setParam ("bundled_dpath_2phase", false);
dp->setParam ("bundled_dpath_pulsed", false);
dp->setParam ("di_dpath", false);
dp->setParam ("ditest_dpath", false);
}
else if (strcmp (family, "bd") == 0) {
dp->setParam ("bundled_dpath", true);
dp->setParam ("bundled_dpath_2phase", false);
dp->setParam ("bundled_dpath_pulsed", false);
dp->setParam ("di_dpath", false);
dp->setParam ("ditest_dpath", false);
}
else if (strcmp (family, "bd2") == 0) {
if (strcmp (nm, "sdt") == 0) {
fprintf (stderr, "bd2 family not supported with sdt engine.\n");
return false;
}
dp->setParam ("bundled_dpath", true);
dp->setParam ("bundled_dpath_2phase", true);
dp->setParam ("bundled_dpath_pulsed", false);
dp->setParam ("di_dpath", false);
dp->setParam ("ditest_dpath", false);
}
else if (strcmp (family, "bdp") == 0) {
if (strcmp (nm, "sdt") == 0) {
fprintf (stderr, "bdp family not supported with sdt engine.\n");
return false;
}
dp->setParam ("bundled_dpath", true);
dp->setParam ("bundled_dpath_2phase", false);
dp->setParam ("bundled_dpath_pulsed", true);
dp->setParam ("di_dpath", false);
dp->setParam ("ditest_dpath", false);
}
else if (strcmp (family, "di") == 0) {
if (strcmp (nm, "sdt") == 0) {
fprintf (stderr, "di family not supported with sdt engine.\n");
return false;
}
dp->setParam ("bundled_dpath", false);
dp->setParam ("bundled_dpath_2phase", false);
dp->setParam ("bundled_dpath_pulsed", false);
dp->setParam ("di_dpath", true);
dp->setParam ("ditest_dpath", false);
}
else if (strcmp (family, "ditest") == 0) {
if (strcmp (nm, "sdt") == 0) {
fprintf (stderr, "ditest family not supported with sdt engine.\n");
return false;
}
dp->setParam ("bundled_dpath", false);
dp->setParam ("bundled_dpath_2phase", false);
dp->setParam ("bundled_dpath_pulsed", false);
dp->setParam ("di_dpath", false);
dp->setParam ("ditest_dpath", true);
}
else {
return false;
}
return true;
}
bool _set_engine (ActDynamicPass *dp, const char *engine)
{
bool found = false;
static struct {
const char *nm;
const char *prefix;
ActSynthesize *(*f) (const char *, char *, char *, char *);
} engines[] = {
{ "dataflow", "df", gen_df_engine },
{ "ring", "ring", gen_ring_engine },
{ "maelstrom", "ring", gen_ring_engine },
{ "sdt", "sdt", gen_sdt_engine },
{ "decomp", "decomp", gen_decomp_engine }
};
static const char *default_synth = "abc";
static const char *default_expr = "expr.act";
for (int i=0; !found && i < sizeof (engines)/sizeof(engines[0]); i++) {
if (strcmp (engines[i].nm, engine) == 0) {
/* set the engine */
dp->setParam ("engine_name", (void *) engines[i].nm);
dp->setParam ("engine", (void *) engines[i].f);
/* prefix for output process names */
dp->setParam ("prefix", (void *) engines[i].prefix);
/* for original SDT, there are basic unoptimized designs; but
not a great idea to use them! */
dp->setParam ("external_opt", 1);
/* combinational logic synthesis */
dp->setParam ("externopt_toolname", (void *) default_synth);
/* expression file */
dp->setParam ("expr", (void *) default_expr);
/* track execution time */
dp->setParam ("run_time", false);
found = true;
}
}
if (found) {
// set the default options
if (strcmp (engine, "ring") == 0 || strcmp (engine, "maelstrom") == 0) {
/* ring params */
dp->setParam ("datapath_style", false); /* SSA style is set */
dp->setParam ("delay_margin", 110); /* default 10% margin */
}
else if (strcmp (engine, "decomp") == 0) {
/* decomp params */
/* high cycle time target, so don't do anything by default */
dp->setParam ("cycle_time_target", 1000000.0);
/* no projection by default */
dp->setParam ("project", false);
}
return true;
}
fprintf (stderr, "Error; valid synthesis engines: ");
for (int i=0; i < sizeof (engines)/sizeof (engines[0]); i++) {
if (i != 0) {
fprintf (stderr, ", ");
}
fprintf (stderr, "%s", engines[i].nm);
}
fprintf (stderr, "\n");
return false;
}
int process_synth_init (int argc, char **argv)
{
ActDynamicPass *dp;
if (!std_argcheck ((argc == 2 ? 1 : argc), argv, 1, "[engine]",
STATE_EXPANDED)) {
return LISP_RET_ERROR;
}
dp = getSynthPass ();
if (!dp) {
fprintf (stderr, "%s: could not initialize synthesis pass.\n", argv[0]);
return LISP_RET_ERROR;
}
if (argc == 2) {
if (_set_engine (dp, argv[1])) {
_set_synth_defaults (dp, "qdi");
return LISP_RET_TRUE;
}
else {
fprintf (stderr, "%s: unknown synthesis engine `%s'.\n", argv[0],
argv[1]);
return LISP_RET_ERROR;
}
}
else {
if (!_set_engine (dp, "maelstrom")) {
fprintf (stderr,
"%s: Could not find default maelstrom synthesis engine.\n",
argv[0]);
return LISP_RET_ERROR;
}
}
_set_synth_defaults (dp, "qdi");
return LISP_RET_TRUE;
}
int process_synth_engine (int argc, char **argv)
{
ActDynamicPass *dp;
if (!std_argcheck (argc, argv, 3, "<name> <family>", STATE_EXPANDED)) {
return LISP_RET_ERROR;
}
dp = getSynthPass ();
if (!dp) {
fprintf (stderr, "%s: could not initialize synthesis pass.\n", argv[0]);
return LISP_RET_ERROR;
}
if (_set_engine (dp, argv[1])) {
if (_set_synth_defaults (dp, argv[2])) {
return LISP_RET_TRUE;
}
fprintf (stderr, "%s: unknown circuit family `%s'.\n", argv[0],
argv[2]);
return LISP_RET_ERROR;
}
else {
fprintf (stderr, "%s: unknown synthesis engine `%s'.\n", argv[0],
argv[1]);
return LISP_RET_ERROR;
}
}
int process_synth_family (int argc, char **argv)
{
ActDynamicPass *dp;
if (!std_argcheck (argc, argv, 2, "<name>", STATE_EXPANDED)) {
return LISP_RET_ERROR;
}
dp = getSynthPass ();
if (!dp) {
fprintf (stderr, "%s: could not initialize synthesis pass.\n", argv[0]);
return LISP_RET_ERROR;
}
if (!_set_synth_defaults (dp, argv[1])) {
fprintf (stderr, "%s: invalid family. Options are qdi, bd, bd2, bdp, di, ditest.\n", argv[0]);
return LISP_RET_ERROR;
}
return LISP_RET_TRUE;
}
int process_synth_expropt (int argc, char **argv)
{
ActDynamicPass *dp;
if (!std_argcheck (argc, argv, 2, "<name>", STATE_EXPANDED)) {
return LISP_RET_ERROR;
}
dp = getSynthPass ();
if (!dp) {
fprintf (stderr, "%s: could not initialize synthesis pass.\n", argv[0]);
return LISP_RET_ERROR;
}
if (ExternalExprOpt::engineExists (argv[1])) {
dp->setParam ("externopt_toolname", (void *) Strdup (argv[1]));
dp->setParam ("external_opt", 1);
}
else {
fprintf (stderr, "%s: could not find logic optimization library for `%s'\n",
argv[0], argv[1]);
return LISP_RET_ERROR;
}
return LISP_RET_TRUE;
}
int process_synth_exprfile (int argc, char **argv)
{
ActDynamicPass *dp;
if (!std_argcheck (argc, argv, 2, "<name>", STATE_EXPANDED)) {
return LISP_RET_ERROR;
}
dp = getSynthPass ();
if (!dp) {
fprintf (stderr, "%s: could not initialize synthesis pass.\n", argv[0]);
return LISP_RET_ERROR;
}
dp->setParam ("expr", (void *) Strdup (argv[1]));
return LISP_RET_TRUE;
}
int process_synth_run (int argc, char **argv)
{
ActDynamicPass *dp;
if (!std_argcheck ((argc == 2 ? 1 : argc), argv, 1, "[outfile]", STATE_EXPANDED)) {
return LISP_RET_ERROR;
}
dp = getSynthPass ();
if (!dp) {
fprintf (stderr, "%s: could not initialize synthesis pass.\n", argv[0]);
return LISP_RET_ERROR;
}
if (F.act_toplevel == NULL) {
fprintf (stderr, "%s: no top-level process specified\n", argv[0]);
return LISP_RET_ERROR;
}
if (argc == 2) {
dp->setParam ("out", (void *) Strdup (argv[1]));
}
else {
dp->setParam ("out", (void *) NULL);
}
dp->run (F.act_toplevel);
return LISP_RET_TRUE;
}
struct LispCliCommand synth_cmds[] = {
{ NULL, "ACT logic synthesis", NULL },
{ "init", "[engine] - initialize synthesis engine; default circuit family is qdi", process_synth_init },
{ "engine", "<name> <family> - set synthesis engine to <name>, circuit family to <family>", process_synth_engine },
{ "expropt", "<name> - set name of external combinational logic optimization engine",
process_synth_expropt },
{ "exprfile", "<name> - set name of ACT file for synthesized expressions",
process_synth_exprfile },
{ "run", "[outfile] - run sythesis pass, saving the results in the specified output", process_synth_run }
};
}
void synth_cmds_init (void)
{
LispCliAddCommands ("synth", synth_cmds, sizeof (synth_cmds)/sizeof (synth_cmds[0]));
}