Skip to content

Commit 8d83a7d

Browse files
committed
improve evaluation setup
1 parent aca8cf0 commit 8d83a7d

11 files changed

Lines changed: 373 additions & 35 deletions

File tree

code/jvm/src/main/scala/maf/cli/experiments/SchemeAnalyses.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ object SchemeAnalyses:
159159
with FIFOWorklistAlgorithm[SchemeExp]
160160
with SchemeModFLocalFSAnalysisResults
161161

162+
def modfADIAnalysis(prg: SchemeExp, k: Int) =
163+
new SchemeModFADIAnalysis(prg, k)
164+
with SchemeModFADIAnalysisResults
165+
162166
// Flow sensitive analysis
163167
def modFFlowSensitive(prg: SchemeExp) =
164168
new SimpleFlowSensitiveAnalysis(prg)

code/jvm/src/main/scala/maf/cli/experiments/precision/AnalysisComparisonAlt.scala

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ abstract class AnalysisComparisonAlt[Num: IntLattice, Rea: RealLattice, Bln: Boo
2323
// - the number of runs for the concrete interpreter
2424
def analyses: List[(SchemeExp => Analysis, String)]
2525
def benchmarks: List[Benchmark]
26-
def runs = 3 // number of runs for the concrete interpreter
26+
def runs = 1 // number of runs for the concrete interpreter
2727

2828
// and can, optionally, be configured in its timeouts (default: 10min.) and the number of concrete runs
29-
def timeout() = Timeout.start(Duration(10, MINUTES)) // timeout for the analyses
29+
def timeout() = Timeout.start(Duration(5, MINUTES)) // timeout for the analyses
3030

3131
// keep the results of the benchmarks in a table
3232
enum Result:
@@ -80,10 +80,13 @@ abstract class AnalysisComparisonAlt[Num: IntLattice, Rea: RealLattice, Bln: Boo
8080

8181
private def runBenchmarks(benchmarks: List[Benchmark], outputFolder: Option[String] = None) =
8282
assert(benchmarks.size == benchmarks.toSet.size) // sanity check to make sure we don't have duplicates
83-
benchmarks.foreach(runBenchmark)
84-
showResults(outputFolder)
83+
benchmarks.foreach { benchmark =>
84+
runBenchmark(benchmark)
85+
writeResultsToFile(outputFolder)
86+
}
87+
showResults()
8588

86-
protected def showResults(outputFolder: Option[String]) =
89+
protected def showResults() =
8790
println()
8891
println("PRECISION RESULTS")
8992
println("=================")
@@ -94,16 +97,18 @@ abstract class AnalysisComparisonAlt[Num: IntLattice, Rea: RealLattice, Bln: Boo
9497
println("===================")
9598
println()
9699
println(performanceResults.prettyString())
97-
outputFolder.foreach { dir =>
98-
writeToFile(precisionResults, s"$dir/precision-benchmarks.csv")
99-
writeToFile(performanceResults, s"$dir/performance-benchmarks.csv")
100-
}
101100

102101
protected def writeToFile[X](results: Table[X], path: String) =
103102
val writer = Writer.open(path)
104103
Writer.write(writer, results.toCSVString(rowName = "benchmark"))
105104
Writer.close(writer)
106105

106+
protected def writeResultsToFile(outputFolder: Option[String]) =
107+
outputFolder.foreach { dir =>
108+
writeToFile(precisionResults, s"$dir/precision-benchmarks.csv")
109+
writeToFile(performanceResults, s"$dir/performance-benchmarks.csv")
110+
}
111+
107112
def main(args: Array[String]) = runBenchmarks(benchmarks, args.headOption)
108113

109114

@@ -123,6 +128,9 @@ abstract class SASBenchmarks
123128
lazy val dss0: (SchemeExp => Analysis, String) = (SchemeAnalyses.modflocalAnalysis(_, 0), "0-CFA DSS")
124129
lazy val dss1: (SchemeExp => Analysis, String) = (SchemeAnalyses.modflocalAnalysis(_, 1), "1-CFA DSS")
125130
lazy val dss2: (SchemeExp => Analysis, String) = (SchemeAnalyses.modflocalAnalysis(_, 2), "2-CFA DSS")
131+
lazy val adi0: (SchemeExp => Analysis, String) = (SchemeAnalyses.modfADIAnalysis(_, 0), "0-CFA ADI")
132+
lazy val adi1: (SchemeExp => Analysis, String) = (SchemeAnalyses.modfADIAnalysis(_, 1), "1-CFA ADI")
133+
lazy val adi2: (SchemeExp => Analysis, String) = (SchemeAnalyses.modfADIAnalysis(_, 2), "2-CFA ADI")
126134
lazy val dssFS0: (SchemeExp => Analysis, String) = (SchemeAnalyses.modflocalFSAnalysis(_, 0, true), "0-CFA DSS-FS")
127135
lazy val dssFS1: (SchemeExp => Analysis, String) = (SchemeAnalyses.modflocalFSAnalysis(_, 1, true), "1-CFA DSS-FS")
128136
lazy val dssFS2: (SchemeExp => Analysis, String) = (SchemeAnalyses.modflocalFSAnalysis(_, 2, true), "2-CFA DSS-FS")
@@ -144,6 +152,18 @@ abstract class SASBenchmarks
144152
//"triangl" <- times out in concrete interpreter
145153
).map(name => s"test/R5RS/gabriel/$name.scm")
146154

155+
def slowBenchmarks =
156+
List(
157+
"boyer",
158+
"browse",
159+
"destruc"
160+
).map(name => s"test/R5RS/gabriel/$name.scm")
161+
++
162+
List(
163+
"test/R5RS/gambit/matrix.scm",
164+
"test/R5RS/various/mceval.scm",
165+
)
166+
147167
def extraBenchmarks =
148168
List(
149169
"test/R5RS/various/grid.scm",
@@ -188,26 +208,44 @@ object Table4Benchmarks extends SASBenchmarks:
188208
dssFS0NoGC, dssFS1NoGC, dssFS2NoGC
189209
)
190210

211+
object ADIBenchmarks extends SASBenchmarks:
212+
def analyses = List(
213+
dss0, dss1, dss2,
214+
adi0, adi1, adi2
215+
)
216+
217+
object DSS2Benchmark extends SASBenchmarks:
218+
def analyses = List(dssFS2NoGC)
219+
override def benchmarks = List("test/R5RS/gabriel/boyer.scm")
220+
191221
object CountIterationBenchmark extends SASBenchmarks:
192222

193223
def analyses = List(
194224
dssFS0, dssFS0NoGC
195225
)
196226

197-
var results: Table[Int] = Table.empty
227+
var results: Table[Option[Long]] = Table.empty
198228

199229
override protected def forBenchmark(path: Benchmark, program: SchemeExp): Unit =
200230
println(s"ANALYZING $path")
201231
analyses.foreach { case (analysis, name) =>
202232
val anl = analysis(program)
203233
anl.analyzeWithTimeout(Timeout.start(Duration(15, MINUTES)))
204-
results = results.add(path, name, anl.asInstanceOf[SchemeModFLocalFS].iterations)
234+
val res = anl.asInstanceOf[SchemeModFLocalFS].computeOneCountsPercentage.map(_ * 100)
235+
results = results.add(path, name, res.map(_.round))
205236
}
206237

207238
override def timeout() = Timeout.none
208239

209-
override protected def showResults(outputFolder: Option[String]) =
210-
println(results.prettyString())
240+
private def showResult(res: Option[Long]): String =
241+
res match
242+
case None => "N/A"
243+
case Some(value) => s"$value%"
244+
245+
override protected def showResults() =
246+
println(results.prettyString(format=showResult))
247+
248+
override protected def writeResultsToFile(outputFolder: Option[String]) =
211249
outputFolder.foreach { dir =>
212250
writeToFile(results, s"$dir/iteration-benchmarks.csv")
213251
}

code/shared/src/main/scala/maf/modular/scheme/modactor/ASchemeMirrorsSemantics.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ trait ASchemeMirrorsSemantics extends ASchemeSemantics:
355355
case ASchemeCreate(beh, ags, idn) =>
356356
// we intercept actor creation and forward it to the meta layer if necessary
357357
for
358-
evaluatedBeh <- nontail(eval(beh))
358+
evaluatedBeh <- nontail(???)(eval(beh))
359359
evaluatedAgs <- evalAll(ags)
360360
result <- interceptCreate(evaluatedBeh, evaluatedAgs, lattice.bool(false), ags, idn)
361361
yield result
362362
case ASchemeSend(actorRef, Identifier(tag, _), ags, idn) =>
363363
for
364-
evaluatedActor <- nontail(eval(actorRef))
364+
evaluatedActor <- nontail(???)(eval(actorRef))
365365
evaluatedAgs <- evalAll(ags)
366366
self <- selfActor
367367
message = Message(tag, evaluatedAgs, ags)
@@ -426,9 +426,9 @@ trait ASchemeMirrorsSemantics extends ASchemeSemantics:
426426
// TODO: in the concrete actor implementation we have that the create-with-mirror call
427427
// is also intercepted. We should do that here as well.
428428
for
429-
evaluatedBehavior <- nontail(eval(behavior))
429+
evaluatedBehavior <- nontail(???)(eval(behavior))
430430
_ = log(s"+++ create-with-mirror (1) $behavior")
431-
evaluatedAgs <- nontail(evalAll(ags))
431+
evaluatedAgs <- nontail(???)(evalAll(ags))
432432
_ = log(s"+++ create-with-mirror (2) $evaluatedAgs")
433433
// defer spawning the actor since the mirror will be installed later
434434
actorRef <- create(evaluatedBehavior, evaluatedAgs, idn, defer = true)
@@ -444,7 +444,7 @@ trait ASchemeMirrorsSemantics extends ASchemeSemantics:
444444

445445
case SchemeFuncall(SchemeVar(Identifier("base/send-envelope" | "send-envelope", _)), List(envelopeExpression), _) =>
446446
for
447-
evaluatedEnvelope <- nontail(eval(envelopeExpression))
447+
evaluatedEnvelope <- nontail(???)(eval(envelopeExpression))
448448
_ = log(s"+++ base/send-envelope $evaluatedEnvelope")
449449
// get the envelopes from the abstract domain
450450
envelope <- nondets(lattice.getEnvelopes(evaluatedEnvelope).map(unit))

code/shared/src/main/scala/maf/modular/scheme/modactor/ASchemeSemantics.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ trait ASchemeSemantics extends SchemeSemantics, SchemeModFLocalSensitivity, Sche
136136
case ASchemeCreate(beh, ags, idn) =>
137137
for
138138
env <- getEnv
139-
evaluatedBeh <- nontail(eval(beh))
139+
evaluatedBeh <- nontail(???)(eval(beh))
140140
evaluatedAgs <- evalAll(ags)
141141
actorRef <- create(evaluatedBeh, evaluatedAgs, idn)
142142
yield lattice.actor(actorRef)
143143

144144
// Sending a message is atomic (asynchronous) and results in nil
145145
case ASchemeSend(actorRef, messageTpy, ags, idn) =>
146146
for
147-
evaluatedActorRef <- nontail(eval(actorRef))
147+
evaluatedActorRef <- nontail(???)(eval(actorRef))
148148
evaluatedAgs <- evalAll(ags)
149149
_ = { log(s"++ intra - actor/send $evaluatedActorRef $messageTpy $evaluatedAgs") }
150150
// TODO: the context should be inherited from the current context.
@@ -157,7 +157,7 @@ trait ASchemeSemantics extends SchemeSemantics, SchemeModFLocalSensitivity, Sche
157157
// Change the behavior of the current actor, and return nil
158158
case ASchemeBecome(beh, ags, idn) =>
159159
for
160-
evaluatedBeh <- nontail(eval(beh))
160+
evaluatedBeh <- nontail(???)(eval(beh))
161161
evaluatedAgs <- evalAll(ags)
162162
_ <- become(evaluatedBeh, evaluatedAgs, idn)
163163
// we stop the analysis here because the actor is in a suspended state,

0 commit comments

Comments
 (0)