1/* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22#include "model/network/ElectricalClos.h"
23
24#include <cmath>
25
26#include "model/ModelGen.h"
27#include "model/timing_graph/ElectricalTimingTree.h"
28#include "model/timing_graph/ElectricalNet.h"
29
30namespace DSENT
31{
32    using std::sqrt;
33
34    ElectricalClos::ElectricalClos(const String& instance_name_, const TechModel* tech_model_)
35        : ElectricalModel(instance_name_, tech_model_)
36    {
37        initParameters();
38        initProperties();
39    }
40
41    ElectricalClos::~ElectricalClos()
42    {}
43
44    void ElectricalClos::initParameters()
45    {
46        // Frequency
47        addParameterName("Frequency");
48        // Physical Parameters
49        addParameterName("NumberInputSites");
50        addParameterName("NumberOutputSites");
51        addParameterName("NumberBitsPerFlit");
52        // Number of each type of routers
53        addParameterName("NumberIngressRouters");
54        addParameterName("NumberMiddleRouters");
55        addParameterName("NumberEgressRouters");
56        // Router parameters
57        addParameterName("Router->NumberVirtualNetworks");
58        addParameterName("Router->NumberVirtualChannelsPerVirtualNetwork");
59        addParameterName("Router->NumberBuffersPerVirtualChannel");
60        addParameterName("Router->InputPort->BufferModel");
61        addParameterName("Router->CrossbarModel");
62        addParameterName("Router->SwitchAllocator->ArbiterModel");
63        addParameterName("Router->ClockTreeModel");
64        addParameterName("Router->ClockTree->NumberLevels");
65        addParameterName("Router->ClockTree->WireLayer");
66        addParameterName("Router->ClockTree->WireWidthMultiplier");
67        addParameterName("Router->ClockTree->WireSpacingMultiplier", 3.0);
68        // Link parameters
69        addParameterName("Link->WireLayer");
70        addParameterName("Link->WireWidthMultiplier");
71        addParameterName("Link->WireSpacingMultiplier");
72        return;
73    }
74
75    void ElectricalClos::initProperties()
76    {
77        addPropertyName("InputSitePitch");
78        addPropertyName("OutputSitePitch");
79        return;
80    }
81
82    ElectricalClos* ElectricalClos::clone() const
83    {
84        // TODO
85        return NULL;
86    }
87
88    void ElectricalClos::constructModel()
89    {
90        // Get input parameters
91        unsigned int number_input_sites = getParameter("NumberInputSites").toUInt();
92        unsigned int number_output_sites = getParameter("NumberOutputSites").toUInt();
93        unsigned int number_bits_per_flit = getParameter("NumberBitsPerFlit").toUInt();
94        unsigned int number_ingress_routers = getParameter("NumberIngressRouters").toUInt();
95        unsigned int number_middle_routers = getParameter("NumberMiddleRouters").toUInt();
96        unsigned int number_egress_routers = getParameter("NumberEgressRouters").toUInt();
97
98        ASSERT(number_input_sites > 0, "[Error] " + getInstanceName() +
99                " -> Number of input sites must be > 0!");
100        ASSERT(number_output_sites > 0, "[Error] " + getInstanceName() +
101                " -> Number of output sites must be > 0!");
102        ASSERT(number_bits_per_flit > 0, "[Error] " + getInstanceName() +
103                " -> Number of bits per flit must be > 0!");
104        ASSERT(number_ingress_routers > 0, "[Error] " + getInstanceName() +
105                " -> Number of ingress routers must be > 0!");
106        ASSERT(number_middle_routers > 0, "[Error] " + getInstanceName() +
107                " -> Number of middle routers must be > 0!");
108        ASSERT(number_egress_routers > 0, "[Error] " + getInstanceName() +
109                " -> Number of egress routers must be > 0!");
110
111        // Get input parameters that will be forwarded to the sub instances
112        const String& router_number_vns = getParameter("Router->NumberVirtualNetworks");
113        const String& router_number_vcs_per_vn = getParameter("Router->NumberVirtualChannelsPerVirtualNetwork");
114        const String& router_number_bufs_per_vc = getParameter("Router->NumberBuffersPerVirtualChannel");
115        const String& router_buffer_model = getParameter("Router->InputPort->BufferModel");
116        const String& router_crossbar_model = getParameter("Router->CrossbarModel");
117        const String& link_wire_layer = getParameter("Link->WireLayer");
118        const String& link_wire_width_multiplier = getParameter("Link->WireWidthMultiplier");
119        const String& link_wire_spacing_multiplier = getParameter("Link->WireSpacingMultiplier");
120
121        // Calculate properties from input parameters
122        unsigned int ingress_router_number_input_ports = number_input_sites / number_ingress_routers;
123        unsigned int ingress_router_number_output_ports = number_middle_routers;
124        unsigned int middle_router_number_input_ports = number_ingress_routers;
125        unsigned int middle_router_number_output_ports = number_egress_routers;
126        unsigned int egress_router_number_input_ports = number_middle_routers;
127        unsigned int egress_router_number_output_ports = number_output_sites / number_egress_routers;
128        unsigned int number_input_to_ingress_links = number_input_sites;
129        unsigned int number_ingress_to_middle_links = number_ingress_routers * number_middle_routers;
130        unsigned int number_middle_to_egress_links = number_middle_routers * number_egress_routers;
131        unsigned int number_egress_to_output_links = number_output_sites;
132
133        getGenProperties()->set("NumberInputSitesPerIngressRouter", ingress_router_number_input_ports);
134        getGenProperties()->set("NumberOutputSitesPerEgressRouter", egress_router_number_output_ports);
135        getGenProperties()->set("IngressRouter->NumberInputPorts", ingress_router_number_input_ports);
136        getGenProperties()->set("IngressRouter->NumberOutputPorts", ingress_router_number_output_ports);
137        getGenProperties()->set("MiddleRouter->NumberInputPorts", middle_router_number_input_ports);
138        getGenProperties()->set("MiddleRouter->NumberOutputPorts", middle_router_number_output_ports);
139        getGenProperties()->set("EgressRouter->NumberInputPorts", egress_router_number_input_ports);
140        getGenProperties()->set("EgressRouter->NumberOutputPorts", egress_router_number_output_ports);
141
142        // Create ports
143        createInputPort("CK");
144
145        // Init ingress router
146        ElectricalModel* ingress_router = (ElectricalModel*)ModelGen::createModel("Router", "IngressRouter", getTechModel());
147        ingress_router->setParameter("NumberInputPorts", ingress_router_number_input_ports);
148        ingress_router->setParameter("NumberOutputPorts", ingress_router_number_output_ports);
149        ingress_router->setParameter("NumberVirtualNetworks", router_number_vns);
150        ingress_router->setParameter("NumberVirtualChannelsPerVirtualNetwork", router_number_vcs_per_vn);
151        ingress_router->setParameter("NumberBuffersPerVirtualChannel", router_number_bufs_per_vc);
152        ingress_router->setParameter("NumberBitsPerFlit", number_bits_per_flit);
153        ingress_router->setParameter("InputPort->BufferModel", router_buffer_model);
154        ingress_router->setParameter("CrossbarModel", router_crossbar_model);
155        ingress_router->setParameter("SwitchAllocator->ArbiterModel", getParameter("Router->SwitchAllocator->ArbiterModel"));
156        ingress_router->setParameter("ClockTreeModel", getParameter("Router->ClockTreeModel"));
157        ingress_router->setParameter("ClockTree->NumberLevels", getParameter("Router->ClockTree->NumberLevels"));
158        ingress_router->setParameter("ClockTree->WireLayer", getParameter("Router->ClockTree->WireLayer"));
159        ingress_router->setParameter("ClockTree->WireWidthMultiplier", getParameter("Router->ClockTree->WireWidthMultiplier"));
160        ingress_router->setParameter("ClockTree->WireSpacingMultiplier", getParameter("Router->ClockTree->WireSpacingMultiplier"));
161        ingress_router->construct();
162        // Init middle routers
163        ElectricalModel* middle_router = (ElectricalModel*)ModelGen::createModel("Router", "MiddleRouter", getTechModel());
164        middle_router->setParameter("NumberInputPorts", middle_router_number_input_ports);
165        middle_router->setParameter("NumberOutputPorts", middle_router_number_output_ports);
166        middle_router->setParameter("NumberVirtualNetworks", router_number_vns);
167        middle_router->setParameter("NumberVirtualChannelsPerVirtualNetwork", router_number_vcs_per_vn);
168        middle_router->setParameter("NumberBuffersPerVirtualChannel", router_number_bufs_per_vc);
169        middle_router->setParameter("NumberBitsPerFlit", number_bits_per_flit);
170        middle_router->setParameter("InputPort->BufferModel", router_buffer_model);
171        middle_router->setParameter("CrossbarModel", router_crossbar_model);
172        middle_router->setParameter("SwitchAllocator->ArbiterModel", getParameter("Router->SwitchAllocator->ArbiterModel"));
173        middle_router->setParameter("ClockTreeModel", getParameter("Router->ClockTreeModel"));
174        middle_router->setParameter("ClockTree->NumberLevels", getParameter("Router->ClockTree->NumberLevels"));
175        middle_router->setParameter("ClockTree->WireLayer", getParameter("Router->ClockTree->WireLayer"));
176        middle_router->setParameter("ClockTree->WireWidthMultiplier", getParameter("Router->ClockTree->WireWidthMultiplier"));
177        middle_router->setParameter("ClockTree->WireSpacingMultiplier", getParameter("Router->ClockTree->WireSpacingMultiplier"));
178        middle_router->construct();
179        // Init egress routers
180        ElectricalModel* egress_router = (ElectricalModel*)ModelGen::createModel("Router", "EgressRouter", getTechModel());
181        egress_router->setParameter("NumberInputPorts", egress_router_number_input_ports);
182        egress_router->setParameter("NumberOutputPorts", egress_router_number_output_ports);
183        egress_router->setParameter("NumberVirtualNetworks", router_number_vns);
184        egress_router->setParameter("NumberVirtualChannelsPerVirtualNetwork", router_number_vcs_per_vn);
185        egress_router->setParameter("NumberBuffersPerVirtualChannel", router_number_bufs_per_vc);
186        egress_router->setParameter("NumberBitsPerFlit", number_bits_per_flit);
187        egress_router->setParameter("InputPort->BufferModel", router_buffer_model);
188        egress_router->setParameter("CrossbarModel", router_crossbar_model);
189        egress_router->setParameter("SwitchAllocator->ArbiterModel", getParameter("Router->SwitchAllocator->ArbiterModel"));
190        egress_router->setParameter("ClockTreeModel", getParameter("Router->ClockTreeModel"));
191        egress_router->setParameter("ClockTree->NumberLevels", getParameter("Router->ClockTree->NumberLevels"));
192        egress_router->setParameter("ClockTree->WireLayer", getParameter("Router->ClockTree->WireLayer"));
193        egress_router->setParameter("ClockTree->WireWidthMultiplier", getParameter("Router->ClockTree->WireWidthMultiplier"));
194        egress_router->setParameter("ClockTree->WireSpacingMultiplier", getParameter("Router->ClockTree->WireSpacingMultiplier"));
195        egress_router->construct();
196        // Init input to ingress link
197        ElectricalModel* input_to_ingress_link = (ElectricalModel*)ModelGen::createModel("RepeatedLink", "InputToIngressLink", getTechModel());
198        input_to_ingress_link->setParameter("NumberBits", number_bits_per_flit);
199        input_to_ingress_link->setParameter("WireLayer", link_wire_layer);
200        input_to_ingress_link->setParameter("WireWidthMultiplier", link_wire_width_multiplier);
201        input_to_ingress_link->setParameter("WireSpacingMultiplier", link_wire_spacing_multiplier);
202        input_to_ingress_link->construct();
203        // Init ingress to middle link
204        ElectricalModel* ingress_to_middle_link = (ElectricalModel*)ModelGen::createModel("RepeatedLink", "IngressToMiddleLink", getTechModel());
205        ingress_to_middle_link->setParameter("NumberBits", number_bits_per_flit);
206        ingress_to_middle_link->setParameter("WireLayer", link_wire_layer);
207        ingress_to_middle_link->setParameter("WireWidthMultiplier", link_wire_width_multiplier);
208        ingress_to_middle_link->setParameter("WireSpacingMultiplier", link_wire_spacing_multiplier);
209        ingress_to_middle_link->construct();
210        // Init middle to egress link
211        ElectricalModel* middle_to_egress_link = (ElectricalModel*)ModelGen::createModel("RepeatedLink", "MiddleToEgressLink", getTechModel());
212        middle_to_egress_link->setParameter("NumberBits", number_bits_per_flit);
213        middle_to_egress_link->setParameter("WireLayer", link_wire_layer);
214        middle_to_egress_link->setParameter("WireWidthMultiplier", link_wire_width_multiplier);
215        middle_to_egress_link->setParameter("WireSpacingMultiplier", link_wire_spacing_multiplier);
216        middle_to_egress_link->construct();
217        // Init egress to output link
218        ElectricalModel* egress_to_output_link = (ElectricalModel*)ModelGen::createModel("RepeatedLink", "EgressToOutputLink", getTechModel());
219        egress_to_output_link->setParameter("NumberBits", number_bits_per_flit);
220        egress_to_output_link->setParameter("WireLayer", link_wire_layer);
221        egress_to_output_link->setParameter("WireWidthMultiplier", link_wire_width_multiplier);
222        egress_to_output_link->setParameter("WireSpacingMultiplier", link_wire_spacing_multiplier);
223        egress_to_output_link->construct();
224
225        // Connect ports
226        createNet("InputToIngressLink_Out", makeNetIndex(0, number_bits_per_flit-1));
227        createNet("InputToIngressLink_In", makeNetIndex(0, number_bits_per_flit-1));
228        portConnect(input_to_ingress_link, "In", "InputToIngressLink_In");
229        portConnect(input_to_ingress_link, "Out", "InputToIngressLink_Out");
230
231        createNet("IngressToMiddleLink_In", makeNetIndex(0, number_bits_per_flit-1));
232        createNet("IngressToMiddleLink_Out", makeNetIndex(0, number_bits_per_flit-1));
233        portConnect(ingress_to_middle_link, "In", "IngressToMiddleLink_In");
234        portConnect(ingress_to_middle_link, "Out", "IngressToMiddleLink_Out");
235
236        createNet("MiddleToEgressLink_In", makeNetIndex(0, number_bits_per_flit-1));
237        createNet("MiddleToEgressLink_Out", makeNetIndex(0, number_bits_per_flit-1));
238        portConnect(middle_to_egress_link, "In", "MiddleToEgressLink_In");
239        portConnect(middle_to_egress_link, "Out", "MiddleToEgressLink_Out");
240
241        createNet("EgressToOutputLink_In", makeNetIndex(0, number_bits_per_flit-1));
242        createNet("EgressToOutputLink_Out", makeNetIndex(0, number_bits_per_flit-1));
243        portConnect(egress_to_output_link, "In", "EgressToOutputLink_In");
244        portConnect(egress_to_output_link, "Out", "EgressToOutputLink_Out");
245
246
247        portConnect(ingress_router, "CK", "CK");
248        for(unsigned int i = 0; i < ingress_router_number_input_ports; ++i)
249        {
250            createNet("IngressRouter_In" + (String)i, makeNetIndex(0, number_bits_per_flit-1));
251            for (unsigned int j = 0; j < number_bits_per_flit; ++j)
252                assignVirtualFanout("IngressRouter_In" + (String)i, makeNetIndex(j), "InputToIngressLink_Out", makeNetIndex(j));
253            portConnect(ingress_router, "FlitIn" + (String)i, "IngressRouter_In" + (String)i);
254        }
255        for(unsigned int i = 0; i < ingress_router_number_output_ports; ++i)
256        {
257            // VFI
258            portConnect(ingress_router, "FlitOut" + (String)i, "IngressToMiddleLink_In");
259        }
260
261        portConnect(middle_router, "CK", "CK");
262        for(unsigned int i = 0; i < middle_router_number_input_ports; ++i)
263        {
264            createNet("MiddleRouter_In" + (String)i, makeNetIndex(0, number_bits_per_flit-1));
265            for (unsigned int j = 0; j < number_bits_per_flit; ++j)
266                assignVirtualFanout("MiddleRouter_In" + (String)i, makeNetIndex(j), "IngressToMiddleLink_Out", makeNetIndex(j));
267            portConnect(middle_router, "FlitIn" + (String)i, "MiddleRouter_In" + (String)i);
268        }
269        for(unsigned int i = 0; i < middle_router_number_output_ports; ++i)
270        {
271            // VFI
272            portConnect(middle_router, "FlitOut" + (String)i, "MiddleToEgressLink_In");
273        }
274
275        portConnect(egress_router, "CK", "CK");
276        for(unsigned int i = 0; i < egress_router_number_input_ports; ++i)
277        {
278            createNet("EgressRouter_In" + (String)i, makeNetIndex(0, number_bits_per_flit-1));
279            for (unsigned int j = 0; j < number_bits_per_flit; ++j)
280                assignVirtualFanout("EgressRouter_In" + (String)i, makeNetIndex(j), "MiddleToEgressLink_Out", makeNetIndex(j));
281            portConnect(egress_router, "FlitIn" + (String)i, "EgressRouter_In" + (String)i);
282        }
283        for(unsigned int i = 0; i < egress_router_number_output_ports; ++i)
284        {
285            // VFI
286            portConnect(egress_router, "FlitOut" + (String)i, "EgressToOutputLink_In");
287        }
288
289        // Create area, power, and event results
290        createElectricalResults();
291        createElectricalEventResult("AvgUnicast");
292        createElectricalEventResult("AvgBroadcast");
293
294        // Add all instances
295        addSubInstances(ingress_router, number_ingress_routers);
296        addElectricalSubResults(ingress_router, number_ingress_routers);
297        addSubInstances(middle_router, number_middle_routers);
298        addElectricalSubResults(middle_router, number_middle_routers);
299        addSubInstances(egress_router, number_egress_routers);
300        addElectricalSubResults(egress_router, number_egress_routers);
301        addSubInstances(input_to_ingress_link, number_input_to_ingress_links);
302        addElectricalSubResults(input_to_ingress_link, number_input_to_ingress_links);
303        addSubInstances(ingress_to_middle_link, number_ingress_to_middle_links);
304        addElectricalSubResults(ingress_to_middle_link, number_ingress_to_middle_links);
305        addSubInstances(middle_to_egress_link, number_middle_to_egress_links);
306        addElectricalSubResults(middle_to_egress_link, number_middle_to_egress_links);
307        addSubInstances(egress_to_output_link, number_egress_to_output_links);
308        addElectricalSubResults(egress_to_output_link, number_egress_to_output_links);
309
310        // Update unicast event
311        Result* avg_unicast_event = getEventResult("AvgUnicast");
312        avg_unicast_event->addSubResult(input_to_ingress_link->getEventResult("Send"), "InputToIngressLink", 1.0);
313        if(ingress_router->hasEventResult("WriteBuffer"))
314        {
315            avg_unicast_event->addSubResult(ingress_router->getEventResult("WriteBuffer"), "IngressRouter", 1.0);
316        }
317        if(ingress_router->hasEventResult("ReadBuffer"))
318        {
319            avg_unicast_event->addSubResult(ingress_router->getEventResult("ReadBuffer"), "IngressRouter", 1.0);
320        }
321        avg_unicast_event->addSubResult(ingress_router->getEventResult("TraverseCrossbar->Multicast1"), "IngressRouter", 1.0);
322        avg_unicast_event->addSubResult(ingress_to_middle_link->getEventResult("Send"), "IngressToMiddleLink", 1.0);
323        if(middle_router->hasEventResult("WriteBuffer"))
324        {
325            avg_unicast_event->addSubResult(middle_router->getEventResult("WriteBuffer"), "MiddleRouter", 1.0);
326        }
327        if(middle_router->hasEventResult("ReadBuffer"))
328        {
329            avg_unicast_event->addSubResult(middle_router->getEventResult("ReadBuffer"), "MiddleRouter", 1.0);
330        }
331        avg_unicast_event->addSubResult(middle_router->getEventResult("TraverseCrossbar->Multicast1"), "MiddleRouter", 1.0);
332        avg_unicast_event->addSubResult(middle_to_egress_link->getEventResult("Send"), "MiddleToEgressLink", 1.0);
333        if(egress_router->hasEventResult("WriteBuffer"))
334        {
335            avg_unicast_event->addSubResult(egress_router->getEventResult("WriteBuffer"), "EgressRouter", 1.0);
336        }
337        if(egress_router->hasEventResult("ReadBuffer"))
338        {
339            avg_unicast_event->addSubResult(egress_router->getEventResult("ReadBuffer"), "EgressRouter", 1.0);
340        }
341        avg_unicast_event->addSubResult(egress_router->getEventResult("TraverseCrossbar->Multicast1"), "EgressRouter", 1.0);
342        avg_unicast_event->addSubResult(egress_to_output_link->getEventResult("Send"), "EgressToOutputLink", 1.0);
343
344        // Update broadcast event
345        Result* avg_broadcast_event = getEventResult("AvgBroadcast");
346        avg_broadcast_event->addSubResult(input_to_ingress_link->getEventResult("Send"), "InputToIngressLink", 1.0);
347        if(ingress_router->hasEventResult("WriteBuffer"))
348        {
349            avg_broadcast_event->addSubResult(ingress_router->getEventResult("WriteBuffer"), "IngressRouter", 1.0);
350        }
351        if(ingress_router->hasEventResult("ReadBuffer"))
352        {
353            avg_broadcast_event->addSubResult(ingress_router->getEventResult("ReadBuffer"), "IngressRouter", 1.0);
354        }
355        avg_broadcast_event->addSubResult(ingress_router->getEventResult("TraverseCrossbar->Multicast1"), "IngressRouter", 1.0);
356        avg_broadcast_event->addSubResult(ingress_to_middle_link->getEventResult("Send"), "IngressToMiddleLink", 1.0);
357        if(middle_router->hasEventResult("WriteBuffer"))
358        {
359            avg_broadcast_event->addSubResult(middle_router->getEventResult("WriteBuffer"), "MiddleRouter", 1.0);
360        }
361        if(middle_router->hasEventResult("ReadBuffer"))
362        {
363            avg_broadcast_event->addSubResult(middle_router->getEventResult("ReadBuffer"), "MiddleRouter", 1.0);
364        }
365        avg_broadcast_event->addSubResult(middle_router->getEventResult("TraverseCrossbar->Multicast1"), "MiddleRouter", 1.0);
366        avg_broadcast_event->addSubResult(middle_to_egress_link->getEventResult("Send"), "MiddleToEgressLink", number_egress_routers);
367        if(egress_router->hasEventResult("WriteBuffer"))
368        {
369            avg_broadcast_event->addSubResult(egress_router->getEventResult("WriteBuffer"), "EgressRouter", number_egress_routers);
370        }
371        if(egress_router->hasEventResult("ReadBuffer"))
372        {
373            avg_broadcast_event->addSubResult(egress_router->getEventResult("ReadBuffer"), "EgressRouter", number_egress_routers);
374        }
375        avg_broadcast_event->addSubResult(egress_router->getEventResult("TraverseCrossbar->Multicast" + (String)number_egress_routers), "EgressRouter", 1.0);
376        avg_broadcast_event->addSubResult(egress_to_output_link->getEventResult("Send"), "EgressToOutputLink", number_output_sites);
377        return;
378    }
379
380    void ElectricalClos::updateModel()
381    {
382        // Get properties
383        double input_site_pitch = getProperty("InputSitePitch").toDouble();
384        double output_site_pitch = getProperty("OutputSitePitch").toDouble();
385        double clock_freq = getParameter("Frequency");
386
387        ASSERT(input_site_pitch > 0, "[Error] " + getInstanceName() +
388                " -> Input site pitch must be > 0!");
389        ASSERT(output_site_pitch > 0, "[Error] " + getInstanceName() +
390                " -> Output site pitch must be > 0!");
391        ASSERT(clock_freq > 0, "[Error] " + getInstanceName() +
392                " -> Clock frequency must be > 0!");
393
394        unsigned int number_input_sites_per_ingress_router = getGenProperties()->get("NumberInputSitesPerIngressRouter");
395        unsigned int number_ingress_routers = getParameter("NumberIngressRouters");
396        unsigned int number_output_sites_per_egress_router = getGenProperties()->get("NumberOutputSitesPerEgressRouter");
397        unsigned int number_egress_routers = getParameter("NumberEgressRouters");
398        double delay = 1.0 / clock_freq;
399
400        double input_to_ingress_link_length = input_site_pitch * (sqrt(number_input_sites_per_ingress_router) - 1.0);
401        double input_to_ingress_link_delay = delay * 0.8;
402        double ingress_to_middle_link_length = input_site_pitch * (sqrt(number_input_sites_per_ingress_router) * sqrt(number_ingress_routers));
403        double ingress_to_middle_link_delay = delay * 0.8;
404        double middle_to_egress_link_length = output_site_pitch * (sqrt(number_output_sites_per_egress_router) * sqrt(number_egress_routers));
405        double middle_to_egress_link_delay = delay * 0.8;
406        double egress_to_output_link_length = output_site_pitch * (sqrt(number_output_sites_per_egress_router) - 1.0);
407        double egress_to_output_link_delay = delay * 0.8;
408        double ingress_router_delay = delay;
409        double middle_router_delay = delay;
410        double egress_router_delay = delay;
411
412        Model* input_to_ingress_link = getSubInstance("InputToIngressLink");
413        input_to_ingress_link->setProperty("WireLength", input_to_ingress_link_length);
414        input_to_ingress_link->setProperty("Delay", input_to_ingress_link_delay);
415        input_to_ingress_link->setProperty("IsKeepParity", "TRUE");
416        input_to_ingress_link->update();
417
418        Model* ingress_to_middle_link = getSubInstance("IngressToMiddleLink");
419        ingress_to_middle_link->setProperty("WireLength", ingress_to_middle_link_length);
420        ingress_to_middle_link->setProperty("Delay", ingress_to_middle_link_delay);
421        ingress_to_middle_link->setProperty("IsKeepParity", "TRUE");
422        ingress_to_middle_link->update();
423
424        Model* middle_to_egress_link = getSubInstance("MiddleToEgressLink");
425        middle_to_egress_link->setProperty("WireLength", middle_to_egress_link_length);
426        middle_to_egress_link->setProperty("Delay", middle_to_egress_link_delay);
427        middle_to_egress_link->setProperty("IsKeepParity", "TRUE");
428        middle_to_egress_link->update();
429
430        Model* egress_to_output_link = getSubInstance("EgressToOutputLink");
431        egress_to_output_link->setProperty("WireLength", egress_to_output_link_length);
432        egress_to_output_link->setProperty("Delay", egress_to_output_link_delay);
433        egress_to_output_link->setProperty("IsKeepParity", "TRUE");
434        egress_to_output_link->update();
435
436        ElectricalModel* ingress_router = (ElectricalModel*)getSubInstance("IngressRouter");
437        ingress_router->update();
438
439        ElectricalTimingTree ingress_router_timing_tree("IngressRouter", ingress_router);
440        ingress_router_timing_tree.performTimingOpt(ingress_router->getNet("CK"), ingress_router_delay);
441
442        ElectricalModel* middle_router = (ElectricalModel*)getSubInstance("MiddleRouter");
443        middle_router->update();
444
445        ElectricalTimingTree middle_router_timing_tree("MiddleRouter", middle_router);
446        middle_router_timing_tree.performTimingOpt(middle_router->getNet("CK"), middle_router_delay);
447
448        ElectricalModel* egress_router = (ElectricalModel*)getSubInstance("EgressRouter");
449        egress_router->update();
450
451        ElectricalTimingTree egress_router_timing_tree("EgressRouter", egress_router);
452        egress_router_timing_tree.performTimingOpt(egress_router->getNet("CK"), egress_router_delay);
453
454        return;
455    }
456
457    void ElectricalClos::propagateTransitionInfo()
458    {
459        // Get properties
460        unsigned int ingress_router_number_input_ports = getGenProperties()->get("IngressRouter->NumberInputPorts");
461        unsigned int middle_router_number_input_ports = getGenProperties()->get("MiddleRouter->NumberInputPorts");
462        unsigned int egress_router_number_input_ports = getGenProperties()->get("EgressRouter->NumberInputPorts");
463
464        ElectricalModel* input_to_ingress_link = (ElectricalModel*)getSubInstance("InputToIngressLink");
465        assignPortTransitionInfo(input_to_ingress_link, "In", TransitionInfo(0.25, 0.25, 0.25));
466        input_to_ingress_link->use();
467
468        ElectricalModel* ingress_to_middle_link = (ElectricalModel*)getSubInstance("IngressToMiddleLink");
469        assignPortTransitionInfo(ingress_to_middle_link, "In", TransitionInfo(0.25, 0.25, 0.25));
470        ingress_to_middle_link->use();
471
472        ElectricalModel* middle_to_egress_link = (ElectricalModel*)getSubInstance("MiddleToEgressLink");
473        assignPortTransitionInfo(middle_to_egress_link, "In", TransitionInfo(0.25, 0.25, 0.25));
474        middle_to_egress_link->use();
475
476        ElectricalModel* egress_to_output_link = (ElectricalModel*)getSubInstance("EgressToOutputLink");
477        assignPortTransitionInfo(egress_to_output_link, "In", TransitionInfo(0.25, 0.25, 0.25));
478        egress_to_output_link->use();
479
480        ElectricalModel* ingress_router = (ElectricalModel*)getSubInstance("IngressRouter");
481        for(unsigned int i = 0; i < ingress_router_number_input_ports; ++i)
482        {
483            assignPortTransitionInfo(ingress_router, "FlitIn" + (String)i, TransitionInfo(0.25, 0.25, 0.25));
484        }
485        assignPortTransitionInfo(ingress_router, "CK", TransitionInfo(0.0, 1.0, 0.0));
486        ingress_router->getGenProperties()->set("UseModelEvent", "");
487        ingress_router->use();
488
489        ElectricalModel* middle_router = (ElectricalModel*)getSubInstance("MiddleRouter");
490        for(unsigned int i = 0; i < middle_router_number_input_ports; ++i)
491        {
492            assignPortTransitionInfo(middle_router, "FlitIn" + (String)i, TransitionInfo(0.25, 0.25, 0.25));
493        }
494        assignPortTransitionInfo(middle_router, "CK", TransitionInfo(0.0, 1.0, 0.0));
495        middle_router->getGenProperties()->set("UseModelEvent", "");
496        middle_router->use();
497
498        ElectricalModel* egress_router = (ElectricalModel*)getSubInstance("EgressRouter");
499        for(unsigned int i = 0; i < egress_router_number_input_ports; ++i)
500        {
501            assignPortTransitionInfo(egress_router, "FlitIn" + (String)i, TransitionInfo(0.25, 0.25, 0.25));
502        }
503        assignPortTransitionInfo(egress_router, "CK", TransitionInfo(0.0, 1.0, 0.0));
504        egress_router->getGenProperties()->set("UseModelEvent", "");
505        egress_router->use();
506
507        return;
508    }
509} // namespace DSENT
510
511