Commit 138c3d96 authored by Noric Couderc's avatar Noric Couderc
Browse files

Refactored PapiRunner handling of normalization

Instead of taking a boolean as a parameter, added methods.
parent 18220e1d
......@@ -4,11 +4,10 @@ import papi.EventSet
import papi.Papi
import papi.PapiException
import java.io.FileWriter
import java.time.Duration
import java.time.Instant
open class PapiRunner(numRuns : Int, counters: CounterSpecification, normalizeFeatures : Boolean) {
constructor(numRuns: Int, specification: CounterSpecification) : this(numRuns, specification, false) {
}
open class PapiRunner(numRuns : Int, counters: CounterSpecification) {
init {
Papi.init()
......@@ -16,7 +15,6 @@ open class PapiRunner(numRuns : Int, counters: CounterSpecification, normalizeFe
val counterSpec = counters
val numRuns = numRuns
val normalizeFeatures = normalizeFeatures
/**
* Empty benchmark:
......@@ -200,7 +198,7 @@ open class PapiRunner(numRuns : Int, counters: CounterSpecification, normalizeFe
return medianLong(data)
}
fun runApplications(syntheticBenchmarks: List<SyntheticBenchmark<*>>): List<Map<String, Double>> {
fun runApplications(syntheticBenchmarks: List<SyntheticBenchmark<*>>): List<Map<String, List<Long>>> {
// return syntheticBenchmarks.map { b -> runApplication(iterations, b) }
val specs = createRunSpecs(syntheticBenchmarks)
val map = specs.map {
......@@ -216,13 +214,20 @@ open class PapiRunner(numRuns : Int, counters: CounterSpecification, normalizeFe
}.map {
it.value
}
// If we are in normalized mode, the scores are normalized by the total number of
// instructions
return when (normalizeFeatures) {
true -> mapsOfSamples.map {
normalizeFeatures(medianFeatures(it))
}
false -> mapsOfSamples.map { medianFeatures(it) }
return mapsOfSamples
}
fun runApplicationsMedian(syntheticBenchmarks: List<SyntheticBenchmark<*>>) : List<Map<String, Double>> {
val mapsOfSamples = runApplications(syntheticBenchmarks)
return mapsOfSamples.map {
medianFeatures(it)
}
}
fun runApplicationsNormalized(syntheticBenchmarks: List<SyntheticBenchmark<*>>) : List<Map<String, Double>> {
val mapsOfMedianFeatures = runApplicationsMedian(syntheticBenchmarks)
return mapsOfMedianFeatures.map {
normalizeFeatures(it)
}
}
......
......@@ -5,12 +5,15 @@ import java.util.*
class SyntheticBenchmarkFeaturePrinter(out: Writer,
papiRunner: PapiRunner,
methodPrintFormat: String)
methodPrintFormat: String,
normalizeFeatures: Boolean)
: SyntheticBenchmarkDataPrinter(out, methodPrintFormat) {
private val papiRunner: PapiRunner = papiRunner
private var benchmarkToCounters = HashMap<SyntheticBenchmark<*>,
Map<String, Double>>()
Map<String, List<Long>>>()
private val normalizeFeatures = normalizeFeatures
/**
* Prints the header for benchmark features
......@@ -34,13 +37,21 @@ class SyntheticBenchmarkFeaturePrinter(out: Writer,
printer.printRecord(identifier, "collection", collection)
// Getting the software perf counters
val softwareCounters = syntheticBenchmark.methodHistogram()
val softwareCounters =
when (normalizeFeatures) {
true -> syntheticBenchmark.methodNormalizedHistogram()
false -> syntheticBenchmark.methodHistogram()
}
for (kvp in softwareCounters) {
printer.printRecord(identifier, getMethodName(kvp.key), kvp.value)
}
val hardwareCounters = benchmarkToCounters[syntheticBenchmark]!!
for (kvp in hardwareCounters) {
val hardwareFeatures = when (normalizeFeatures) {
true -> papiRunner.normalizeFeatures(papiRunner.medianFeatures(hardwareCounters))
false -> papiRunner.medianFeatures(hardwareCounters)
}
for (kvp in hardwareFeatures) {
printer.printRecord(identifier, kvp.key, kvp.value)
}
}
......@@ -51,8 +62,8 @@ class SyntheticBenchmarkFeaturePrinter(out: Writer,
}
private fun runBenchmarks(syntheticBenchmarks: List<SyntheticBenchmark<*>>) {
benchmarkToCounters.clear()
val hardwareCounters = papiRunner.runApplications(syntheticBenchmarks)
syntheticBenchmarks.zip(hardwareCounters).toMap(benchmarkToCounters)
}
}
......
......@@ -78,10 +78,9 @@ class PapiCommandLine : CliktCommand() {
"FEATURE-VECTORS" -> {
val runner = PapiRunner(
numberRuns,
CounterSpecification.fromFile(countersFile),
normalizeFeatures = normalizeFeatures
CounterSpecification.fromFile(countersFile)
)
SyntheticBenchmarkFeaturePrinter(writer, runner, methodOutputFormat)
SyntheticBenchmarkFeaturePrinter(writer, runner, methodOutputFormat, normalizeFeatures)
}
else -> null
}
......
......@@ -73,7 +73,7 @@ public class PapiRunnerTest {
3,
100
);
List<Map<String, Double>> data = runner.runApplications(syntheticBenchmarks);
List<Map<String, Double>> data = runner.runApplicationsMedian(syntheticBenchmarks);
// We check all known Papi counters are in the map
Assert.assertFalse(data.isEmpty());
......@@ -106,7 +106,7 @@ public class PapiRunnerTest {
benchmarks.add(bench);
}
List<Map<String, Double>> results = runner.runApplications(benchmarks);
List<Map<String, Double>> results = runner.runApplicationsMedian(benchmarks);
for (Map<String, Double> r : results) {
Assert.assertFalse(r.isEmpty());
}
......
......@@ -11,13 +11,14 @@ class SyntheticBenchmarkFeaturePrinterTest {
)
val methodOutputFormat = "JAVA-STANDARD-FORMAT"
val normalizeFeatures = false
@Test
fun testEmptyBenchmark() {
val benchmark = MapSyntheticBenchmark(0, 0, HashMap())
val writer = StringWriter()
val csvPrinter = SyntheticBenchmarkFeaturePrinter(writer, runner, methodOutputFormat)
val csvPrinter = SyntheticBenchmarkFeaturePrinter(writer, runner, methodOutputFormat, normalizeFeatures)
csvPrinter.printToCSV(sequenceOf(benchmark))
Assert.assertEquals(
......@@ -29,7 +30,7 @@ class SyntheticBenchmarkFeaturePrinterTest {
val benchmark = MapSyntheticBenchmark(0, 10, HashMap())
val writer = StringWriter()
val csvPrinter = SyntheticBenchmarkFeaturePrinter(writer, runner, "SYNTHETIC-RUN-FORMAT")
val csvPrinter = SyntheticBenchmarkFeaturePrinter(writer, runner, "SYNTHETIC-RUN-FORMAT", normalizeFeatures)
csvPrinter.printToCSV(sequenceOf(benchmark))
......
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