Skip to content

Commit

Permalink
[ci] remove all the run configs
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jan 18, 2024
1 parent 71082b5 commit 4753117
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 64 deletions.
12 changes: 6 additions & 6 deletions .github/cases/default.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
v1024-l8-b2/debug/default.json
v1024-l8-b2-fp/debug/default.json
v4096-l8-b4/debug/default.json
v4096-l8-b4-fp/debug/default.json
v4096-l32-b4/debug/default.json
v4096-l32-b4-fp/debug/default.json
v1024-l8-b2/default.json
v1024-l8-b2-fp/default.json
v4096-l8-b4/default.json
v4096-l8-b4-fp/default.json
v4096-l32-b4/default.json
v4096-l32-b4-fp/default.json
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
69 changes: 33 additions & 36 deletions .github/scripts/ci.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.collection.mutable.ArrayBuffer
//
// @param allTests The original Seq
// @param bucketSize Specify the size of the output Seq
def buckets(alltests: Seq[String], bucketSize: Int): Seq[String] = // TODO: investigate load inbalance
def buckets(alltests: Seq[String], bucketSize: Int): Seq[String] =
scala.util.Random.shuffle(alltests).grouped(
math.ceil(alltests.size.toDouble / bucketSize).toInt
).toSeq.map(_.mkString(";"))
Expand Down Expand Up @@ -41,12 +41,12 @@ def scheduleTasks(allTasksFile: Seq[os.Path], bucketSize: Int): Seq[String] = {
val init = Seq[(String, Int)]()
val allCycleData = allTasksFile.flatMap (file => {
System.err.println(s"Generate tests from file: $file")
val Seq(_, runCfg, config) = file.segments.toSeq.reverse.slice(0, 3)
val config = file.segments.toSeq.reverse(1)
ujson
.read(os.read(file))
.obj
.map { case (caseName, v) =>
(s"$config,$caseName,$runCfg", v.num.toInt)
.map { case (caseName, cycle) =>
(s"$config,$caseName", cycle.num.toInt)
}
.toSeq
})
Expand Down Expand Up @@ -101,25 +101,24 @@ def postPrMatrixJson(
) = {
val defaultCases = os.pwd / os.RelPath(".github/cases/default.txt")
val caseFiles = os.read.lines(defaultCases).map(os.RelPath(_))
val testCaseDir = os.proc("nix", "build", ".#t1.rvv-testcases.all", "--no-link", "--print-out-paths").call(cwd=os.pwd).out.trim
val unpassedCases = caseFiles.flatMap(file => {
val Seq(verilateCfg, runCfg, _) = file.segments.toSeq
val configFile = os.pwd / "configs" / s"$verilateCfg.json"
val verilateCfg = file.segments.head
val exists = ujson.read(os.read(defaultCases / os.up / file))
.obj.keys
.map(caseName => s"$verilateCfg,$caseName,$runCfg")
val testCaseDir = os.proc("nix", "build", ".#t1.rvv-testcases.all", "--no-link", "--print-out-paths").call(cwd=os.pwd).out.trim
.map(caseName => s"$verilateCfg,$caseName")
val isFpVerilator = verilateCfg.endsWith("-fp")
val all: Seq[String] = os.list(os.Path(testCaseDir) / "configs")
// For fp verilator, don't filter tests
// For non-fp verilator, filter out fp tests
.filter(f => !isFpVerilator && !ujson.read(os.read(f))("fp").bool)
.map(f => s"$verilateCfg,${f.baseName.toString},$runCfg")
.map(f => s"$verilateCfg,${f.baseName.toString}")
val perfCases = os.walk(defaultCases / os.up)
.filter(f => f.last == "perf-cases.txt")
.flatMap(f => {
val Seq(_, runCfg, verilateCfg) = file.segments.toSeq.reverse.slice(0, 3)
val Seq(_, verilateCfg) = file.segments.toSeq.reverse.slice(0, 2)
os.read.lines(f).filter(_.length > 0).map (caseName =>
s"$verilateCfg,$caseName,$runCfg"
s"$verilateCfg,$caseName"
)
})

Expand All @@ -137,46 +136,44 @@ def convertPerfToMD() = os
.foreach(p => {
val testRunDir = os.pwd / "testrun"
val perfCases = os.read.lines(p).filter(_.length > 0)
val Seq(config, runCfg, _) =
p.relativeTo(os.pwd / ".github" / "cases").segments.toSeq
val config = p.relativeTo(os.pwd / ".github" / "cases").segments.toSeq(0)
val existPerfFile = perfCases
.filter {testcase =>
val path = testRunDir / os.RelPath(
s"$config/$testcase/$runCfg/perf.txt"
s"$config/$testcase/perf.txt"
)
os.exists(path)
}
.foreach(testcase => {
val path = testRunDir / os.RelPath(
s"$config/$testcase/$runCfg/perf.txt"
s"$config/$testcase/perf.txt"
)
System.err.println(s"generating perf-result-$testcase-$config-$runCfg.md")
System.err.println(s"generating perf-result-$testcase-$config.md")
val output =
s"""### $testcase
|
|* Config: $config
|* Run Config: $runCfg
|
|```
|${os.read(path).trim}
|```
|\n""".stripMargin
os.write(os.pwd / s"perf-result-$testcase-$config-$runCfg.md", output)
os.write(os.pwd / s"perf-result-$testcase-$config.md", output)
})
})


def writeCycleUpdates(job: String, testRunDir: os.Path, resultDir: os.Path) = {
val isEmulatorTask = raw"([^,]+),([^,]+),([^,]+)".r
val isEmulatorTask = raw"([^,]+),([^,]+)".r
job match {
case isEmulatorTask(e, t, r) => {
val passedFile = os.pwd / os.RelPath(s".github/cases/$e/$r/default.json")
case isEmulatorTask(e, t) => {
val passedFile = os.pwd / os.RelPath(s".github/cases/$e/default.json")
val original = ujson.read(os.read(passedFile))

val perfCycleRegex = raw"total_cycles:\s(\d+)".r
val newCycleCount = os
.read
.lines(testRunDir / os.RelPath(s"$e/$t/$r/perf.txt"))
.lines(testRunDir / os.RelPath(s"$e/$t/perf.txt"))
.apply(0) match {
case perfCycleRegex(cycle) => cycle.toInt
case _ => throw new Exception("perf.txt file is not format as expected")
Expand All @@ -194,7 +191,7 @@ def writeCycleUpdates(job: String, testRunDir: os.Path, resultDir: os.Path) = {
os.write.append(cycleUpdateFile, s"* 🐢 $job: $oldCycleCount -> $newCycleCount\n")
}

val newCycleFile = resultDir / s"${e}_${r}_cycle.json"
val newCycleFile = resultDir / s"${e}_cycle.json"
val newCycleRecord = if (os.exists(newCycleFile)) {
ujson.read(os.read(newCycleFile))
} else {
Expand Down Expand Up @@ -230,13 +227,13 @@ def runTests(jobs: String, resultDir: Option[os.Path], dontBail: Boolean = false
val totalJobs = jobs.split(";")
val failed = totalJobs.zipWithIndex.foldLeft(Seq[String]()) {
case(failed, (job, i)) => {
val Array(config, caseName, runCfg) = job.split(",")
System.err.println(s"\n\n\n>>>[${i+1}/${totalJobs.length}] Running test case $config,$caseName,$runCfg")
val Array(config, caseName) = job.split(",")
System.err.println(s"\n\n\n>>>[${i+1}/${totalJobs.length}] Running test case $config,$caseName")
val handle = os
.proc("scripts/run-test.py", "verilate", "-c", config, "-r", runCfg, "--no-log", "--base-out-dir", testRunDir, caseName)
.proc("scripts/run-test.py", "verilate", "-c", config, "--no-log", "--base-out-dir", testRunDir, caseName)
.call(check=false)
if (handle.exitCode != 0) {
val outDir = testRunDir / config / caseName / runCfg
val outDir = testRunDir / config / caseName
System.err.println(s"Test case $job failed")
failed :+ job
} else {
Expand Down Expand Up @@ -268,10 +265,10 @@ def runFailedTests(jobs: String) = {
val testRunDir = os.pwd / "testrun"
val totalJobs = jobs.split(";")
val failed = totalJobs.zipWithIndex.foreach { case (job, i) => {
val Array(config, caseName, runCfg) = job.split(",")
System.err.println(s"[${i+1}/${totalJobs.length}] Running test case with trace $config,$caseName,$runCfg")
val Array(config, caseName) = job.split(",")
System.err.println(s"[${i+1}/${totalJobs.length}] Running test case with trace $config,$caseName")
val handle = os
.proc("scripts/run-test.py", "verilate", "-c", config, "-r", runCfg, "--trace", "--no-log", "--base-out-dir", testRunDir, caseName)
.proc("scripts/run-test.py", "verilate", "-c", config, "--trace", "--no-log", "--base-out-dir", testRunDir, caseName)
.call(check=false)
}}
}
Expand All @@ -282,16 +279,16 @@ def mergeCycleData() = {
val original = os.walk(os.pwd / ".github" / "cases")
.filter(_.last == "default.json")
.map(path => {
val Seq(_, runConfig, config) = path.segments.toSeq.reverse.slice(0, 3)
(s"$config,$runConfig", ujson.read(os.read(path)))
val config = path.segments.toSeq.reverse(1)
(config, ujson.read(os.read(path)))
})
.toMap
os.walk(os.pwd)
.filter(_.last.endsWith("_cycle.json"))
.map(path => {
val Array(config, runConfig, _) = path.last.split("_")
val config = path.last.split("_")(0)
println(s"Reading new cycle data from $path")
(s"$config,$runConfig", ujson.read(os.read(path)))
(config, ujson.read(os.read(path)))
})
.foreach {
case(name, latest) => {
Expand All @@ -303,9 +300,9 @@ def mergeCycleData() = {
}
original.foreach {
case(name, data) => {
val Array(config, runConfig) = name.split(",")
val config = name.split(",")(0)
os.write.over(
os.pwd / os.RelPath(s".github/cases/$config/$runConfig/default.json"),
os.pwd / os.RelPath(s".github/cases/$config/default.json"),
ujson.write(data, indent = 2)
)
}
Expand Down
4 changes: 0 additions & 4 deletions run/debug.json

This file was deleted.

54 changes: 36 additions & 18 deletions scripts/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def main():
"--trace", action="store_true", help="use emulator with trace support"
)
verilator_args_parser.add_argument(
"-r",
"--run-config",
default="debug",
help="run configuration name, as filenames in ./run",
"--cosim-timeout", default=100000, help="set cosim timeout"
)
verilator_args_parser.add_argument(
"-v", "--verbose", action="store_true", help="set loglevel to debug"
Expand All @@ -63,7 +60,7 @@ def main():
verilator_args_parser.add_argument(
"--base-out-dir",
default=None,
help="save result files in {base_out_dir}/{config}/{case}/{run_config}",
help="save result files in {base_out_dir}/{config}/{case}",
)
verilator_args_parser.add_argument(
"--emulator-path", default=None, help="path to emulator"
Expand Down Expand Up @@ -118,11 +115,9 @@ def run_verilator_emulator(args):

if args.out_dir is None:
if args.base_out_dir is not None:
args.out_dir = (
f"{args.base_out_dir}/{args.config}/{args.case}/{args.run_config}"
)
args.out_dir = f"{args.base_out_dir}/{args.config}/{args.case}"
else:
args.out_dir = f"./testrun/{args.config}/{args.case}/{args.run_config}"
args.out_dir = f"./testrun/{args.config}/{args.case}"
Path(args.out_dir).mkdir(exist_ok=True, parents=True)

execute_verilator_emulator(args)
Expand Down Expand Up @@ -155,21 +150,30 @@ def load_elf_from_dir(cases_dir, case_name):


def execute_verilator_emulator(args):
run_config_path = Path("run") / f"{args.run_config}.json"
assert run_config_path.exists(), f"cannot find run config in {run_config_path}"
run_config = json.loads(run_config_path.read_text())

case_elf_path = (
args.case
if Path(args.case).exists()
else load_elf_from_dir(args.cases_dir, args.case)
)

elaborate_config_path = Path("configs") / f"{args.config}.json"
logger.info("Running configgen")
subprocess.check_call(
[
"nix",
"run",
".#t1.configgen",
"--",
f"{args.config.replace('-', '')}",
"-t",
f"{args.out_dir}",
]
)
elaborate_config_path = Path(f"{args.out_dir}/config.json")
assert (
elaborate_config_path.exists()
), f"cannot find elaborate config in {elaborate_config_path}"

logger.info("Running emulator builder")
target_name = "ip.emu-trace" if args.trace else "ip.emu"
process_args = (
[args.emulator_path]
Expand All @@ -179,7 +183,7 @@ def execute_verilator_emulator(args):
env = {
"COSIM_bin": str(case_elf_path),
"COSIM_wave": str(Path(args.out_dir) / "wave.fst"),
"COSIM_timeout": str(run_config["timeout"]),
"COSIM_timeout": str(args.cosim_timeout),
"COSIM_config": str(elaborate_config_path),
"PERF_output_file": str(Path(args.out_dir) / "perf.txt"),
"EMULATOR_log_path": str(Path(args.out_dir) / "emulator.log"),
Expand All @@ -196,10 +200,24 @@ def execute_verilator_emulator(args):


def run_soc(args):
assert Path(
f"./configs/{args.config}.json"
).exists(), f"./configs/{args.config}.json doesn't exists. \nHint: are you running this script in project root?"
logger.info("Running configgen")
subprocess.check_call(
[
"nix",
"run",
".#t1.configgen",
"--",
f"{args.config.replace('-', '')}",
"-t",
f"{args.out_dir}",
]
)
elaborate_config_path = Path(f"{args.out_dir}/config.json")
assert (
elaborate_config_path.exists()
), f"cannot find elaborate config in {elaborate_config_path}"

logger.info("Running emulator builder")
target_name = "subsystem.emu-trace" if args.trace else "subsystem.emu"
process_args = (
[args.emulator_path]
Expand Down

0 comments on commit 4753117

Please sign in to comment.