ExperimentTest.kt 5.23 KB
Newer Older
1
import org.junit.FixMethodOrder
Noric Couderc's avatar
Noric Couderc committed
2
3
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
4
5
6
import org.junit.runners.MethodSorters
import papi.Constants
import papi.EventSet
Noric Couderc's avatar
Noric Couderc committed
7
8
import se.lth.cs.bcgen.BCBenchmarkPackage
import se.lth.cs.papicounters.PAPICounter
9
import se.lth.cs.papicounters.PapiTracerRunner
10
import se.lth.cs.smartmodules.tracer.Tracer
Noric Couderc's avatar
Noric Couderc committed
11
12
import se.lth.cs.timing.OperationType
import se.lth.cs.util.*
13
import java.util.stream.Collectors
Noric Couderc's avatar
Noric Couderc committed
14

15
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
16
class ExperimentTest {
Noric Couderc's avatar
Noric Couderc committed
17

18
    val runner = PapiTracerRunner()
19

Noric Couderc's avatar
Noric Couderc committed
20
21
22
23
    @Test
    fun testExperimentNoFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

24
        val exp = Experiment(10, bench, FeatureSet(), runner)
Noric Couderc's avatar
Noric Couderc committed
25

26
        val results = exp.run().collect(Collectors.toList())
Noric Couderc's avatar
Noric Couderc committed
27
28
29
30
31
32
33
        Assertions.assertTrue(results.isEmpty())
    }

    @Test
    fun testExperiment1() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
        val exp = Experiment(10, bench,
34
            FeatureSet(PAPICounter("PAPI_TOT_CYC")),
35
            runner
Noric Couderc's avatar
Noric Couderc committed
36
37
        )

38
        val results = exp.run().collect(Collectors.toList())
39

Noric Couderc's avatar
Noric Couderc committed
40
        Assertions.assertEquals(10, results.size)
Noric Couderc's avatar
Noric Couderc committed
41
42
43
44
        Assertions.assertEquals(
            IntRange(0, 9).toList(),
            results.map { it.iterationNumber }
        )
45
        Assertions.assertTrue(results.all { it.values[PAPICounter("PAPI_TOT_CYC")]!! > 0.0 })
Noric Couderc's avatar
Noric Couderc committed
46
        Assertions.assertEquals(setOf(PAPICounter("PAPI_TOT_CYC")),
Noric Couderc's avatar
Noric Couderc committed
47
            results.flatMap{ it.values.keys }.toSet())
Noric Couderc's avatar
Noric Couderc committed
48
49
    }

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    @Test
    fun testOverflowExperiment() {
        val longBench = BCBenchmarkPackage.LIST(1234, 1000000, 0, ArrayList<Int>())
        val shortBench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

        val costPerDelete = CostFeature(OperationType.DELETE)
        val cacheMissRate = FeatureRatio(
            PAPICounter("PAPI_L2_DCM"),
            PAPICounter("PAPI_L2_DCA")
        )
        val exp = Experiment(10, longBench,
            FeatureSet(
                PAPICounter("PAPI_TOT_INS"),
                PAPICounter("PAPI_TOT_CYC"),
                cacheMissRate,
                costPerDelete
            ),
            runner
        )

        // This should trigger an overflow but it's silent
        val results = exp.run().collect(Collectors.toList())

        Assertions.assertTrue(results.all { it.values[PAPICounter("PAPI_TOT_CYC")]!! > 0.0 })

        // Running another experiment afterwards should still work.
        val exp2 = Experiment(10, shortBench, FeatureSet(PAPICounter("PAPI_TOT_CYC")), runner)

        exp2.run()
    }

Noric Couderc's avatar
Noric Couderc committed
81
82
83
84
85
86
87
88
89
90
91
    @Test
    fun testExperiment2() {
        // This time, with more complicated features

        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

        val cacheMissRate = FeatureRatio(
            PAPICounter("PAPI_L2_DCM"),
            PAPICounter("PAPI_L2_DCA")
        )

92
        val costPerDelete = CostFeature(OperationType.DELETE)
Noric Couderc's avatar
Noric Couderc committed
93
94
95

        val exp = Experiment(10, bench,
            FeatureSet(
96
97
98
                PAPICounter("PAPI_TOT_INS"),
                costPerDelete,
                cacheMissRate
99
100
            ),
            runner
Noric Couderc's avatar
Noric Couderc committed
101
        )
102
        val results = exp.run()
Noric Couderc's avatar
Noric Couderc committed
103
104

        for (iteration in results) {
Noric Couderc's avatar
Noric Couderc committed
105
106
107
108
109
110
            Assertions.assertTrue(iteration.values.containsKey(PAPICounter("PAPI_TOT_INS")))
            Assertions.assertTrue(iteration.values.containsKey(costPerDelete))
            Assertions.assertTrue(iteration.values.containsKey(costPerDelete.counter))
            Assertions.assertTrue(iteration.values.containsKey(cacheMissRate))
            Assertions.assertTrue(iteration.values.containsKey(cacheMissRate.f1))
            Assertions.assertTrue(iteration.values.containsKey(cacheMissRate.f2))
Noric Couderc's avatar
Noric Couderc committed
111
112
113
        }
    }

114
    // @Disabled("PAPI_L1_DCA was not available on my machine, so it wouldn't work")
Noric Couderc's avatar
Noric Couderc committed
115
116
117
118
    @Test
    fun testExperimentBrainyFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

Noric Couderc's avatar
Noric Couderc committed
119
        val features = brainyFeatures().checked()
120
        val exp = Experiment(10, bench, features,runner)
Noric Couderc's avatar
Noric Couderc committed
121

122
        val results = exp.run()
123

124
125
126
127
128
129
        // Fails for some reason. I don't understand why
        // Throws an exception with number -8
        val eventSet = EventSet.create(Constants.PAPI_TOT_CYC)
        eventSet.start()
        eventSet.stop()

130
131
132
133
        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
        }
Noric Couderc's avatar
Noric Couderc committed
134
    }
135

136
137
138
139
140
141
    @Test
    fun cacheSizeFeatures() {
        val f = cacheLineSizeFeature()
        Assertions.assertFalse(f == null)
    }

142
143
144
145
    @Test
    fun testNormalizationBrainyFeatures() {
        val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())

146
        val features = normalize(brainyFeatures()).checked()
147
148
149
150
151
152
153

        val exp = Experiment(10, bench, features,runner)

        val results = exp.run()

        for (iteration in results) {
            Assertions.assertEquals(bench, iteration.benchmark)
154
            Assertions.assertTrue(features.containsAll(iteration.strict().values.keys))
155
            Assertions.assertTrue(iteration.values.values.all { it > 0 })
156
            Assertions.assertTrue(iteration.strict().values.values.all { it <= 1.0 })
157
158
        }
    }
159
}