Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
BuildTask: print utilisation stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Jun 2, 2024
1 parent ce7014d commit 353c7f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ trait ECP5Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
val lpfPath = s"$buildDir/${platform.id}/$name.lpf"
writePath(lpfPath, topPlatform.lpf.toString())

val textcfgPath = s"$buildDir/${platform.id}/$name.config"
val textcfgPath = s"$buildDir/${platform.id}/$name.config"
val nextpnrLogPath = s"$buildDir/${platform.id}/$name.config.log"
val textcfgCu = CompilationUnit(
Some(jsonPath),
Seq(lpfPath),
Expand All @@ -68,7 +69,7 @@ trait ECP5Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
"nextpnr-ecp5",
"-q",
"--log",
s"$buildDir/${platform.id}/$name.tim",
nextpnrLogPath,
"--json",
jsonPath,
"--lpf",
Expand All @@ -84,6 +85,8 @@ trait ECP5Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
)
runCu(CmdStepPNR, textcfgCu)

// TODO (ECP5): print statistics like ICE40Platform.

val bitPath = s"$buildDir/${platform.id}/$name.bit"
val svfPath = s"$buildDir/${platform.id}/$name.svf"
val bitCu = CompilationUnit(
Expand Down
14 changes: 12 additions & 2 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ trait ICE40Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
val pcfPath = s"$buildDir/${platform.id}/$name.pcf"
writePath(pcfPath, topPlatform.pcf.toString())

val ascPath = s"$buildDir/${platform.id}/$name.asc"
val ascPath = s"$buildDir/${platform.id}/$name.asc"
val nextpnrLogPath = s"$buildDir/${platform.id}/$name.asc.log"
val ascCu = CompilationUnit(
Some(jsonPath),
Seq(pcfPath),
Expand All @@ -66,7 +67,7 @@ trait ICE40Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
"nextpnr-ice40",
"-q",
"--log",
s"$buildDir/${platform.id}/$name.tim",
nextpnrLogPath,
"--json",
jsonPath,
"--pcf",
Expand All @@ -80,6 +81,15 @@ trait ICE40Platform { this: PlatformBoard[_ <: PlatformBoardResources] =>
)
runCu(CmdStepPNR, ascCu)

println()
println("Device utilisation:")
logFileBetween(
nextpnrLogPath,
raw"Info: Device utilisation:".r,
raw"Info: Placed .*".r,
Some("Info: "),
)

val binPath = s"$buildDir/${platform.id}/$name.bin"
val binCu = CompilationUnit(
Some(ascPath),
Expand Down
32 changes: 32 additions & 0 deletions src/main/scala/ee/hrzn/chryse/tasks/BaseTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,38 @@ trait BaseTask {
.map(_.toString)
.filter(_.endsWith(ext))

protected def logFileBetween(
path: String,
start: Regex,
end: Regex,
prefix: Option[String] = None,
): Unit = {
var started = false
var ended = false
val lines = Files.lines(Paths.get(path)).iterator.asScala

while (!ended && lines.hasNext) {
val line = lines.next()
if (!started) {
started = start.matches(line)
} else if (end.matches(line)) {
ended = true
} else {
println(prefix match {
case Some(prefix) =>
if (
line.length >= prefix.length && line
.substring(0, prefix.length()) == prefix
)
line.substring(prefix.length())
else line
case None =>
line
})
}
}
}

case class CompilationUnit(
val primaryInPath: Option[String],
val otherInPaths: Seq[String],
Expand Down
17 changes: 8 additions & 9 deletions src/main/scala/ee/hrzn/chryse/tasks/BuildTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,21 @@ private[chryse] object BuildTask extends BaseTask {
|write_json $jsonPath""".stripMargin,
)

val yosysLogPath = s"$buildDir/${platform.id}/$name.json.log"
val yosysCu = CompilationUnit(
Some(verilogPath),
Seq(yosysScriptPath),
jsonPath,
Seq(
"yosys",
"-q",
"-g",
"-l",
s"$buildDir/${platform.id}/$name.rpt",
"-s",
yosysScriptPath,
),
Seq("yosys", "-q", "-g", "-l", yosysLogPath, "-s", yosysScriptPath),
)
runCu(CmdStepSynthesise, yosysCu)

logFileBetween(
yosysLogPath,
raw"\d+\.\d+\. Printing statistics\.".r,
raw"\d+\.\d+\. .*".r,
)

val binPath = platform.build(chryse, topPlatform.get, jsonPath)

if (options.program) {
Expand Down

0 comments on commit 353c7f1

Please sign in to comment.