Commit d7ac1c05 authored by Noric Couderc's avatar Noric Couderc
Browse files

Refactoring: Removed need to list of counters

The PAPICounter class checks that the counter works on the current
machine everytime create one. That way, we don't need the list.
parent e53064a4
......@@ -8,7 +8,7 @@ import java.lang.RuntimeException
/**
* Creates an eventSet from a FeatureSet
*/
class EventSetBuilder(val availableCounters : List<PAPICounter>) : FeatureVisitor {
class EventSetBuilder : FeatureVisitor {
private var counterSet : LinkedHashSet<PAPICounter> = java.util.LinkedHashSet()
......@@ -40,19 +40,10 @@ class EventSetBuilder(val availableCounters : List<PAPICounter>) : FeatureVisito
private var eventSet : EventSet? = null
override fun visitFeatureSet(featureSet: FeatureSet) {
Papi.init()
for (f in featureSet.features) {
f.accept(this)
}
counterSet.forEach {
if (availableCounters.contains(it)) {
// OK
} else {
throw RuntimeException("The counter '%s' is not supported on this machine".format(it.counter))
}
}
val counters = counterSet.map { it.toPAPIConstant()!! }.toIntArray()
eventSet = EventSet.create(*counters)
}
......
......@@ -11,10 +11,10 @@ class Experiment(val numberIterations : Int,
val benchmark : BCBenchmarkPackage<*>,
val features : FeatureSet) : FeatureVisitor {
fun run(availableCounters : List<PAPICounter>) : List<Map<Feature, Double>> {
fun run() : List<Map<Feature, Double>> {
if (features.features.isEmpty()) { return listOf() }
val eventSetBuilder = EventSetBuilder(availableCounters)
val eventSetBuilder = EventSetBuilder()
eventSetBuilder.visitFeatureSet(features)
val counters = eventSetBuilder.getCounterSet()
val papiRunner = PapiTracerRunner(numberIterations, counters.toList())
......
......@@ -36,7 +36,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(counters)
val builder = EventSetBuilder(availableCounters)
val builder = EventSetBuilder()
spec.accept(builder)
Assertions.assertEquals(counters.toSet(), builder.getCounterSet())
......@@ -51,7 +51,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(features)
val builder = EventSetBuilder(availableCounters)
val builder = EventSetBuilder()
spec.accept(builder)
val expected = setOf(
......@@ -79,7 +79,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(features)
val builder = EventSetBuilder(availableCounters)
val builder = EventSetBuilder()
spec.accept(builder)
val expected = listOf(
......@@ -100,7 +100,7 @@ class EventSetBuilderTest {
val spec = FeatureSet(features)
// Oh no! empty list of PAPI events!
val builder = EventSetBuilder(listOf())
val builder = EventSetBuilder()
Assertions.assertThrows(RuntimeException::class.java, { spec.accept(builder) })
}
}
\ No newline at end of file
......@@ -14,16 +14,12 @@ class ExperimentTest {
val exp = Experiment(10, bench, FeatureSet(listOf()))
val results = exp.run(listOf())
val results = exp.run()
Assertions.assertTrue(results.isEmpty())
}
@Test
fun testExperiment1() {
val available = listOf(PAPICounter("PAPI_TOT_CYC"),
PAPICounter("PAPI_TOT_INS")
)
val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
val exp = Experiment(10, bench,
FeatureSet(
......@@ -31,7 +27,8 @@ class ExperimentTest {
)
)
val results = exp.run(available)
val results = exp.run()
Assertions.assertEquals(10, results.size)
Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
results.flatMap{ it.keys }.toSet())
......@@ -40,12 +37,6 @@ class ExperimentTest {
@Test
fun testExperiment2() {
// This time, with more complicated features
val available = listOf(
PAPICounter("PAPI_L2_DCM"),
PAPICounter("PAPI_L2_DCA"),
PAPICounter("PAPI_TOT_CYC"),
PAPICounter("PAPI_TOT_INS")
)
val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
......@@ -67,7 +58,7 @@ class ExperimentTest {
)
)
)
val results = exp.run(available)
val results = exp.run()
for (iteration in results) {
Assertions.assertTrue(iteration.containsKey(PAPICounter("PAPI_TOT_INS")))
......@@ -82,22 +73,11 @@ class ExperimentTest {
@Disabled("PAPI_L1_DCA was not available on my machine, so it wouldn't work")
@Test
fun testExperimentBrainyFeatures() {
val available = listOf(
PAPICounter("PAPI_L1_DCM"),
PAPICounter("PAPI_L1_DCA"),
PAPICounter("PAPI_BR_CN"),
PAPICounter("PAPI_L2_DCM"),
PAPICounter("PAPI_BR_MSP"),
PAPICounter("PAPI_L2_DCA"),
PAPICounter("PAPI_TOT_CYC"),
PAPICounter("PAPI_TOT_INS")
)
val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
val exp = Experiment(10, bench, brainyFeatures())
val results = exp.run(available)
val results = exp.run()
Assertions.assertEquals(listOf<Map<Feature, Double>>(), results)
}
}
\ No newline at end of file
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