PapiBenchmarkAnalyzer.kt 2.09 KB
Newer Older
Noric Couderc's avatar
Noric Couderc committed
1
2
package se.lth.cs.papicounters

3
4
import papi.EventSet
import se.lth.cs.bcgen.BCBenchmarkPackage
5
import se.lth.cs.timing.OperationType
6
import se.lth.cs.util.Feature
Noric Couderc's avatar
Noric Couderc committed
7
import se.lth.cs.util.FeatureSet
8

Noric Couderc's avatar
Noric Couderc committed
9
interface PapiBenchmarkAnalyzer {
10
    class RunSpec(val numberRuns : Int,
Noric Couderc's avatar
Noric Couderc committed
11
                  val features : FeatureSet,
12
                  val syntheticBenchmark: BCBenchmarkPackage<*>) {
13

14
15
        val eventSetBuilder = EventSetBuilder(features)

Noric Couderc's avatar
Noric Couderc committed
16
        fun eventSet(): EventSet {
17
            return eventSetBuilder.getEventSet()
Noric Couderc's avatar
Noric Couderc committed
18
19
        }

20
21
22
23
24
        /**
         Tells you if a RunSpec can be sampled in one single pass
         for that, the counters have to be 2 counters + (optionally) PAPI_TOT_CYC and PAPI_TOT_INS
         */
        fun canBeSampled(): Boolean {
25
26
27
28
            return counters().filter { ! it.isSpecial() }.size <= 2
        }

        fun counters() : List<PAPICounter> {
29
            return eventSetBuilder.getCounterSet().toList()
30
31
32
33
        }
    }


34
    data class BenchmarkRunSample(val counter : PAPICounter, var value : Double)
35
36
37

    class BenchmarkRunData(val benchmark : BCBenchmarkPackage<*>,
                           val iteration : Int,
38
39
                           val samples : List<BenchmarkRunSample>,
                           val cyclesPerOpType : Map<OperationType, Double>) {
40

41
42
        fun normalizationCounter(): PAPICounter {
            return PAPICounter("PAPI_TOT_CYC")
43
44
45
46
47
48
49
50
51
        }

        fun normalized(): BenchmarkRunData {
            val cycles = samples.find { it.counter == normalizationCounter() }!!.value

            val newSamples = this.samples.map {
                BenchmarkRunSample(it.counter, it.value / cycles)
            }

52
53
54
55
56
            val newCycles = this.cyclesPerOpType.mapValues {
                it.value / cycles
            }

            return BenchmarkRunData(this.benchmark, this.iteration, newSamples, newCycles)
57
58
59
        }
    }

60
    fun runSpec(spec : RunSpec) : List<BenchmarkRunData>
61

62
    fun runApplications(numberRuns: Int,
Noric Couderc's avatar
Noric Couderc committed
63
                        features : FeatureSet,
64
                        syntheticBenchmarks: List<BCBenchmarkPackage<*>>): List<BenchmarkRunData>
Noric Couderc's avatar
Noric Couderc committed
65
}