Commit 3db25dd3 authored by Noric Couderc's avatar Noric Couderc
Browse files

Refactored running applications with PAPI.

Creates list of objects specifying what to run, which gives more control
on the iteration mechanism. Prevents a bug when trying to create
eventsets too fast.
parent 537e6686
......@@ -80,6 +80,61 @@ open class PapiRunner(counters: CounterSpecification) {
return values
}
data class RunSpec(val numRuns: Int,
val counter : String,
val eventSet: EventSet,
val syntheticBenchmark: SyntheticBenchmark<*>)
/**
* Creates a list of specifications of what counter to get from what benchmarks
*/
fun createRunSpecs(numRuns : Int, syntheticBenchmarks: MutableList<SyntheticBenchmark<*>>): List<RunSpec> {
val counters = counterSpec.currentSpec
// Let's say we want to minimize the counter change
// We put it in the outer loop
val specification = mutableListOf<RunSpec>()
for (c in counters) {
val eventSet = EventSet.create(c.value)
for (b in syntheticBenchmarks) {
for (i in 0 until numRuns) {
specification.add(RunSpec(i, c.key, eventSet, b))
}
}
}
return specification.toList()
}
fun runSpec(spec : RunSpec): List<Long> {
val writer = FileWriter("/dev/null")
val samples = mutableListOf<Long>()
for (i in 0 until spec.numRuns) {
val app = spec.syntheticBenchmark
val evset = spec.eventSet
// We do the measurements
app.reset(app.baseDataStructureSize)
var accumulator = 0
evset.start()
while (app.hasNext()) {
val result: Int? = app.invokeCurrentMethod() as? Int
accumulator += result ?: 1
app.tick()
}
val resultDataStructure = app.getDataStructure()
evset.stop()
// We reset the benchmark
app.reset(0)
// Write the result somewhere to prevent dead code elimination
writer.write(accumulator)
writer.write(resultDataStructure.toString())
// We record the data
samples.addAll(evset.counters.toList())
}
return samples
}
/**
* A function for running one benchmark, gathering all the hardware counters
......@@ -93,7 +148,8 @@ open class PapiRunner(counters: CounterSpecification) {
var result = mutableMapOf<String, List<Long>>()
for (counter in counters.keys) {
val evset = EventSet.create(counters[counter]!!)
val counterId = counterSpec.getCounter(counter)
val evset = EventSet.create(counterId!!)
val samples = mutableListOf<Long>()
for (run in 0 until numRuns) {
// We do the measurements
......@@ -140,6 +196,20 @@ open class PapiRunner(counters: CounterSpecification) {
}
fun runApplications(iterations: Int, syntheticBenchmarks: MutableList<SyntheticBenchmark<*>>): List<Map<String, List<Long>>> {
return syntheticBenchmarks.map { b -> runApplication(iterations, b) }
// return syntheticBenchmarks.map { b -> runApplication(iterations, b) }
val specs = createRunSpecs(iterations, syntheticBenchmarks)
val map = specs.map {
val samples = runSpec(it)
Pair(it, samples)
}
// TODO: Return a Map<Pair<CounterString, Benchmark>, List<Long>> instead of this mess.
val map1 = map.groupBy { s -> s.first.syntheticBenchmark }
return map1.mapValues {
it.value.map {
Pair(it.first.counter, it.second)
}.toMap()
}.map {
it.value
}
}
}
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