summaryrefslogtreecommitdiff
path: root/src/mem/ruby/network/orion/NetworkPower.cc
blob: 7d4aae3edcf46f6982de5bba0ec59088c12285cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * Copyright (c) 2010 Massachusetts Institute of Technology
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Chia-Hsin Owen Chen
 *          Tushar Krishna
 */

#include "mem/ruby/network/orion/NetworkPower.hh"
#include "mem/ruby/network/orion/OrionConfig.hh"
#include "mem/ruby/network/orion/OrionRouter.hh"
#include "mem/ruby/network/orion/OrionLink.hh"

double
Router_d::calculate_power()
{
    //Network Activities from garnet
    calculate_performance_numbers();
    double sim_cycles;
    sim_cycles = g_eventQueue_ptr->getTime() - m_network_ptr->getRubyStartTime();

    // Number of virtual networks/message classes declared in Ruby
    // maybe greater than active virtual networks.
    // Estimate active virtual networks for correct power estimates
    int num_active_vclass = 0;
    std::vector<bool > active_vclass_ary;
    active_vclass_ary.resize(m_virtual_networks);

    std::vector<double > vc_local_arbit_count_active;
    std::vector<double > vc_global_arbit_count_active;
    std::vector<double > buf_read_count_active;
    std::vector<double > buf_write_count_active;

    for (int i =0; i < m_virtual_networks; i++) {
        if (vc_local_arbit_count[i] > 0) {
            num_active_vclass++;
            active_vclass_ary[i] = true;
            vc_local_arbit_count_active.push_back(vc_local_arbit_count[i]);
            vc_global_arbit_count_active.push_back(vc_global_arbit_count[i]);
            buf_read_count_active.push_back(buf_read_count[i]);
            buf_write_count_active.push_back(buf_write_count[i]);
        }
        else {
            // Inactive vclass
            assert(vc_global_arbit_count[i] == 0);
            active_vclass_ary[i] = false;
        }
    }

    // Orion Initialization
    OrionConfig* orion_cfg_ptr;
    OrionRouter* orion_rtr_ptr;
    static double freq_Hz;

    const string cfg_fn = "src/mem/ruby/network/orion/router.cfg";
    orion_cfg_ptr = new OrionConfig(cfg_fn);
    freq_Hz = orion_cfg_ptr->get<double>("FREQUENCY");

    uint32_t num_in_port = m_input_unit.size();
    uint32_t num_out_port = m_output_unit.size();
    uint32_t num_vclass = num_active_vclass;
    std::vector<uint32_t > vclass_type_ary;

    for (int i = 0; i < m_virtual_networks; i++) {
        if (active_vclass_ary[i]) {
            int temp_vc = i*m_vc_per_vnet;
            vclass_type_ary.push_back((uint32_t) m_network_ptr->get_vnet_type(temp_vc));
        }
    }
    assert(vclass_type_ary.size() == num_active_vclass);

    uint32_t num_vc_per_vclass = m_vc_per_vnet;
    uint32_t in_buf_per_data_vc = m_network_ptr->getBuffersPerDataVC();
    uint32_t in_buf_per_ctrl_vc = m_network_ptr->getBuffersPerCtrlVC();
    uint32_t flit_width = m_flit_width * 8; //flit width in bits

    orion_rtr_ptr = new OrionRouter(
        num_in_port,
        num_out_port,
        num_vclass,
        vclass_type_ary,
        num_vc_per_vclass,
        in_buf_per_data_vc,
        in_buf_per_ctrl_vc,
        flit_width,
        orion_cfg_ptr
    );


    //Power Calculation
    double Pbuf_wr_dyn = 0.0;
    double Pbuf_rd_dyn = 0.0;
    double Pvc_arb_local_dyn = 0.0;
    double Pvc_arb_global_dyn = 0.0;
    double Psw_arb_local_dyn = 0.0;
    double Psw_arb_global_dyn = 0.0;
    double Pxbar_dyn = 0.0;
    double Pclk_dyn = 0.0;
    double Ptotal_dyn = 0.0;

    double Pbuf_sta = 0.0;
    double Pvc_arb_sta = 0.0;
    double Psw_arb_sta = 0.0;
    double Pxbar_sta = 0.0;
    double Ptotal_sta = 0.0;

    double Ptotal = 0.0;


    //Dynamic Power

    // Note: For each active arbiter in vc_arb or sw_arb of size T:1,
    // assuming half the requests (T/2) are high on average.
    // TODO: estimate expected value of requests from simulation.

    for (int i = 0; i < num_vclass; i++) {
        // Buffer Write
        Pbuf_wr_dyn +=
            orion_rtr_ptr->calc_dynamic_energy_buf(i, WRITE_MODE, false)*
                (buf_write_count_active[i]/sim_cycles)*freq_Hz;

        // Buffer Read
        Pbuf_rd_dyn +=
            orion_rtr_ptr->calc_dynamic_energy_buf(i, READ_MODE, false)*
                (buf_read_count_active[i]/sim_cycles)*freq_Hz;

        // VC arbitration local
        // Each input VC arbitrates for one output VC (in its vclass)
        // at its output port.
        // Arbiter size: num_vc_per_vclass:1
        Pvc_arb_local_dyn +=
            orion_rtr_ptr->calc_dynamic_energy_local_vc_arb(i,
                num_vc_per_vclass/2, false)*
                    (vc_local_arbit_count_active[i]/sim_cycles)*
                    freq_Hz;

        // VC arbitration global
        // Each output VC chooses one input VC out of all possible requesting
        // VCs (within vclass) at all input ports
        // Arbiter size: num_in_port*num_vc_per_vclass:1
        // Round-robin at each input VC for outvcs in the local stage will
        // try to keep outvc conflicts to the minimum.
        // Assuming conflicts due to request for same outvc from
        // num_in_port/2 requests.
        // TODO: use garnet to estimate this
        Pvc_arb_global_dyn +=
            orion_rtr_ptr->calc_dynamic_energy_global_vc_arb(i,
                num_in_port/2, false)*
                    (vc_global_arbit_count_active[i]/sim_cycles)*
                    freq_Hz;
    }

    // Switch Allocation Local
    // Each input port chooses one input VC as requestor
    // Arbiter size: num_vclass*num_vc_per_vclass:1
    Psw_arb_local_dyn +=
        orion_rtr_ptr->calc_dynamic_energy_local_sw_arb(
            num_vclass*num_vc_per_vclass/2, false)*
            (sw_local_arbit_count/sim_cycles)*
            freq_Hz;

    // Switch Allocation Global
    // Each output port chooses one input port as winner
    // Arbiter size: num_in_port:1
    Psw_arb_global_dyn +=
        orion_rtr_ptr->calc_dynamic_energy_global_sw_arb(
            num_in_port/2, false)*
                (sw_global_arbit_count/sim_cycles)*
                freq_Hz;

    // Crossbar
    Pxbar_dyn +=
        orion_rtr_ptr->calc_dynamic_energy_xbar(false)*
            (crossbar_count/sim_cycles)*freq_Hz;

    // Clock
    Pclk_dyn += orion_rtr_ptr->calc_dynamic_energy_clock()*freq_Hz;

    // Total
    Ptotal_dyn = Pbuf_wr_dyn + Pbuf_rd_dyn +
                 Pvc_arb_local_dyn + Pvc_arb_global_dyn +
                 Psw_arb_local_dyn + Psw_arb_global_dyn +
                 Pxbar_dyn +
                 Pclk_dyn;


    // Static Power
    Pbuf_sta = orion_rtr_ptr->get_static_power_buf();
    Pvc_arb_sta = orion_rtr_ptr->get_static_power_va();
    Psw_arb_sta = orion_rtr_ptr->get_static_power_sa();
    Pxbar_sta = orion_rtr_ptr->get_static_power_xbar();

    Ptotal_sta += Pbuf_sta + Pvc_arb_sta + Psw_arb_sta + Pxbar_sta;

    Ptotal = Ptotal_dyn + Ptotal_sta;

    return Ptotal;
}

double
NetworkLink_d::calculate_power()
{
    OrionConfig* orion_cfg_ptr;
    OrionLink* orion_link_ptr;
    static double freq_Hz;
    double link_length;
    int channel_width;

    // Initialization
    const string cfg_fn = "src/mem/ruby/network/orion/router.cfg";
    orion_cfg_ptr = new OrionConfig(cfg_fn);
    freq_Hz = orion_cfg_ptr->get<double>("FREQUENCY");

    link_length = orion_cfg_ptr->get<double>("LINK_LENGTH");
    channel_width = m_net_ptr->getFlitSize();

    orion_link_ptr = new OrionLink(
        link_length,
        channel_width    /* channel width */,
        orion_cfg_ptr);


    // Dynamic Power
    double sim_cycles =
        (double)(g_eventQueue_ptr->getTime() - m_net_ptr->getRubyStartTime());

    double Plink_dyn = orion_link_ptr->calc_dynamic_energy(channel_width/2)*
        (m_link_utilized/ sim_cycles)*freq_Hz;

    // Static Power
    double Plink_sta = orion_link_ptr->get_static_power();

    double Ptotal = Plink_dyn + Plink_sta;

    return Ptotal;
}