Commit 35af5e80 authored by Noric Couderc's avatar Noric Couderc
Browse files

Refactoring: number of runs now class field

The number of benchmarks was passed in a lot of places, now it's only
passed to the class, all methods use it.
parent 4e5ceb5f
......@@ -7,12 +7,13 @@ import java.io.FileWriter
import java.time.Duration
import java.time.Instant
open class PapiRunner(counters: CounterSpecification) {
open class PapiRunner(numRuns : Int, counters: CounterSpecification) {
init {
Papi.init()
}
val counterSpec = counters
val numRuns = numRuns
/**
* Empty benchmark:
......@@ -55,7 +56,7 @@ open class PapiRunner(counters: CounterSpecification) {
* Runs a function several times
* @return A map from PAPI counter names to list of values
*/
inline fun runFunction(numRuns: Int, counter: String, function: () -> Unit): MutableList<Long> {
inline fun runFunction(counter: String, function: () -> Unit): MutableList<Long> {
val counterId = counterSpec.getCounter(counter)!!
// We record only one counter
var evset = EventSet.create()
......@@ -88,7 +89,7 @@ open class PapiRunner(counters: CounterSpecification) {
/**
* Creates a list of specifications of what counter to get from what benchmarks
*/
fun createRunSpecs(numRuns : Int, syntheticBenchmarks: List<SyntheticBenchmark<*>>): List<RunSpec> {
fun createRunSpecs(syntheticBenchmarks: List<SyntheticBenchmark<*>>): List<RunSpec> {
val counters = counterSpec.currentSpec
// Let's say we want to minimize the counter change
......@@ -109,7 +110,7 @@ open class PapiRunner(counters: CounterSpecification) {
val writer = FileWriter("/dev/null")
val samples = mutableListOf<Long>()
for (i in 0 until spec.numRuns) {
for (i in 0 until numRuns) {
val app = spec.syntheticBenchmark
val evset = spec.eventSet
// We do the measurements
......@@ -141,7 +142,7 @@ open class PapiRunner(counters: CounterSpecification) {
* A function for running one benchmark, gathering all the hardware counters
* Present in the counter specification we have.
*/
fun runApplication(numRuns: Int, app: SyntheticBenchmark<*>) : Map<String, List<Long>> {
fun runApplication(app: SyntheticBenchmark<*>) : Map<String, List<Long>> {
// We will write the aggregators to nowhere
val writer = FileWriter("/dev/null")
// We get integers for all the counters.
......@@ -191,14 +192,14 @@ open class PapiRunner(counters: CounterSpecification) {
* @param function The function to benchmark
* @return A map from PAPI counter names to the median of their values over numRuns
*/
fun runFunctionMedian(numRuns: Int, counter: String, function: () -> Unit): Double {
val data = runFunction(numRuns, counter, function)
fun runFunctionMedian(counter: String, function: () -> Unit): Double {
val data = runFunction(counter, function)
return medianLong(data)
}
fun runApplications(iterations: Int, syntheticBenchmarks: List<SyntheticBenchmark<*>>): List<Map<String, List<Long>>> {
fun runApplications(syntheticBenchmarks: List<SyntheticBenchmark<*>>): List<Map<String, List<Long>>> {
// return syntheticBenchmarks.map { b -> runApplication(iterations, b) }
val specs = createRunSpecs(iterations, syntheticBenchmarks)
val specs = createRunSpecs(syntheticBenchmarks)
val map = specs.map {
val samples = runSpec(it)
Pair(it, samples)
......
......@@ -48,8 +48,7 @@ class SyntheticBenchmarkFeaturePrinter(out: Writer, papiRunner: PapiRunner) : Sy
}
private fun runBenchmarks(syntheticBenchmarks: List<SyntheticBenchmark<*>>) {
val hardwareCounters = papiRunner.runApplications(10,
syntheticBenchmarks)
val hardwareCounters = papiRunner.runApplications(syntheticBenchmarks)
syntheticBenchmarks.zip(hardwareCounters).toMap(benchmarkToCounters)
}
......
......@@ -67,6 +67,7 @@ class PapiCommandLine : CliktCommand() {
"SOFTWARE-COUNTERS" -> SyntheticBenchmarkHistPrinter(writer)
"FEATURE-VECTORS" -> {
val runner = PapiRunner(
10,
CounterSpecification.fromFile(File(papiCountersFileName))
)
SyntheticBenchmarkFeaturePrinter(writer, runner)
......@@ -89,10 +90,10 @@ class PapiCommandLine : CliktCommand() {
return jmhRows.map { x -> x.generateSyntheticBenchmark()!! }
}
private fun createFeatureVectors(writer : Writer, benchmarks : List<SyntheticBenchmark<*>>):
private fun createFeatureVectors(writer : Writer, numberRuns : Int, benchmarks : List<SyntheticBenchmark<*>>):
SyntheticBenchmarkFeaturePrinter {
val counterSpec = CounterSpecification.fromFile(File("papi_avail"))
val r = PapiRunner(counterSpec)
val r = PapiRunner(numberRuns, counterSpec)
return SyntheticBenchmarkFeaturePrinter(writer, r)
}
......
......@@ -8,9 +8,6 @@ import se.lth.cs.*;
import se.lth.cs.SyntheticBenchmarkGeneration.ListSyntheticBenchmarkGenerator;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;
......@@ -27,7 +24,7 @@ public class PapiRunnerTest {
File papiAvailableCounters = new File("papi_avail");
Assert.assertTrue(papiAvailableCounters.exists());
specification = CounterSpecification.Companion.fromFile(papiAvailableCounters);
runner = new PapiRunner(specification);
runner = new PapiRunner(10, specification);
}
/**
* Tests that all performance counters can be put in an eventSet
......@@ -71,10 +68,7 @@ public class PapiRunnerTest {
3,
100
);
PapiRunner runner = new PapiRunner(
CounterSpecification.Companion.fromFile(new File("papi_avail"))
);
List<Map<String, List<Long>>> data = runner.runApplications(10, syntheticBenchmarks);
List<Map<String, List<Long>>> data = runner.runApplications(syntheticBenchmarks);
// We check all known Papi counters are in the map
Assert.assertFalse(data.isEmpty());
......@@ -90,11 +84,7 @@ public class PapiRunnerTest {
public void testPapiRunBenchmark() throws PapiException {
MapSyntheticBenchmark bench = new MapSyntheticBenchmark(0, 100, new HashMap());
PapiRunner runner = new PapiRunner(
CounterSpecification.Companion.fromFile(new File("papi_avail"))
);
Map<String, List<Long>> results = runner.runApplication(100, bench);
Map<String, List<Long>> results = runner.runApplication(bench);
Assert.assertFalse(results.isEmpty());
for (String k : results.keySet()) {
Assert.assertFalse(results.get(k).isEmpty());
......@@ -104,16 +94,14 @@ public class PapiRunnerTest {
@Test
public void testRunManyBenchmarks() {
// We want to test our setup can handle many benchmarks without crashing.
PapiRunner runner = new PapiRunner(
CounterSpecification.Companion.fromFile(new File("papi_avail"))
);
List<SyntheticBenchmark<?>> benchmarks = new ArrayList<>();
for (int i = 0; i < 100; ++i) {
MapSyntheticBenchmark bench = new MapSyntheticBenchmark(i, 100, new HashMap<>());
benchmarks.add(bench);
}
List<Map<String, List<Long>>> results = runner.runApplications(10, benchmarks);
List<Map<String, List<Long>>> results = runner.runApplications(benchmarks);
for (Map<String, List<Long>> r : results) {
Assert.assertFalse(r.isEmpty());
for (String k : r.keySet()) {
......@@ -135,7 +123,7 @@ public class PapiRunnerTest {
apps.add(setsmall);
apps.add(setbig);
List<Map<String, List<Long>>> result = runner.runApplications(10, apps);
List<Map<String, List<Long>>> result = runner.runApplications(apps);
Assert.assertEquals(
result.get(0).keySet(),
result.get(1).keySet()
......
......@@ -6,6 +6,7 @@ import java.io.StringWriter
class SyntheticBenchmarkFeaturePrinterTest {
val runner = PapiRunner(
10,
CounterSpecification.fromFile(File("papi_avail"))
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment