summaryrefslogtreecommitdiff
path: root/ext/drampower/test/libdrampowertest
diff options
context:
space:
mode:
Diffstat (limited to 'ext/drampower/test/libdrampowertest')
-rw-r--r--ext/drampower/test/libdrampowertest/Makefile82
-rw-r--r--ext/drampower/test/libdrampowertest/commands.trace19
-rw-r--r--ext/drampower/test/libdrampowertest/lib_test.cc122
3 files changed, 223 insertions, 0 deletions
diff --git a/ext/drampower/test/libdrampowertest/Makefile b/ext/drampower/test/libdrampowertest/Makefile
new file mode 100644
index 000000000..354309fd4
--- /dev/null
+++ b/ext/drampower/test/libdrampowertest/Makefile
@@ -0,0 +1,82 @@
+# Copyright (c) 2012-2014, TU Delft
+# Copyright (c) 2012-2014, TU Eindhoven
+# Copyright (c) 2012-2014, TU Kaiserslautern
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. 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.
+#
+# 3. Neither the name of the copyright holder 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
+# HOLDER 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: Matthias Jung, Omar Naji, Sven Goossens
+#
+
+ifeq ($(COVERAGE),1)
+ GCOVFLAGS := -fprofile-arcs -ftest-coverage
+else
+ GCOVFLAGS :=
+endif
+
+# Optimization flags. Usually you should not optimize until you have finished
+# debugging, except when you want to detect dead code.
+OPTCXXFLAGS ?=
+
+# Debugging flags.
+DBGCXXFLAGS ?= -g ${GCOVFLAGS}
+
+# Common warning flags shared by both C and C++.
+WARNFLAGS := -W -pedantic-errors -Wextra -Werror \
+ -Wformat -Wformat-nonliteral -Wpointer-arith \
+ -Wcast-align -Wconversion -Wall -Werror
+
+# Sum up the flags.
+CXXFLAGS := -O ${WARNFLAGS} ${DBGCXXFLAGS} ${OPTCXXFLAGS} -std=c++98
+
+DRAMPOWER_PATH ?= ../..
+MYPATH := ${DRAMPOWER_PATH}/test/libdrampowertest
+USE_XERCES ?= 1
+
+# Name of the generated binary.
+BINARY := ${MYPATH}/library_test
+
+ifeq ($(USE_XERCES),1)
+ LIBS := -lxerces-c -ldrampowerxml -ldrampower
+else
+ LIBS := -ldrampower
+endif
+
+all:
+ g++ ${MYPATH}/lib_test.cc ${CXXFLAGS} -iquote ${DRAMPOWER_PATH}/src -DUSE_XERCES=${USE_XERCES} -L${DRAMPOWER_PATH}/src/ ${LIBS} -o $(BINARY)
+
+clean:
+ rm -f $(BINARY)
+
+coverageclean:
+ $(RM) lib_test.gcno lib_test.gcda
+
+test: all
+ ./$(BINARY) ${DRAMPOWER_PATH}/memspecs/MICRON_1Gb_DDR2-1066_16bit_H.xml
+
+.PHONY: clean test
diff --git a/ext/drampower/test/libdrampowertest/commands.trace b/ext/drampower/test/libdrampowertest/commands.trace
new file mode 100644
index 000000000..3463586de
--- /dev/null
+++ b/ext/drampower/test/libdrampowertest/commands.trace
@@ -0,0 +1,19 @@
+35,ACT,0
+50,RDA,0
+51,ACT,4
+66,RDA,4
+86,ACT,0
+101,RDA,0
+102,ACT,2
+117,RDA,2
+119,ACT,5
+134,RDA,5
+137,ACT,0
+152,RDA,0
+159,ACT,3
+174,RDA,3
+195,ACT,0
+210,RDA,0
+232,ACT,4
+247,WRA,4
+248,PDN_F_ACT,3
diff --git a/ext/drampower/test/libdrampowertest/lib_test.cc b/ext/drampower/test/libdrampowertest/lib_test.cc
new file mode 100644
index 000000000..f382a727e
--- /dev/null
+++ b/ext/drampower/test/libdrampowertest/lib_test.cc
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2014, TU Delft, TU Eindhoven and TU Kaiserslautern
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of the copyright holder 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
+ * HOLDER 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: Matthias Jung, Omar Naji
+ *
+ */
+
+#include <string>
+#include "libdrampower/LibDRAMPower.h"
+
+#if USE_XERCES
+ #include "xmlparser/MemSpecParser.h"
+#endif
+
+using namespace std;
+using namespace Data;
+
+int main(int argc, char* argv[])
+{
+ assert(argc == 2);
+ //Setup of DRAMPower for your simulation
+ string filename;
+ //type path to memspec file
+ filename = argv[1];
+ //Parsing the Memspec specification of found in memspec folder
+ #if USE_XERCES
+ MemorySpecification memSpec(MemSpecParser::getMemSpecFromXML(filename));
+ #else
+ MemorySpecification memSpec;
+ #endif
+ libDRAMPower test = libDRAMPower(memSpec, 0);
+ // During the simulation you can report activity
+ // to DRAMPower with the doCommand(...) function:
+ test.doCommand(MemCommand::ACT,0,35);
+ test.doCommand(MemCommand::RDA,0,50);
+ test.doCommand(MemCommand::ACT,4,51);
+ test.doCommand(MemCommand::RDA,4,66);
+ test.doCommand(MemCommand::ACT,0,86);
+ test.doCommand(MemCommand::RDA,0,101);
+ test.doCommand(MemCommand::ACT,2,102);
+ //This functionality is still not implemented.
+ test.updateCounters(false);
+ test.doCommand(MemCommand::RDA,2,117);
+ test.doCommand(MemCommand::ACT,5,119);
+ test.doCommand(MemCommand::RDA,5,134);
+ test.doCommand(MemCommand::ACT,0,137);
+ test.doCommand(MemCommand::RDA,0,152);
+ test.doCommand(MemCommand::ACT,3,159);
+ test.doCommand(MemCommand::RDA,3,174);
+ test.doCommand(MemCommand::ACT,0,195);
+ test.doCommand(MemCommand::RDA,0,210);
+ test.doCommand(MemCommand::ACT,4,232);
+ test.doCommand(MemCommand::WRA,4,247);
+ test.doCommand(MemCommand::PDN_F_ACT,3,248);
+
+ //set bool to true when this is the last update of the counters
+ test.updateCounters(true);
+
+ // At the end of your simulation call the getEnergy(...)
+ // function to print the power report
+ test.calcEnergy();
+
+ // Accesing the results:
+
+ // Number of issued Commands
+ std::cout << "# of acts" << "\t" <<test.counters.numberofacts << endl;
+ std::cout << "# of reads" << "\t" <<test.counters.numberofreads << endl;
+ std::cout << "# of precharges" << "\t" <<test.counters.numberofpres << endl;
+ // many other timing parameters in test.mpm.timings
+
+ //ENERGIES per Rank
+ std::cout << "ACT Cmd Energy" << "\t" << test.getEnergy().act_energy << endl;
+ std::cout << "PRE Cmd Energy" << "\t" << test.getEnergy().pre_energy << endl;
+ std::cout << "Read Cmd Energy" << "\t" << test.getEnergy().read_energy << endl;
+ std::cout << "Write Cmd Energy" << "\t" << test.getEnergy().write_energy << endl;
+ //Standby Energy for 1 rank
+ //In total energy calculated for both ranks= test.memSpec.memArchSpec *
+ //test.getEnergy().act_stdby_energy
+ std::cout << "ACT Std Energy" << "\t" << test.getEnergy().act_stdby_energy << endl;
+ //total active standby energy for both ranks
+ std::cout << "ACT Std Energy total ranks" << "\t" << memSpec.memArchSpec.nbrOfRanks *
+ test.getEnergy().act_stdby_energy << "\n" ;
+ std::cout << "PRE Std Energy" << "\t" << test.getEnergy().pre_stdby_energy << endl;
+ std::cout << "Total Energy" << "\t" << test.getEnergy().total_energy << endl;
+ //many other energies in test.mpm.energy
+
+ //Powers per Rank
+ std::cout << "Average Power" << "\t" << test.getPower().average_power << endl;
+ //many other powers in test.getPower()
+
+ // Test clearState function.
+ test.clearState();
+ return 0;
+}