crossbar.cc revision 10152
110152Satgutier@umich.edu/*****************************************************************************
210152Satgutier@umich.edu *                                McPAT/CACTI
310152Satgutier@umich.edu *                      SOFTWARE LICENSE AGREEMENT
410152Satgutier@umich.edu *            Copyright 2012 Hewlett-Packard Development Company, L.P.
510152Satgutier@umich.edu *                          All Rights Reserved
610152Satgutier@umich.edu *
710152Satgutier@umich.edu * Redistribution and use in source and binary forms, with or without
810152Satgutier@umich.edu * modification, are permitted provided that the following conditions are
910152Satgutier@umich.edu * met: redistributions of source code must retain the above copyright
1010152Satgutier@umich.edu * notice, this list of conditions and the following disclaimer;
1110152Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright
1210152Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the
1310152Satgutier@umich.edu * documentation and/or other materials provided with the distribution;
1410152Satgutier@umich.edu * neither the name of the copyright holders nor the names of its
1510152Satgutier@umich.edu * contributors may be used to endorse or promote products derived from
1610152Satgutier@umich.edu * this software without specific prior written permission.
1710152Satgutier@umich.edu
1810152Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1910152Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2010152Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2110152Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2210152Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2310152Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2410152Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2510152Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2610152Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2710152Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2810152Satgutier@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.”
2910152Satgutier@umich.edu *
3010152Satgutier@umich.edu ***************************************************************************/
3110152Satgutier@umich.edu
3210152Satgutier@umich.edu#include "crossbar.h"
3310152Satgutier@umich.edu
3410152Satgutier@umich.edu#define ASPECT_THRESHOLD .8
3510152Satgutier@umich.edu#define ADJ 1
3610152Satgutier@umich.edu
3710152Satgutier@umich.eduCrossbar::Crossbar(
3810152Satgutier@umich.edu    double n_inp_,
3910152Satgutier@umich.edu    double n_out_,
4010152Satgutier@umich.edu    double flit_size_,
4110152Satgutier@umich.edu    TechnologyParameter::DeviceType *dt
4210152Satgutier@umich.edu    ):n_inp(n_inp_), n_out(n_out_), flit_size(flit_size_), deviceType(dt)
4310152Satgutier@umich.edu{
4410152Satgutier@umich.edu  min_w_pmos = deviceType->n_to_p_eff_curr_drv_ratio*g_tp.min_w_nmos_;
4510152Satgutier@umich.edu  Vdd = dt->Vdd;
4610152Satgutier@umich.edu  CB_ADJ = 1;
4710152Satgutier@umich.edu}
4810152Satgutier@umich.edu
4910152Satgutier@umich.eduCrossbar::~Crossbar(){}
5010152Satgutier@umich.edu
5110152Satgutier@umich.edudouble Crossbar::output_buffer()
5210152Satgutier@umich.edu{
5310152Satgutier@umich.edu
5410152Satgutier@umich.edu  //Wire winit(4, 4);
5510152Satgutier@umich.edu  double l_eff = n_inp*flit_size*g_tp.wire_outside_mat.pitch;
5610152Satgutier@umich.edu  Wire w1(g_ip->wt, l_eff);
5710152Satgutier@umich.edu  //double s1 = w1.repeater_size *l_eff*ADJ/w1.repeater_spacing;
5810152Satgutier@umich.edu  double s1 = w1.repeater_size * (l_eff <w1.repeater_spacing?  l_eff *ADJ/w1.repeater_spacing : ADJ);
5910152Satgutier@umich.edu  double pton_size = deviceType->n_to_p_eff_curr_drv_ratio;
6010152Satgutier@umich.edu  // the model assumes input capacitance of the wire driver = input capacitance of nand + nor = input cap of the driver transistor
6110152Satgutier@umich.edu  TriS1 = s1*(1 + pton_size)/(2 + pton_size + 1 + 2*pton_size);
6210152Satgutier@umich.edu  TriS2 = s1; //driver transistor
6310152Satgutier@umich.edu
6410152Satgutier@umich.edu  if (TriS1 < 1)
6510152Satgutier@umich.edu    TriS1 = 1;
6610152Satgutier@umich.edu
6710152Satgutier@umich.edu  double input_cap = gate_C(TriS1*(2*min_w_pmos + g_tp.min_w_nmos_), 0) +
6810152Satgutier@umich.edu    gate_C(TriS1*(min_w_pmos + 2*g_tp.min_w_nmos_), 0);
6910152Satgutier@umich.edu//  input_cap += drain_C_(TriS1*g_tp.min_w_nmos_, NCH, 1, 1, g_tp.cell_h_def) +
7010152Satgutier@umich.edu//    drain_C_(TriS1*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)*2 +
7110152Satgutier@umich.edu//    gate_C(TriS2*g_tp.min_w_nmos_, 0)+
7210152Satgutier@umich.edu//    drain_C_(TriS1*min_w_pmos, NCH, 1, 1, g_tp.cell_h_def)*2 +
7310152Satgutier@umich.edu//    drain_C_(TriS1*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def) +
7410152Satgutier@umich.edu//    gate_C(TriS2*min_w_pmos, 0);
7510152Satgutier@umich.edu  tri_int_cap = drain_C_(TriS1*g_tp.min_w_nmos_, NCH, 1, 1, g_tp.cell_h_def) +
7610152Satgutier@umich.edu    drain_C_(TriS1*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)*2 +
7710152Satgutier@umich.edu    gate_C(TriS2*g_tp.min_w_nmos_, 0)+
7810152Satgutier@umich.edu    drain_C_(TriS1*min_w_pmos, NCH, 1, 1, g_tp.cell_h_def)*2 +
7910152Satgutier@umich.edu    drain_C_(TriS1*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def) +
8010152Satgutier@umich.edu    gate_C(TriS2*min_w_pmos, 0);
8110152Satgutier@umich.edu  double output_cap = drain_C_(TriS2*g_tp.min_w_nmos_, NCH, 1, 1, g_tp.cell_h_def) +
8210152Satgutier@umich.edu    drain_C_(TriS2*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def);
8310152Satgutier@umich.edu  double ctr_cap = gate_C(TriS2 *(min_w_pmos + g_tp.min_w_nmos_), 0);
8410152Satgutier@umich.edu
8510152Satgutier@umich.edu  tri_inp_cap = input_cap;
8610152Satgutier@umich.edu  tri_out_cap = output_cap;
8710152Satgutier@umich.edu  tri_ctr_cap = ctr_cap;
8810152Satgutier@umich.edu  return input_cap + output_cap + ctr_cap;
8910152Satgutier@umich.edu}
9010152Satgutier@umich.edu
9110152Satgutier@umich.eduvoid Crossbar::compute_power()
9210152Satgutier@umich.edu{
9310152Satgutier@umich.edu
9410152Satgutier@umich.edu  Wire winit(4, 4);
9510152Satgutier@umich.edu  double tri_cap = output_buffer();
9610152Satgutier@umich.edu  assert(tri_cap > 0);
9710152Satgutier@umich.edu  //area of a tristate logic
9810152Satgutier@umich.edu  double g_area = compute_gate_area(INV, 1, TriS2*g_tp.min_w_nmos_, TriS2*min_w_pmos, g_tp.cell_h_def);
9910152Satgutier@umich.edu  g_area *= 2; // to model area of output transistors
10010152Satgutier@umich.edu  g_area += compute_gate_area (NAND, 2, TriS1*2*g_tp.min_w_nmos_, TriS1*min_w_pmos, g_tp.cell_h_def);
10110152Satgutier@umich.edu  g_area += compute_gate_area (NOR, 2, TriS1*g_tp.min_w_nmos_, TriS1*2*min_w_pmos, g_tp.cell_h_def);
10210152Satgutier@umich.edu  double width /*per tristate*/ = g_area/(CB_ADJ * g_tp.cell_h_def);
10310152Satgutier@umich.edu  // effective no. of tristate buffers that need to be laid side by side
10410152Satgutier@umich.edu  int ntri = (int)ceil(g_tp.cell_h_def/(g_tp.wire_outside_mat.pitch));
10510152Satgutier@umich.edu  double wire_len = MAX(width*ntri*n_out, flit_size*g_tp.wire_outside_mat.pitch*n_out);
10610152Satgutier@umich.edu  Wire w1(g_ip->wt, wire_len);
10710152Satgutier@umich.edu
10810152Satgutier@umich.edu  area.w = wire_len;
10910152Satgutier@umich.edu  area.h = g_tp.wire_outside_mat.pitch*n_inp*flit_size * CB_ADJ;
11010152Satgutier@umich.edu  Wire w2(g_ip->wt, area.h);
11110152Satgutier@umich.edu
11210152Satgutier@umich.edu  double aspect_ratio_cb = (area.h/area.w)*(n_out/n_inp);
11310152Satgutier@umich.edu  if (aspect_ratio_cb > 1) aspect_ratio_cb = 1/aspect_ratio_cb;
11410152Satgutier@umich.edu
11510152Satgutier@umich.edu  if (aspect_ratio_cb < ASPECT_THRESHOLD) {
11610152Satgutier@umich.edu    if (n_out > 2 && n_inp > 2) {
11710152Satgutier@umich.edu      CB_ADJ+=0.2;
11810152Satgutier@umich.edu      //cout << "CB ADJ " << CB_ADJ << endl;
11910152Satgutier@umich.edu      if (CB_ADJ < 4) {
12010152Satgutier@umich.edu        this->compute_power();
12110152Satgutier@umich.edu      }
12210152Satgutier@umich.edu    }
12310152Satgutier@umich.edu  }
12410152Satgutier@umich.edu
12510152Satgutier@umich.edu
12610152Satgutier@umich.edu
12710152Satgutier@umich.edu  power.readOp.dynamic = (w1.power.readOp.dynamic + w2.power.readOp.dynamic + (tri_inp_cap * n_out + tri_out_cap * n_inp + tri_ctr_cap + tri_int_cap) * Vdd*Vdd)*flit_size;
12810152Satgutier@umich.edu  power.readOp.leakage      =  n_inp * n_out * flit_size * (
12910152Satgutier@umich.edu    cmos_Isub_leakage(g_tp.min_w_nmos_*TriS2*2, min_w_pmos*TriS2*2, 1, inv) *Vdd+
13010152Satgutier@umich.edu        cmos_Isub_leakage(g_tp.min_w_nmos_*TriS1*3, min_w_pmos*TriS1*3, 2, nand)*Vdd+
13110152Satgutier@umich.edu        cmos_Isub_leakage(g_tp.min_w_nmos_*TriS1*3, min_w_pmos*TriS1*3, 2, nor) *Vdd+
13210152Satgutier@umich.edu    w1.power.readOp.leakage + w2.power.readOp.leakage);
13310152Satgutier@umich.edu  power.readOp.gate_leakage = n_inp * n_out * flit_size * (
13410152Satgutier@umich.edu          cmos_Ig_leakage(g_tp.min_w_nmos_*TriS2*2, min_w_pmos*TriS2*2, 1, inv) *Vdd+
13510152Satgutier@umich.edu          cmos_Ig_leakage(g_tp.min_w_nmos_*TriS1*3, min_w_pmos*TriS1*3, 2, nand)*Vdd+
13610152Satgutier@umich.edu          cmos_Ig_leakage(g_tp.min_w_nmos_*TriS1*3, min_w_pmos*TriS1*3, 2, nor) *Vdd+
13710152Satgutier@umich.edu          w1.power.readOp.gate_leakage + w2.power.readOp.gate_leakage);
13810152Satgutier@umich.edu
13910152Satgutier@umich.edu  // delay calculation
14010152Satgutier@umich.edu  double l_eff = n_inp*flit_size*g_tp.wire_outside_mat.pitch;
14110152Satgutier@umich.edu  Wire wdriver(g_ip->wt, l_eff);
14210152Satgutier@umich.edu  double res = g_tp.wire_outside_mat.R_per_um * (area.w+area.h) + tr_R_on(g_tp.min_w_nmos_*wdriver.repeater_size, NCH, 1);
14310152Satgutier@umich.edu  double cap = g_tp.wire_outside_mat.C_per_um * (area.w + area.h) + n_out*tri_inp_cap + n_inp*tri_out_cap;
14410152Satgutier@umich.edu  delay = horowitz(w1.signal_rise_time(), res*cap, deviceType->Vth/deviceType->Vdd, deviceType->Vth/deviceType->Vdd, RISE);
14510152Satgutier@umich.edu
14610152Satgutier@umich.edu  Wire wreset();
14710152Satgutier@umich.edu}
14810152Satgutier@umich.edu
14910152Satgutier@umich.eduvoid Crossbar::print_crossbar()
15010152Satgutier@umich.edu{
15110152Satgutier@umich.edu  cout << "\nCrossbar Stats (" << n_inp << "x" << n_out << ")\n\n";
15210152Satgutier@umich.edu  cout << "Flit size        : " << flit_size << " bits" << endl;
15310152Satgutier@umich.edu  cout << "Width            : " << area.w << " u" << endl;
15410152Satgutier@umich.edu  cout << "Height           : " << area.h << " u" << endl;
15510152Satgutier@umich.edu  cout << "Dynamic Power    : " << power.readOp.dynamic*1e9 * MIN(n_inp, n_out) << " (nJ)" << endl;
15610152Satgutier@umich.edu  cout << "Leakage Power    : " << power.readOp.leakage*1e3 << " (mW)" << endl;
15710152Satgutier@umich.edu  cout << "Gate Leakage Power    : " << power.readOp.gate_leakage*1e3 << " (mW)" << endl;
15810152Satgutier@umich.edu  cout << "Crossbar Delay   : " << delay*1e12 << " ps\n";
15910152Satgutier@umich.edu}
16010152Satgutier@umich.edu
16110152Satgutier@umich.edu
162