This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic transform benchmarking infrastructure and speed up Resolve …
…Kinds (bp #1475) (#1622) * Add benchmark for ResolveKinds with hot JIT * Use HashMap instead of LinkedHashMap in ResolveKinds * Modify to deprecate old methods for backport (cherry picked from commit 0f78e2d) Co-authored-by: Albert Magyar <albert.magyar@gmail.com> * Eliminate unnecessary traversals in ResolveKinds * Modify for backporting * Make find_port return Unit and use Foreachers in ResolveKinds * Modify for backporting Co-authored-by: Jack Koenig <koenig@sifive.com> Co-authored-by: Albert Magyar <albert.magyar@gmail.com>
- Loading branch information
1 parent
dac5d51
commit 83c36db
Showing
5 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
benchmark/src/main/scala/firrtl/benchmark/hot/ResolveKindsBenchmark.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
package firrtl | ||
package benchmark | ||
package hot | ||
|
||
import passes.ResolveKinds | ||
import stage.TransformManager | ||
|
||
import firrtl.benchmark.util._ | ||
|
||
object ResolveKindsBenchmark extends App { | ||
val inputFile = args(0) | ||
val warmup = args(1).toInt | ||
val runs = args(2).toInt | ||
|
||
val input = filenameToCircuit(inputFile) | ||
val state = CircuitState(input, ChirrtlForm) | ||
val prereqs = ResolveKinds.prerequisites | ||
val manager = new TransformManager(prereqs) | ||
val preState = manager.execute(state) | ||
|
||
hot.util.benchmark(warmup, runs)(ResolveKinds.run(preState.circuit)) | ||
} |
28 changes: 28 additions & 0 deletions
28
benchmark/src/main/scala/firrtl/benchmark/hot/util/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
package firrtl.benchmark.hot | ||
|
||
import firrtl.Utils.time | ||
import firrtl.benchmark.util._ | ||
|
||
package object util { | ||
def benchmark(nWarmup: Int, nRun: Int)(f: => Unit): Unit = { | ||
// Warmup | ||
for (i <- 0 until nWarmup) { | ||
val (t, res) = time(f) | ||
println(f"Warmup run $i took $t%.1f ms") | ||
} | ||
|
||
// Benchmark | ||
val times: Array[Double] = Array.fill(nRun)(0.0) | ||
for (i <- 0 until nRun) { | ||
val (t, res) = time(f) | ||
times(i) = t | ||
println(f"Benchmark run $i took $t%.1f ms") | ||
} | ||
|
||
println(f"Mean: ${mean(times)}%.1f ms") | ||
println(f"Median: ${median(times)}%.1f ms") | ||
println(f"Stddev: ${stdDev(times)}%.1f ms") | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
benchmark/src/main/scala/firrtl/benchmark/util/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
package firrtl | ||
package benchmark | ||
|
||
import firrtl.ir.Circuit | ||
import scala.util.control.NonFatal | ||
|
||
package object util { | ||
def filenameToCircuit(filename: String): Circuit = try { | ||
proto.FromProto.fromFile(filename) | ||
} catch { | ||
case NonFatal(_) => Parser.parseFile(filename, Parser.IgnoreInfo) | ||
} | ||
|
||
def mean(xs: Iterable[Double]): Double = xs.sum / xs.size | ||
|
||
def median(xs: Iterable[Double]): Double = { | ||
val size = xs.size | ||
val sorted = xs.toSeq.sorted | ||
if (size % 2 == 1) sorted(size / 2) | ||
else { | ||
val a = sorted(size / 2) | ||
val b = sorted((size / 2) - 1) | ||
(a + b) / 2 | ||
} | ||
} | ||
|
||
def variance(xs: Iterable[Double]): Double = { | ||
val avg = mean(xs) | ||
xs.map(a => math.pow(a - avg, 2)).sum / xs.size | ||
} | ||
|
||
def stdDev(xs: Iterable[Double]): Double = math.sqrt(variance(xs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters