My Project
Dataflow.h
1 #ifndef DATAFLOW_H
2 #define DATAFLOW_H
3 
4 #include <list>
5 #include <set>
6 #include <string>
7 #include <vector>
8 
9 namespace Dataflow
10 {
11 
12 // Identifiers for the main objects of a dataflow system.
13 // Functions, blocks, channels, ports and basic blocks are represented by a unique identifier.
14 // (integers starting from 0). Each type has a different space of identifiers.
15 // Eventually, the range of id's can be sparse, i.e., when functions, blocks,
16 // channels and ports are removed, the original id's do not change.
17 
18 const int invalidDataflowID = -1;
19 
20 using funcID = int;
21 using blockID = int;
22 using channelID = int;
23 using portID = int;
24 
25 // Collections of dataflow objects
26 
27 using vecFuncs = std::vector<funcID>;
28 using setFuncs = std::set<funcID>;
29 using listFuncs = std::list<funcID>;
30 using vecBlocks = std::vector<blockID>;
31 using setBlocks = std::set<blockID>;
32 using listBlocks = std::list<blockID>;
33 using vecPorts = std::vector<portID>;
34 using setPorts = std::set<portID>;
35 using listPorts = std::list<portID>;
36 using vecChannels = std::vector<channelID>;
37 using setChannels = std::set<channelID>;
38 using listChannels = std::list<channelID>;
39 
43 enum BlockType {OPERATOR,
44  ELASTIC_BUFFER,
45  FORK,
46  BRANCH,
47  MERGE,
48  DEMUX,
49  SELECT,
50  CONSTANT,
51  FUNC_ENTRY,
52  FUNC_EXIT,
53  SOURCE,
54  SINK,
55  MUX,
56  CNTRL_MG,
57  LSQ,
58  MC,
59  DISTRIBUTOR,
60  SELECTOR,
61  UNKNOWN
62  };
63 
68 enum PortType {GENERIC_PORT, // Most ports will be generic
69  SELECTION_PORT, // Selection port for branch/select/demux blocks
70  TRUE_PORT, // True port for branch and select blocks
71  FALSE_PORT // False port for branch and select blocks
72  };
73 
75 enum PortDirection {INPUT_PORTS,
76  OUTPUT_PORTS,
77  ALL_PORTS
78  };
79 
80 class DFnetlist_Impl;
81 class DFlib_Impl;
82 
83 class DFnetlist
84 {
85 
86 public:
87  DFnetlist_Impl* DFI;
88 
92  DFnetlist();
93 
97  ~DFnetlist();
98 
103  DFnetlist(const std::string& name);
104 
110  DFnetlist(FILE* file);
111 
119  DFnetlist(const std::string& name, const std::string& name_bb);
120 
124  DFnetlist(const DFnetlist& other);
125 
130  void setMilpSolver(const std::string& solver = "cbc");
131 
137  bool check();
138 
142  const std::string& getName() const;
143 
150  blockID createBlock(BlockType type, const std::string& name = "");
151 
157  blockID getBlock(const std::string& name) const;
158 
164  const std::string& getBlockName(blockID id) const;
165 
171  double getBlockDelay(blockID id, int indx) const;
172 
178  void setBlockDelay(blockID id, double d, int indx);
179 
180  double getBlockRetimingDiff(blockID id) const;
181 
182  void setBlockRetimingDiff(blockID id, double retimingDiff);
183 
184 
190  int getLatency(blockID id) const;
191 
197  void setLatency(blockID id, int lat);
198 
204  int getInitiationInterval(blockID id) const;
205 
211  void setInitiationInterval(blockID id, int ii);
212 
218  void setExecutionFrequency(blockID id, double freq);
219 
225  int getExecutionFrequency(blockID id) const;
226 
232  void setTrueFrac(blockID id, double freq);
233 
234  double getTrueFrac(blockID id) const;
235 
241  int getBufferSize(blockID id) const;
242 
248  void setBufferSize(blockID id, int slots);
249 
255  bool isBufferTransparent(blockID id) const;
256 
262  void setBufferTransparency(blockID id, bool value);
263 
268  blockID getBlockFromPort(portID p) const;
269 
274  void removeBlock(blockID block);
275 
286  portID createPort(blockID block, bool isInput, const std::string& name="", int width = -1, PortType type = GENERIC_PORT);
287 
292  void removePort(portID port);
293 
300  portID getPort(blockID block, const std::string& name) const;
301 
308  const std::string& getPortName(portID port, bool full=true) const;
309 
315  PortType getPortType(portID port) const;
316 
322  bool isInputPort(portID port) const;
323 
329  bool isOutputPort(portID port) const;
330 
336  int getPortWidth(portID port) const;
337 
343  bool isBooleanPort(portID port) const;
344 
350  bool isControlPort(portID port) const;
351 
357  double getPortDelay(portID port) const;
358 
364  void setPortDelay(portID port, double d);
365 
372  const setPorts& getPorts(blockID id, PortDirection dir) const;
373 
378  portID getConditionalPort(blockID id) const;
379 
384  portID getTruePort(blockID id) const;
385 
390  portID getFalsePort(blockID id) const;
391 
396  portID getDemuxDataPort(blockID id) const;
397 
405  portID getDemuxComplementaryPort(portID port) const;
406 
412  channelID getConnectedChannel(portID port) const;
413 
419  BlockType getBlockType(blockID block) const;
420 
426  bool isPortConnected(portID port) const;
427 
433  portID getConnectedPort(portID port) const;
434 
441  channelID createChannel(portID src, portID dst);
442 
448  portID getSrcPort(channelID id) const;
449 
455  portID getDstPort(channelID id) const;
456 
461  void removeChannel(channelID id);
462 
470  std::string getChannelName(channelID id, bool full=true) const;
471 
477  channelID getChannelID(portID id); //Carmine 09.03.22 new function
478 
484  int getChannelBufferSize(channelID id) const;
485 
491  void setChannelBufferSize(blockID id, int slots);
492 
498  bool isChannelTransparent(channelID id) const;
499 
505  void setChannelTransparency(channelID id, bool value);
506 
511  void setChannelEB(channelID id);
512 
517  bool getChannelEB(channelID id);
518 
519  void setChannelFrequency(channelID id, double value);
520 
521  double getChannelFrequency(channelID id);
522 
528  bool hasBuffer(channelID id) const;
529 
538  blockID insertBuffer(channelID c, int slots, bool transparent);
539 
549  blockID insertBuffer(channelID c, int slots, bool transparent, bool EB);
550 
555  void removeBuffer(blockID buf);
556 
561  void setError(const std::string& err);
562 
566  const std::string& getError() const;
567 
571  void clearError();
572 
577  bool hasError() const;
578 
582  int numBlocks() const;
583 
587  int numChannels() const;
588 
592  int numPorts() const;
593 
598  bool validPort(portID p) const;
599 
605  bool validBlock(blockID id) const;
606 
612  bool validChannel(channelID id) const;
613 
617  void reduceMerges(); //Carmine 09.03.22 new function
618 
625  bool writeDot(const std::string& filename = "");
626 
632  bool writeDot(std::ostream& s);
633 
634  bool writeDotMG(const std::string& filename = "");
635  bool writeDotMG(std::ostream& s);
636 
637  bool writeDotBB(std::ostream& s);
638  bool writeDotBB(const std::string& filename = "");
639 
646  bool writeBasicBlockDot(const std::string& filename = "");
647 
653  bool writeBasicBlockDot(std::ostream& s);
654 
663  bool addElasticBuffers(double Period = 0, double BufferDelay = 0, bool maxThroughput = false, double coverage = 0);
664 
665  bool addElasticBuffersBB(double Period = 0, double BufferDelay = 0, bool maxThroughput = false, double coverage = 0, int timeout = -1, bool first_MG = false);
666 
667  bool addElasticBuffersBB_sc(double Period = 0, double BufferDelay = 0, bool maxThroughput = false, double coverage = 0, int timeout = -1, bool first_MG = false, const std::string& model_mode = "default", const std::string& lib_path="");
668 
674 
678  void instantiateAdditionalElasticBuffers(const std::string& filename);
679 
683  void hideElasticBuffers();
684 
688  void cleanElasticBuffers();
689 
694  void eraseNonSCC();
695 
696  void computeSCC(bool onlyMarked);
697 
698  void printBlockSCCs();
699 
704  bool calculateBasicBlocks();
705 
711  bool optimize();
712 
717  bool removeControl();
718 
725  double extractMarkedGraphs(double coverage);
726 };
727 
728 class DFlib
729 {
730 
731  DFlib_Impl* DFLI;
732 
733 public:
737  DFlib();
738 
742  ~DFlib();
743 
748  DFlib(const std::string& name);
749 
750 
756  bool add(const std::string& filename);
757 
764  bool writeDot(const std::string& filename = "");
765 
770  void setError(const std::string& err);
771 
775  const std::string& getError() const;
776 
780  void clearError();
781 
786  bool hasError() const;
787 
791  int numFuncs() const;
792 
798  funcID getFuncID(const std::string& fname) const;
799 
805  DFnetlist& operator[](const std::string& fname);
806 
812  const DFnetlist& operator[](const std::string& fname) const;
813 
819  DFnetlist& operator[](funcID id);
820 
826  const DFnetlist& operator[](funcID id) const;
827 };
828 
829 }
830 #endif // DATAFLOW_H
bool validChannel(channelID id) const
Indicates whether a channel id is valid.
Definition: Dataflow.cpp:376
int getBufferSize(blockID id) const
Returns the number of slots of an elastic buffer.
Definition: Dataflow.cpp:107
portID getConnectedPort(portID port) const
Returns the opposite port connected to the same channel.
Definition: Dataflow.cpp:242
bool removeControl()
Remove the control (synchronization) blocks of the dataflow netlist.
Definition: Dataflow.cpp:476
portID getDemuxDataPort(blockID id) const
Definition: Dataflow.cpp:217
portID getSrcPort(channelID id) const
Returns the source port of a channel.
Definition: Dataflow.cpp:252
portID getPort(blockID block, const std::string &name) const
Returns the id of a port from a given block and pin name.
Definition: Dataflow.cpp:147
bool isOutputPort(portID port) const
Indicates whether a port is output.
Definition: Dataflow.cpp:167
Definition: Dataflow.h:9
Definition: Dataflow.h:728
int getPortWidth(portID port) const
Returns the width of a port.
Definition: Dataflow.cpp:172
portID getTruePort(blockID id) const
Definition: Dataflow.cpp:207
portID getConditionalPort(blockID id) const
Definition: Dataflow.cpp:202
void eraseNonSCC()
Removes all non-SCC blocks and channels.
Definition: Dataflow.cpp:461
void clearError()
Erases the error.
Definition: Dataflow.cpp:341
void setBlockDelay(blockID id, double d, int indx)
Sets the delay of a block.
Definition: Dataflow.cpp:52
bool calculateBasicBlocks()
Calculates the Basic Blocks of the netlist.
Definition: Dataflow.cpp:466
bool isChannelTransparent(channelID id) const
Checks whether the buffer of the channel is transparent.
Definition: Dataflow.cpp:282
bool addElasticBuffers(double Period=0, double BufferDelay=0, bool maxThroughput=false, double coverage=0)
Adds elastic buffers to meet a certain cycle period and have elasticity in the system.
Definition: Dataflow.cpp:426
void setInitiationInterval(blockID id, int ii)
Sets the initiation interval of a block.
Definition: Dataflow.cpp:82
int numChannels() const
Definition: Dataflow.cpp:356
int getInitiationInterval(blockID id) const
Returns the initiation interval of a block.
Definition: Dataflow.cpp:77
channelID getConnectedChannel(portID port) const
Returns the channel associated to a port.
Definition: Dataflow.cpp:227
bool isBooleanPort(portID port) const
Checks whether a port is Boolean.
Definition: Dataflow.cpp:177
void setBufferTransparency(blockID id, bool value)
Sets the transparency of an elastic buffer.
Definition: Dataflow.cpp:122
bool writeBasicBlockDot(const std::string &filename="")
Writes the Basic Blocks of the dataflow netlist in dot format.
void setMilpSolver(const std::string &solver="cbc")
Sets the solver for MILP optimization problems.
Definition: Dataflow.cpp:421
const setPorts & getPorts(blockID id, PortDirection dir) const
Returns the set of ports with a certain direction.
Definition: Dataflow.cpp:197
void setChannelEB(channelID id)
Sets the presence of an EB on the channel.
Definition: Dataflow.cpp:293
bool isBufferTransparent(blockID id) const
Checks whether the buffer is transparent.
Definition: Dataflow.cpp:117
blockID createBlock(BlockType type, const std::string &name="")
Creates a new block in the netlist.
Definition: Dataflow.cpp:32
bool hasError() const
Indicates whether there is an error.
Definition: Dataflow.cpp:346
blockID getBlock(const std::string &name) const
Returns a block id of the netlist.
Definition: Dataflow.cpp:37
void cleanElasticBuffers()
Removes all the elastic buffers from the netlist.
Definition: Dataflow.cpp:456
bool isControlPort(portID port) const
Checks whether a port is a control port.
Definition: Dataflow.cpp:182
const std::string & getError() const
Definition: Dataflow.cpp:336
bool writeDot(const std::string &filename="")
Writes the dataflow netlist in dot format.
Definition: DFnetlist.h:417
void removePort(portID port)
Removes a port and the associated channels from the netlist.
Definition: Dataflow.cpp:142
DFnetlist()
Implementation of DFnet;.
Definition: Dataflow.cpp:7
void setChannelBufferSize(blockID id, int slots)
Sets the number of slots of the elastic buffer in the channel.
Definition: Dataflow.cpp:277
Definition: Dataflow.h:83
void setError(const std::string &err)
Sets an error message for the netlist.
Definition: Dataflow.cpp:331
bool check()
Checks that the netlist is well-formed.
Definition: Dataflow.cpp:22
std::string getChannelName(channelID id, bool full=true) const
Returns the name of the channel.
Definition: Dataflow.cpp:267
bool optimize()
Performs different types of optimizations to reduce the complexity of the dataflow netlist...
Definition: Dataflow.cpp:471
void setPortDelay(portID port, double d)
Sets the delay of a port.
Definition: Dataflow.cpp:192
~DFnetlist()
Default destructor.
Definition: Dataflow.cpp:17
void setBufferSize(blockID id, int slots)
Sets the number of slots of an elastic buffer.
Definition: Dataflow.cpp:112
portID getDemuxComplementaryPort(portID port) const
Returns the complementary port associated to one of the ports of a demux. If the parameter is an inpu...
Definition: Dataflow.cpp:222
bool validPort(portID p) const
Definition: Dataflow.cpp:366
bool isInputPort(portID port) const
Indicates whether a port is input.
Definition: Dataflow.cpp:162
void instantiateAdditionalElasticBuffers(const std::string &filename)
Creates buffers for all those channels annotated inside input file. // Carmine 09.02.22.
Definition: Dataflow.cpp:446
bool isPortConnected(portID port) const
Checks whether a port is connected.
Definition: Dataflow.cpp:237
bool validBlock(blockID id) const
Indicates whether a block id is valid.
Definition: Dataflow.cpp:371
blockID getBlockFromPort(portID p) const
Definition: Dataflow.cpp:127
Definition: DFnetlist.h:2214
const std::string & getBlockName(blockID id) const
Returns the name of a block.
Definition: Dataflow.cpp:42
portID getFalsePort(blockID id) const
Definition: Dataflow.cpp:212
portID getDstPort(channelID id) const
Returns the destination port of a channel.
Definition: Dataflow.cpp:257
void removeBuffer(blockID buf)
Removes a buffer and reconnects the input and output channels.
Definition: Dataflow.cpp:326
double extractMarkedGraphs(double coverage)
Extracts a set of marked graphs from the netlist until a certain coverage of execution frequency is a...
Definition: Dataflow.cpp:481
bool getChannelEB(channelID id)
Gets the presence of an EB on the channel.
Definition: Dataflow.cpp:298
const std::string & getName() const
Definition: Dataflow.cpp:27
int getChannelBufferSize(channelID id) const
Returns the number of slots of the elastic buffer in the channel.
Definition: Dataflow.cpp:272
double getBlockDelay(blockID id, int indx) const
Returns the delay of a block.
Definition: Dataflow.cpp:47
void hideElasticBuffers()
Removes the elastic buffers and transfers the information to the channels.
Definition: Dataflow.cpp:451
portID createPort(blockID block, bool isInput, const std::string &name="", int width=-1, PortType type=GENERIC_PORT)
Adds a new port to a block.
Definition: Dataflow.cpp:137
channelID getChannelID(portID id)
Returns the channel ID.
void removeBlock(blockID block)
Removes a block and all the associated channels from the netlist.
Definition: Dataflow.cpp:132
int numBlocks() const
Definition: Dataflow.cpp:351
void setTrueFrac(blockID id, double freq)
Sets the true/false exe. fraction of a select op.
Definition: Dataflow.cpp:97
double getPortDelay(portID port) const
Returns the delay of a port.
Definition: Dataflow.cpp:187
int numPorts() const
Definition: Dataflow.cpp:361
channelID createChannel(portID src, portID dst)
Creates a channel between two ports.
Definition: Dataflow.cpp:247
void removeChannel(channelID id)
Removes a channel.
Definition: Dataflow.cpp:262
const std::string & getPortName(portID port, bool full=true) const
Returns the name of a port.
Definition: Dataflow.cpp:152
blockID insertBuffer(channelID c, int slots, bool transparent)
Inserts a buffer in a channel. The insertion removes the previous channel and creates two new channel...
Definition: Dataflow.cpp:316
void setExecutionFrequency(blockID id, double freq)
Sets the execution frequency of a block.
Definition: Dataflow.cpp:92
void instantiateElasticBuffers()
Creates buffers for all those channels annotated with buffers. The information in the channels is del...
Definition: Dataflow.cpp:441
void setLatency(blockID id, int lat)
Sets the latency of a block.
Definition: Dataflow.cpp:72
void setChannelTransparency(channelID id, bool value)
Sets the transparency of the elastic buffer in the channel.
Definition: Dataflow.cpp:288
bool hasBuffer(channelID id) const
Checks whether a channel has an elastic buffer (slots > 0).
Definition: Dataflow.cpp:311
BlockType getBlockType(blockID block) const
Returns the block type associated to a block.
Definition: Dataflow.cpp:232
PortType getPortType(portID port) const
Returns the type of a port.
Definition: Dataflow.cpp:157
int getLatency(blockID id) const
Returns the latency of a block.
Definition: Dataflow.cpp:67
void reduceMerges()
Reduce the number of merges since 1 input merges can be reduced to a wire.
Definition: Dataflow.cpp:417
int getExecutionFrequency(blockID id) const
Returns the execution frequency of a block.
Definition: Dataflow.cpp:87