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