1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 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: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of the copyright holder nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * Authors: Karthik Chandrasekar 35 * Matthias Jung 36 * Omar Naji 37 * Subash Kannoth 38 * Éder F. Zulian 39 * Felipe S. Prado 40 * 41 */ 42 43#ifndef MEMORY_POWER_MODEL_H 44#define MEMORY_POWER_MODEL_H 45 46#include <numeric> 47#include "MemorySpecification.h" 48#include "MemBankWiseParams.h" 49#include "CommandAnalysis.h" 50 51namespace Data { 52class MemoryPowerModel { 53 public: 54 55 MemoryPowerModel(); 56 57 // Calculate energy and average power consumption for the given memory 58 // command trace 59 void power_calc(const MemorySpecification& memSpec, 60 const CommandAnalysis& c, 61 int term, 62 const MemBankWiseParams& bwPowerParams); 63 64 // Used to calculate self-refresh active energy 65 static double engy_sref(double idd6, 66 double idd3n, 67 double idd5, 68 double vdd, 69 double sref_cycles_idd6, 70 double sref_ref_act_cycles, 71 double sref_ref_pre_cycles, 72 double spup_ref_act_cycles, 73 double spup_ref_pre_cycles, 74 double clk); 75 static double engy_sref_banks(double idd6, 76 double idd3n, 77 double idd5, 78 double vdd, 79 double sref_cycles, 80 double sref_ref_act_cycles, 81 double sref_ref_pre_cycles, 82 double spup_ref_act_cycles, 83 double spup_ref_pre_cycles, 84 double clk, 85 double esharedPASR, 86 const MemBankWiseParams& bwPowerParams, 87 unsigned bnkIdx, 88 int64_t nbrofBanks); 89 90 int64_t total_cycles; 91 92 int64_t window_cycles; 93 94 struct Energy { 95 // Total energy of all activates 96 double act_energy; 97 std::vector<double> act_energy_banks; 98 99 // Total energy of all precharges 100 double pre_energy; 101 std::vector<double> pre_energy_banks; 102 103 // Total energy of all reads 104 double read_energy; 105 std::vector<double> read_energy_banks; 106 107 // Total energy of all writes 108 double write_energy; 109 std::vector<double> write_energy_banks; 110 111 // Total energy of all refreshes 112 double ref_energy; 113 std::vector<double> ref_energy_banks; 114 115 // Bankwise refresh energy 116 std::vector<double> refb_energy_banks; 117 118 // Total background energy of all active standby cycles 119 double act_stdby_energy; 120 std::vector<double> act_stdby_energy_banks; 121 122 // Total background energy of all precharge standby cycles 123 double pre_stdby_energy; 124 std::vector<double> pre_stdby_energy_banks; 125 126 // Total energy of idle cycles in the active mode 127 double idle_energy_act; 128 std::vector<double> idle_energy_act_banks; 129 130 // Total energy of idle cycles in the precharge mode 131 double idle_energy_pre; 132 std::vector<double> idle_energy_pre_banks; 133 134 // Total trace/pattern energy 135 double total_energy; 136 std::vector<double> total_energy_banks; 137 138 // Window energy 139 double window_energy; 140 141 // Average Power 142 double average_power; 143 144 // Energy consumed in active/precharged fast/slow-exit modes 145 double f_act_pd_energy; 146 std::vector<double> f_act_pd_energy_banks; 147 148 double f_pre_pd_energy; 149 std::vector<double> f_pre_pd_energy_banks; 150 151 double s_act_pd_energy; 152 std::vector<double> s_act_pd_energy_banks; 153 154 double s_pre_pd_energy; 155 std::vector<double> s_pre_pd_energy_banks; 156 157 // Energy consumed in self-refresh mode 158 double sref_energy; 159 std::vector<double> sref_energy_banks; 160 161 // Energy consumed in auto-refresh during self-refresh mode 162 double sref_ref_energy; 163 std::vector<double> sref_ref_energy_banks; 164 165 double sref_ref_act_energy; 166 std::vector<double> sref_ref_act_energy_banks; 167 168 double sref_ref_pre_energy; 169 std::vector<double> sref_ref_pre_energy_banks; 170 171 // Energy consumed in powering-up from self-refresh mode 172 double spup_energy; 173 std::vector<double> spup_energy_banks; 174 175 // Energy consumed in auto-refresh during self-refresh power-up 176 double spup_ref_energy; 177 std::vector<double> spup_ref_energy_banks; 178 179 double spup_ref_act_energy; 180 std::vector<double> spup_ref_act_energy_banks; 181 182 double spup_ref_pre_energy; 183 std::vector<double> spup_ref_pre_energy_banks; 184 185 // Energy consumed in powering-up from active/precharged power-down modes 186 double pup_act_energy; 187 std::vector<double> pup_act_energy_banks; 188 189 double pup_pre_energy; 190 std::vector<double> pup_pre_energy_banks; 191 192 // Energy consumed by IO and Termination 193 double read_io_energy; // Read IO Energy 194 double write_term_energy; // Write Termination Energy 195 double read_oterm_energy; // Read Termination Energy from idle rank 196 double write_oterm_energy; // Write Termination Energy from idle rank 197 // Total IO and Termination Energy 198 double io_term_energy; 199 }; 200 201 struct Power { 202 // Power measures corresponding to IO and Termination 203 double IO_power; // Read IO Power 204 double WR_ODT_power; // Write ODT Power 205 double TermRD_power; // Read Termination in idle rank (in dual-rank systems) 206 double TermWR_power; // Write Termination in idle rank (in dual-rank systems) 207 208 // Average Power 209 double average_power; 210 211 // Window Average Power 212 double window_average_power; 213 }; 214 215 // Print the power and energy 216 void power_print(const MemorySpecification& memSpec, 217 int term, 218 const CommandAnalysis& c, 219 bool bankwiseMode) const; 220 221 // To derive IO and Termination Power measures using DRAM specification 222 void io_term_power(const MemorySpecification& memSpec); 223 224 Energy energy; 225 Power power; 226 227 private: 228 double calcIoTermEnergy(int64_t cycles, double period, double power, int64_t numBits) const; 229 // Sum quantities (e.g., operations, energy, cycles) that are stored in a per bank basis returning the total amount. 230 template <typename T> T sum(const std::vector<T> vec) const { return std::accumulate(vec.begin(), vec.end(), static_cast<T>(0)); } 231}; 232 233class EnergyDomain { 234 public: 235 EnergyDomain(double voltage, double clkPeriod) : 236 voltage(voltage), 237 clkPeriod(clkPeriod) 238 {} 239 240 double calcTivEnergy(int64_t cycles, double current) const; 241 double getVoltage() const{ return voltage; }; 242 private: 243 const double voltage; 244 const double clkPeriod; 245}; 246 247} 248#endif // ifndef MEMORY_POWER_MODEL_H 249