noc.cc revision 10152
1/***************************************************************************** 2 * McPAT 3 * SOFTWARE LICENSE AGREEMENT 4 * Copyright 2012 Hewlett-Packard Development Company, L.P. 5 * All Rights Reserved 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer; 11 * redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution; 14 * neither the name of the copyright holders nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.” 29 * 30 ***************************************************************************/ 31 32#include <algorithm> 33#include <cassert> 34#include <cmath> 35#include <iostream> 36#include <string> 37 38#include "XML_Parse.h" 39#include "basic_circuit.h" 40#include "const.h" 41#include "io.h" 42#include "noc.h" 43#include "parameter.h" 44 45NoC::NoC(ParseXML *XML_interface, int ithNoC_, InputParameter* interface_ip_, double M_traffic_pattern_, double link_len_) 46:XML(XML_interface), 47ithNoC(ithNoC_), 48interface_ip(*interface_ip_), 49router(0), 50link_bus(0), 51link_bus_exist(false), 52router_exist(false), 53M_traffic_pattern(M_traffic_pattern_) 54{ 55 /* 56 * initialize, compute and optimize individual components. 57 */ 58 59 if (XML->sys.Embedded) 60 { 61 interface_ip.wt =Global_30; 62 interface_ip.wire_is_mat_type = 0; 63 interface_ip.wire_os_mat_type = 1; 64 } 65 else 66 { 67 interface_ip.wt =Global; 68 interface_ip.wire_is_mat_type = 2; 69 interface_ip.wire_os_mat_type = 2; 70 } 71 set_noc_param(); 72 local_result=init_interface(&interface_ip); 73 scktRatio = g_tp.sckt_co_eff; 74 75 if (nocdynp.type) 76 {/* 77 * if NOC compute router, router links must be computed separately 78 * and called from external 79 * since total chip area must be known first 80 */ 81 init_router(); 82 } 83 else 84 { 85 init_link_bus(link_len_); //if bus compute bus 86 } 87 88 // //clock power 89 // clockNetwork.init_wire_external(is_default, &interface_ip); 90 // clockNetwork.clk_area =area*1.1;//10% of placement overhead. rule of thumb 91 // clockNetwork.end_wiring_level =5;//toplevel metal 92 // clockNetwork.start_wiring_level =5;//toplevel metal 93 // clockNetwork.num_regs = corepipe.tot_stage_vector; 94 // clockNetwork.optimize_wire(); 95} 96 97void NoC::init_router() 98{ 99 router = new Router(nocdynp.flit_size, 100 nocdynp.virtual_channel_per_port*nocdynp.input_buffer_entries_per_vc, 101 nocdynp.virtual_channel_per_port, &(g_tp.peri_global), 102 nocdynp.input_ports,nocdynp.output_ports, M_traffic_pattern); 103 //router->print_router(); 104 area.set_area(area.get_area()+ router->area.get_area()*nocdynp.total_nodes); 105 106 double long_channel_device_reduction = longer_channel_device_reduction(Uncore_device); 107 router->power.readOp.longer_channel_leakage = router->power.readOp.leakage * long_channel_device_reduction; 108 router->buffer.power.readOp.longer_channel_leakage = router->buffer.power.readOp.leakage * long_channel_device_reduction; 109 router->crossbar.power.readOp.longer_channel_leakage = router->crossbar.power.readOp.leakage * long_channel_device_reduction; 110 router->arbiter.power.readOp.longer_channel_leakage = router->arbiter.power.readOp.leakage * long_channel_device_reduction; 111 router_exist = true; 112} 113 114void NoC ::init_link_bus(double link_len_) 115{ 116 117 118// if (nocdynp.min_ports==1 ) 119 if (nocdynp.type) 120 link_name = "Links"; 121 else 122 link_name = "Bus"; 123 124 link_len=link_len_; 125 assert(link_len>0); 126 127 interface_ip.throughput = nocdynp.link_throughput/nocdynp.clockRate; 128 interface_ip.latency = nocdynp.link_latency/nocdynp.clockRate; 129 130 link_len /= (nocdynp.horizontal_nodes + nocdynp.vertical_nodes)/2; 131 132 if (nocdynp.total_nodes >1) link_len /=2; //All links are shared by neighbors 133 link_bus = new interconnect(name, Uncore_device, 1, 1, nocdynp.flit_size, 134 link_len, &interface_ip, 3, true/*pipelinable*/, nocdynp.route_over_perc); 135 136 link_bus_tot_per_Router.area.set_area(link_bus_tot_per_Router.area.get_area()+ link_bus->area.get_area() 137 * nocdynp.global_linked_ports); 138 139 area.set_area(area.get_area()+ link_bus_tot_per_Router.area.get_area()* nocdynp.total_nodes); 140 link_bus_exist = true; 141} 142void NoC::computeEnergy(bool is_tdp) 143{ 144 //power_point_product_masks 145 double pppm_t[4] = {1,1,1,1}; 146 double M=nocdynp.duty_cycle; 147 if (is_tdp) 148 { 149 //init stats for TDP 150 stats_t.readAc.access = M; 151 tdp_stats = stats_t; 152 if (router_exist) 153 { 154 set_pppm(pppm_t, 1*M, 1, 1, 1);//reset traffic pattern 155 router->power = router->power*pppm_t; 156 set_pppm(pppm_t, nocdynp.total_nodes, nocdynp.total_nodes, nocdynp.total_nodes, nocdynp.total_nodes); 157 power = power + router->power*pppm_t; 158 } 159 if (link_bus_exist) 160 { 161 if (nocdynp.type) 162 set_pppm(pppm_t, 1*M_traffic_pattern*M*(nocdynp.min_ports -1), nocdynp.global_linked_ports, 163 nocdynp.global_linked_ports, nocdynp.global_linked_ports); 164 //reset traffic pattern; local port do not have router links 165 else 166 set_pppm(pppm_t, 1*M_traffic_pattern*M*(nocdynp.min_ports), nocdynp.global_linked_ports, 167 nocdynp.global_linked_ports, nocdynp.global_linked_ports);//reset traffic pattern 168 169 link_bus_tot_per_Router.power = link_bus->power*pppm_t; 170 171 set_pppm(pppm_t, nocdynp.total_nodes, 172 nocdynp.total_nodes, 173 nocdynp.total_nodes, 174 nocdynp.total_nodes); 175 power = power + link_bus_tot_per_Router.power*pppm_t; 176 177 } 178 } 179 else 180 { 181 //init stats for runtime power (RTP) 182 stats_t.readAc.access = XML->sys.NoC[ithNoC].total_accesses; 183 rtp_stats = stats_t; 184 set_pppm(pppm_t, 1, 0 , 0, 0); 185 if (router_exist) 186 { 187 router->buffer.rt_power.readOp.dynamic = (router->buffer.power.readOp.dynamic + router->buffer.power.writeOp.dynamic)*rtp_stats.readAc.access ; 188 router->crossbar.rt_power.readOp.dynamic = router->crossbar.power.readOp.dynamic*rtp_stats.readAc.access ; 189 router->arbiter.rt_power.readOp.dynamic = router->arbiter.power.readOp.dynamic*rtp_stats.readAc.access ; 190 191 router->rt_power = router->rt_power + (router->buffer.rt_power + router->crossbar.rt_power + router->arbiter.rt_power)*pppm_t + 192 router->power*pppm_lkg;//TDP power must be calculated first! 193 rt_power = rt_power + router->rt_power; 194 } 195 if (link_bus_exist) 196 { 197 set_pppm(pppm_t, rtp_stats.readAc.access, 1 , 1, rtp_stats.readAc.access); 198 link_bus->rt_power = link_bus->power * pppm_t; 199 rt_power = rt_power + link_bus->rt_power; 200 } 201 202 } 203} 204 205 206void NoC::displayEnergy(uint32_t indent,int plevel,bool is_tdp) 207{ 208 string indent_str(indent, ' '); 209 string indent_str_next(indent+2, ' '); 210 bool long_channel = XML->sys.longer_channel_device; 211 212 double M =M_traffic_pattern*nocdynp.duty_cycle; 213 /*only router as a whole has been applied the M_traffic_pattern(0.6 by default) factor in router.cc; 214 * When power of crossbars, arbiters, etc need to be displayed, the M_traffic_pattern factor need to 215 * be applied together with McPAT's extra traffic pattern. 216 * */ 217 if (is_tdp) 218 { 219 cout << name << endl; 220 cout << indent_str << "Area = " << area.get_area()*1e-6<< " mm^2" << endl; 221 cout << indent_str<< "Peak Dynamic = " << power.readOp.dynamic*nocdynp.clockRate << " W" << endl; 222 cout << indent_str << "Subthreshold Leakage = " 223 << (long_channel? power.readOp.longer_channel_leakage:power.readOp.leakage) <<" W" << endl; 224 cout << indent_str << "Gate Leakage = " << power.readOp.gate_leakage << " W" << endl; 225 cout << indent_str<< "Runtime Dynamic = " << rt_power.readOp.dynamic/nocdynp.executionTime << " W" << endl; 226 cout<<endl; 227 228 if (router_exist) 229 { 230 cout << indent_str << "Router: " << endl; 231 cout << indent_str_next << "Area = " << router->area.get_area()*1e-6<< " mm^2" << endl; 232 cout << indent_str_next<< "Peak Dynamic = " << router->power.readOp.dynamic*nocdynp.clockRate << " W" << endl; 233 cout << indent_str_next << "Subthreshold Leakage = " 234 << (long_channel? router->power.readOp.longer_channel_leakage:router->power.readOp.leakage) <<" W" << endl; 235 cout << indent_str_next << "Gate Leakage = " << router->power.readOp.gate_leakage << " W" << endl; 236 cout << indent_str_next<< "Runtime Dynamic = " << router->rt_power.readOp.dynamic/nocdynp.executionTime << " W" << endl; 237 cout<<endl; 238 if (plevel >2){ 239 cout << indent_str<< indent_str << "Virtual Channel Buffer:" << endl; 240 cout << indent_str<< indent_str_next << "Area = " << router->buffer.area.get_area()*1e-6*nocdynp.input_ports<< " mm^2" << endl; 241 cout << indent_str<< indent_str_next << "Peak Dynamic = " <<(router->buffer.power.readOp.dynamic + router->buffer.power.writeOp.dynamic) 242 *nocdynp.min_ports*M*nocdynp.clockRate << " W" << endl; 243 cout << indent_str<< indent_str_next << "Subthreshold Leakage = " 244 << (long_channel? router->buffer.power.readOp.longer_channel_leakage*nocdynp.input_ports:router->buffer.power.readOp.leakage*nocdynp.input_ports) <<" W" << endl; 245 cout << indent_str<< indent_str_next << "Gate Leakage = " << router->buffer.power.readOp.gate_leakage*nocdynp.input_ports << " W" << endl; 246 cout << indent_str<< indent_str_next << "Runtime Dynamic = " << router->buffer.rt_power.readOp.dynamic/nocdynp.executionTime << " W" << endl; 247 cout <<endl; 248 cout << indent_str<< indent_str<< "Crossbar:" << endl; 249 cout << indent_str<< indent_str_next << "Area = " << router->crossbar.area.get_area()*1e-6 << " mm^2" << endl; 250 cout << indent_str<< indent_str_next << "Peak Dynamic = " << router->crossbar.power.readOp.dynamic*nocdynp.clockRate*nocdynp.min_ports*M << " W" << endl; 251 cout << indent_str<< indent_str_next << "Subthreshold Leakage = " 252 << (long_channel? router->crossbar.power.readOp.longer_channel_leakage:router->crossbar.power.readOp.leakage) << " W" << endl; 253 cout << indent_str<< indent_str_next << "Gate Leakage = " << router->crossbar.power.readOp.gate_leakage << " W" << endl; 254 cout << indent_str<< indent_str_next << "Runtime Dynamic = " << router->crossbar.rt_power.readOp.dynamic/nocdynp.executionTime << " W" << endl; 255 cout <<endl; 256 cout << indent_str<< indent_str<< "Arbiter:" << endl; 257 cout << indent_str<< indent_str_next << "Peak Dynamic = " << router->arbiter.power.readOp.dynamic*nocdynp.clockRate*nocdynp.min_ports*M << " W" << endl; 258 cout << indent_str<< indent_str_next << "Subthreshold Leakage = " 259 << (long_channel? router->arbiter.power.readOp.longer_channel_leakage:router->arbiter.power.readOp.leakage) << " W" << endl; 260 cout << indent_str<< indent_str_next << "Gate Leakage = " << router->arbiter.power.readOp.gate_leakage << " W" << endl; 261 cout << indent_str<< indent_str_next << "Runtime Dynamic = " << router->arbiter.rt_power.readOp.dynamic/nocdynp.executionTime << " W" << endl; 262 cout <<endl; 263 } 264 } 265 if (link_bus_exist) 266 { 267 cout << indent_str << (nocdynp.type? "Per Router ":"") << link_name<<": " << endl; 268 cout << indent_str_next << "Area = " << link_bus_tot_per_Router.area.get_area()*1e-6<< " mm^2" << endl; 269 cout << indent_str_next<< "Peak Dynamic = " << link_bus_tot_per_Router.power.readOp.dynamic* 270 nocdynp.clockRate << " W" << endl; 271 cout << indent_str_next << "Subthreshold Leakage = " 272 << (long_channel? link_bus_tot_per_Router.power.readOp.longer_channel_leakage:link_bus_tot_per_Router.power.readOp.leakage) 273 <<" W" << endl; 274 cout << indent_str_next << "Gate Leakage = " << link_bus_tot_per_Router.power.readOp.gate_leakage 275 << " W" << endl; 276 cout << indent_str_next<< "Runtime Dynamic = " << link_bus->rt_power.readOp.dynamic/nocdynp.executionTime << " W" << endl; 277 cout<<endl; 278 279 } 280 } 281 else 282 { 283// cout << indent_str_next << "Instruction Fetch Unit Peak Dynamic = " << ifu->rt_power.readOp.dynamic*clockRate << " W" << endl; 284// cout << indent_str_next << "Instruction Fetch Unit Subthreshold Leakage = " << ifu->rt_power.readOp.leakage <<" W" << endl; 285// cout << indent_str_next << "Instruction Fetch Unit Gate Leakage = " << ifu->rt_power.readOp.gate_leakage << " W" << endl; 286// cout << indent_str_next << "Load Store Unit Peak Dynamic = " << lsu->rt_power.readOp.dynamic*clockRate << " W" << endl; 287// cout << indent_str_next << "Load Store Unit Subthreshold Leakage = " << lsu->rt_power.readOp.leakage << " W" << endl; 288// cout << indent_str_next << "Load Store Unit Gate Leakage = " << lsu->rt_power.readOp.gate_leakage << " W" << endl; 289// cout << indent_str_next << "Memory Management Unit Peak Dynamic = " << mmu->rt_power.readOp.dynamic*clockRate << " W" << endl; 290// cout << indent_str_next << "Memory Management Unit Subthreshold Leakage = " << mmu->rt_power.readOp.leakage << " W" << endl; 291// cout << indent_str_next << "Memory Management Unit Gate Leakage = " << mmu->rt_power.readOp.gate_leakage << " W" << endl; 292// cout << indent_str_next << "Execution Unit Peak Dynamic = " << exu->rt_power.readOp.dynamic*clockRate << " W" << endl; 293// cout << indent_str_next << "Execution Unit Subthreshold Leakage = " << exu->rt_power.readOp.leakage << " W" << endl; 294// cout << indent_str_next << "Execution Unit Gate Leakage = " << exu->rt_power.readOp.gate_leakage << " W" << endl; 295 } 296} 297 298void NoC::set_noc_param() 299{ 300 301 nocdynp.type = XML->sys.NoC[ithNoC].type; 302 nocdynp.clockRate =XML->sys.NoC[ithNoC].clockrate; 303 nocdynp.clockRate *= 1e6; 304 nocdynp.executionTime = XML->sys.total_cycles/(XML->sys.target_core_clockrate*1e6); 305 306 nocdynp.flit_size = XML->sys.NoC[ithNoC].flit_bits; 307 if (nocdynp.type) 308 { 309 nocdynp.input_ports = XML->sys.NoC[ithNoC].input_ports; 310 nocdynp.output_ports = XML->sys.NoC[ithNoC].output_ports;//later minus 1 311 nocdynp.min_ports = min(nocdynp.input_ports,nocdynp.output_ports); 312 nocdynp.global_linked_ports = (nocdynp.input_ports-1) + (nocdynp.output_ports-1); 313 /* 314 * Except local i/o ports, all ports needs links( global_linked_ports); 315 * However only min_ports can be fully active simultaneously 316 * since the fewer number of ports (input or output ) is the bottleneck. 317 */ 318 } 319 else 320 { 321 nocdynp.input_ports = 1; 322 nocdynp.output_ports = 1; 323 nocdynp.min_ports = min(nocdynp.input_ports,nocdynp.output_ports); 324 nocdynp.global_linked_ports = 1; 325 } 326 327 nocdynp.virtual_channel_per_port = XML->sys.NoC[ithNoC].virtual_channel_per_port; 328 nocdynp.input_buffer_entries_per_vc = XML->sys.NoC[ithNoC].input_buffer_entries_per_vc; 329 330 nocdynp.horizontal_nodes = XML->sys.NoC[ithNoC].horizontal_nodes; 331 nocdynp.vertical_nodes = XML->sys.NoC[ithNoC].vertical_nodes; 332 nocdynp.total_nodes = nocdynp.horizontal_nodes*nocdynp.vertical_nodes; 333 nocdynp.duty_cycle = XML->sys.NoC[ithNoC].duty_cycle; 334 nocdynp.has_global_link = XML->sys.NoC[ithNoC].has_global_link; 335 nocdynp.link_throughput = XML->sys.NoC[ithNoC].link_throughput; 336 nocdynp.link_latency = XML->sys.NoC[ithNoC].link_latency; 337 nocdynp.chip_coverage = XML->sys.NoC[ithNoC].chip_coverage; 338 nocdynp.route_over_perc = XML->sys.NoC[ithNoC].route_over_perc; 339 340 assert (nocdynp.chip_coverage <=1); 341 assert (nocdynp.route_over_perc <=1); 342 343 if (nocdynp.type) 344 name = "NOC"; 345 else 346 name = "BUSES"; 347 348} 349 350 351NoC ::~NoC(){ 352 353 if(router) {delete router; router = 0;} 354 if(link_bus) {delete link_bus; link_bus = 0;} 355} 356