lib_test.cc revision 10428:0caf62b57dfd
1/* 2 * Copyright (c) 2014, TU Delft, TU Eindhoven and TU Kaiserslautern 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * 3. Neither the name of the copyright holder nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 26 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * 32 * Authors: Matthias Jung, Omar Naji 33 * 34 */ 35 36#include <string> 37#include "libdrampower/LibDRAMPower.h" 38 39#if USE_XERCES 40 #include "xmlparser/MemSpecParser.h" 41#endif 42 43using namespace std; 44using namespace Data; 45 46int main(int argc, char* argv[]) 47{ 48 assert(argc == 2); 49 //Setup of DRAMPower for your simulation 50 string filename; 51 //type path to memspec file 52 filename = argv[1]; 53 //Parsing the Memspec specification of found in memspec folder 54 #if USE_XERCES 55 MemorySpecification memSpec(MemSpecParser::getMemSpecFromXML(filename)); 56 #else 57 MemorySpecification memSpec; 58 #endif 59 libDRAMPower test = libDRAMPower(memSpec, 0); 60 // During the simulation you can report activity 61 // to DRAMPower with the doCommand(...) function: 62 test.doCommand(MemCommand::ACT,0,35); 63 test.doCommand(MemCommand::RDA,0,50); 64 test.doCommand(MemCommand::ACT,4,51); 65 test.doCommand(MemCommand::RDA,4,66); 66 test.doCommand(MemCommand::ACT,0,86); 67 test.doCommand(MemCommand::RDA,0,101); 68 test.doCommand(MemCommand::ACT,2,102); 69 //This functionality is still not implemented. 70 test.updateCounters(false); 71 test.doCommand(MemCommand::RDA,2,117); 72 test.doCommand(MemCommand::ACT,5,119); 73 test.doCommand(MemCommand::RDA,5,134); 74 test.doCommand(MemCommand::ACT,0,137); 75 test.doCommand(MemCommand::RDA,0,152); 76 test.doCommand(MemCommand::ACT,3,159); 77 test.doCommand(MemCommand::RDA,3,174); 78 test.doCommand(MemCommand::ACT,0,195); 79 test.doCommand(MemCommand::RDA,0,210); 80 test.doCommand(MemCommand::ACT,4,232); 81 test.doCommand(MemCommand::WRA,4,247); 82 test.doCommand(MemCommand::PDN_F_ACT,3,248); 83 84 //set bool to true when this is the last update of the counters 85 test.updateCounters(true); 86 87 // At the end of your simulation call the getEnergy(...) 88 // function to print the power report 89 test.calcEnergy(); 90 91 // Accesing the results: 92 93 // Number of issued Commands 94 std::cout << "# of acts" << "\t" <<test.counters.numberofacts << endl; 95 std::cout << "# of reads" << "\t" <<test.counters.numberofreads << endl; 96 std::cout << "# of precharges" << "\t" <<test.counters.numberofpres << endl; 97 // many other timing parameters in test.mpm.timings 98 99 //ENERGIES per Rank 100 std::cout << "ACT Cmd Energy" << "\t" << test.getEnergy().act_energy << endl; 101 std::cout << "PRE Cmd Energy" << "\t" << test.getEnergy().pre_energy << endl; 102 std::cout << "Read Cmd Energy" << "\t" << test.getEnergy().read_energy << endl; 103 std::cout << "Write Cmd Energy" << "\t" << test.getEnergy().write_energy << endl; 104 //Standby Energy for 1 rank 105 //In total energy calculated for both ranks= test.memSpec.memArchSpec * 106 //test.getEnergy().act_stdby_energy 107 std::cout << "ACT Std Energy" << "\t" << test.getEnergy().act_stdby_energy << endl; 108 //total active standby energy for both ranks 109 std::cout << "ACT Std Energy total ranks" << "\t" << memSpec.memArchSpec.nbrOfRanks * 110 test.getEnergy().act_stdby_energy << "\n" ; 111 std::cout << "PRE Std Energy" << "\t" << test.getEnergy().pre_stdby_energy << endl; 112 std::cout << "Total Energy" << "\t" << test.getEnergy().total_energy << endl; 113 //many other energies in test.mpm.energy 114 115 //Powers per Rank 116 std::cout << "Average Power" << "\t" << test.getPower().average_power << endl; 117 //many other powers in test.getPower() 118 119 // Test clearState function. 120 test.clearState(); 121 return 0; 122} 123