Compare commits

...

2 Commits

Author SHA1 Message Date
47614ad47f Add Longnail complete command 2025-10-02 18:23:31 +02:00
69b63d93da Update file handling and descriptions 2025-10-02 12:46:32 +02:00
17 changed files with 160 additions and 63 deletions

View File

@@ -1,6 +1,10 @@
package com.minres.tgc.hammer
import org.rogach.scallop.{ValueConverter, listArgConverter, singleArgConverter}
import os.*
import Global.*
import scala.collection.IterableOps
object FileUtils {
def changeExtension(path: os.Path, newExt: String): os.Path = {
@@ -8,4 +12,23 @@ object FileUtils {
val newName = s"$baseName.$newExt"
path / os.up / newName
}
extension (x: String)
def asPath(relative: Path): Path = {
Path(x, relative)
}
def path(): Path = asPath(BASE_DIR)
extension [T <: Iterable](x: IterableOps[String, T, T[String]])
def asPath(relative: Path): T[Path] = {
x.map(_.asPath(relative))
}
def path(): T[Path] = asPath(BASE_DIR)
implicit val osPathRelBaseConverter: ValueConverter[Path] = {
singleArgConverter[Path](_.asPath(BASE_DIR))
}
implicit val osPathRelBaseListConverter: ValueConverter[List[Path]] = {
listArgConverter[Path](_.asPath(BASE_DIR))
}
}

View File

@@ -1,5 +1,6 @@
package com.minres.tgc.hammer
import com.minres.tgc.hammer.FileUtils.*
import os.Path
object Global {
@@ -9,5 +10,7 @@ object Global {
lazy val TREENAIL: Path = HAMMER / "deps" / "treenail"
lazy val LONGNAIL: Path = HAMMER / "deps" / "longnail"
lazy val BASE_DIR: Path = os.pwd
lazy val OUT_DIR: Path = Main.conf.outputDirectory()
lazy val TMP_DIR: Path = OUT_DIR / "tmp"
lazy val CORE_DATASHEETS: Path = HAMMER / "coreDatasheets"
}

View File

@@ -4,7 +4,7 @@ import com.minres.tgc.hammer.Global.CORE_DATASHEETS
import org.rogach.scallop.*
trait CoreSelection { this: MySubcommand =>
val core: ScallopOption[String] = opt[String](group = mainGroup)
val core: ScallopOption[String] = opt[String](group = mainGroup, required = true, descr = "The core to be extended; core datasheets are in coreDatasheets/")
def getCoreDatasheet: os.Path = CORE_DATASHEETS / s"$core.yaml"
}

View File

@@ -1,22 +1,14 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.Global
import org.rogach.scallop.{ScallopConf, ScallopOption, ValueConverter, fileConverter, listArgConverter, singleArgConverter}
import org.rogach.scallop.*
import os.Path
import java.io.File
import com.minres.tgc.hammer.FileUtils.*
class HammerConf(arguments: Seq[String]) extends ScallopConf(arguments) {
val outputDirectory: ScallopOption[Path] = opt[Path](default = Some("output".path()), descr = "The base output directory")
addSubcommand(new LongnailCommand)
addSubcommand(new TreenailCommand)
addSubcommand(new LongnailSchedCommand)
verify()
}
implicit val osPathConverter: ValueConverter[os.Path] = {
singleArgConverter[os.Path](os.Path(_, Global.BASE_DIR))
}
implicit val osPathListConverter: ValueConverter[List[os.Path]] = {
listArgConverter[os.Path](os.Path(_, Global.BASE_DIR))
}

View File

@@ -0,0 +1,44 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.FileUtils.*
import com.minres.tgc.hammer.Global.*
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
import com.minres.tgc.hammer.tasks.longnail.{LongnailHLSTask, LongnailMergeTask, LongnailScheduleTask, SchedulingParameters}
import org.rogach.scallop.*
import os.Path
import scala.collection.mutable
class LongnailCommand extends MySubcommand("isaxHLS") with CoreSelection {
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup, descr = "One or multiple input files; Both .core_desc as well as .mlir are supported (also mixed)")
val useMinIISolution: ScallopOption[Boolean] = toggle(name = "useMinIISolution", group = mainGroup, default = Some(false), descrYes = "Whether to automatically choose the scheduling solution with the lowest II. If not activated, a manual selection during execution will be required!")
val schedParams: SchedulingParameters = addConfigElement(new SchedulingParameters)
banner(
"""Run the complete longnail flow from CoreDSL/MLIR to receive a SystemVerilog representation of the ISAXes
|Usage: tgc-hammer isaxHLS -c VexRiscv --useMinIISolution isax.core_desc
|""".stripMargin)
override def getRequiredTasks: Seq[Task] = {
val tasks = mutable.ListBuffer[Task]()
val (coreDSLFiles, mlirFiles) = inputFiles().partition(_.ext == "core_desc")
val treenailTasks = coreDSLFiles.map(i => TreenailTask(i, TMP_DIR / s"${i.baseName}.mlir"))
tasks ++= treenailTasks
val allMlirFiles = mlirFiles ++ treenailTasks.map(_.output)
if (allMlirFiles.size == 1) {
tasks += LongnailScheduleTask(allMlirFiles.head, getCoreDatasheet, schedParams)
} else {
val mergedInput = TMP_DIR / "merged.mlir"
val concatInput = TMP_DIR / "concat.mlir"
tasks += LongnailMergeTask(allMlirFiles, concatInput, mergedInput)
tasks += LongnailScheduleTask(mergedInput, getCoreDatasheet, schedParams)
}
if (useMinIISolution()) {
tasks += LongnailHLSTask(schedParams.schedulingSolutionFile(), None, OUT_DIR)
} else {
???
}
tasks.toSeq
}
}

View File

@@ -1,5 +0,0 @@
package com.minres.tgc.hammer.cli
class LongnailHLSCommand {
}

View File

@@ -1,5 +1,31 @@
package com.minres.tgc.hammer.cli
class LongnailMergeCommand {
import com.minres.tgc.hammer.tasks.{CopyTask, Task, TreenailTask}
import org.rogach.scallop.*
import os.Path
import com.minres.tgc.hammer.FileUtils.*
import com.minres.tgc.hammer.Global.*
import com.minres.tgc.hammer.tasks.longnail.LongnailMergeTask
class LongnailMergeCommand extends MySubcommand("mergeISAX") {
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup, descr = "One or multiple input files; Both .core_desc as well as .mlir are supported (also mixed)")
val output: ScallopOption[Path] = opt[Path](short = 'o', default = Some("merged.mlir".path()), descr = "The .mlir file containing the merged ISAXes")
override def getRequiredTasks: Seq[Task] = {
val (coreDSLFiles, mlirFiles) = inputFiles().partition(_.ext == "core_desc")
if (inputFiles().size == 1) {
if (coreDSLFiles.size == 1) {
Seq(TreenailTask(coreDSLFiles.head, output()))
} else {
Seq(CopyTask(mlirFiles.head, output()))
}
} else {
val treenailTasks = coreDSLFiles.map(i => TreenailTask(i, TMP_DIR / s"${i.baseName}.mlir"))
val allMlirFiles = mlirFiles ++ treenailTasks.map(_.output)
val concatInput = TMP_DIR / "concat.mlir"
treenailTasks :+ LongnailMergeTask(allMlirFiles, concatInput, output())
}
}
}

View File

@@ -1,28 +1,32 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.FileUtils.changeExtension
import com.minres.tgc.hammer.FileUtils.*
import com.minres.tgc.hammer.Global.*
import com.minres.tgc.hammer.tasks.longnail.{LongnailMergeTask, LongnailScheduleTask}
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
import com.minres.tgc.hammer.tasks.longnail.SchedulingParameters
import org.rogach.scallop.ScallopOption
import org.rogach.scallop.*
import os.Path
class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelection {
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup)
val outputDirectory: ScallopOption[Path] = opt[Path](group = mainGroup)
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", group = mainGroup, descr = "One or multiple input files; Both .core_desc as well as .mlir are supported (also mixed)")
val schedParams: SchedulingParameters = addConfigElement(new SchedulingParameters)
validateOSPathIsDirectory(outputDirectory)
banner(
"""Generate Scheduling information for the provided ISAXes using Longnail
|Usage: tgc-hammer scheduleISAX -c VexRiscv isax.core_desc
|""".stripMargin)
override def getRequiredTasks: Seq[Task] = {
val (coreDSLFiles, mlirFiles) = inputFiles().partition(_.ext == "core_desc")
val treenailTasks = coreDSLFiles.map(i => TreenailTask(i, changeExtension(i, "mlir")))
val treenailTasks = coreDSLFiles.map(i => TreenailTask(i, TMP_DIR / s"${i.baseName}.mlir"))
val allMlirFiles = mlirFiles ++ treenailTasks.map(_.output)
if (allMlirFiles.size == 1) {
treenailTasks :+ LongnailScheduleTask(allMlirFiles.head, getCoreDatasheet, schedParams)
} else {
val mergedInput = outputDirectory() / "merged.mlir"
val concatInput = outputDirectory() / "concat.mlir"
val mergedInput = TMP_DIR / "merged.mlir"
val concatInput = TMP_DIR / "concat.mlir"
treenailTasks :+ LongnailMergeTask(allMlirFiles, concatInput, mergedInput) :+ LongnailScheduleTask(mergedInput, getCoreDatasheet, schedParams)
}
}

View File

@@ -1,10 +1,10 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.options.{BaseOption, ConfigElement, OptionGroup}
import com.minres.tgc.hammer.options.ConfigElement
import com.minres.tgc.hammer.tasks.Task
import org.rogach.scallop.{ScallopOption, ScallopOptionGroup, Subcommand, Util}
import java.nio.file.{Files, Path}
import java.nio.file.Files
abstract class MySubcommand(name: String) extends Subcommand(name) {
protected val mainGroup: ScallopOptionGroup = group()

View File

@@ -1,21 +1,22 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.Global
import com.minres.tgc.hammer.FileUtils.*
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
import org.rogach.scallop.*
import java.io.File
import os.Path
class TreenailCommand extends MySubcommand("parseCoreDSL") {
val coreDSL: ScallopOption[File] = trailArg[File]("coreDSL")
val output: ScallopOption[Path] = opt[Path](short = 'o', default = Some(os.Path("isax.mlir", Global.BASE_DIR)))
val coreDSL: ScallopOption[Path] = trailArg[Path]("coreDSL", descr = "The .core_desc input file to be converted")
val output: ScallopOption[Path] = opt[Path](short = 'o', default = Some("isax.mlir".path()), descr = "The .mlir file containing the converted ISAX")
validateFileIsFile(coreDSL)
banner(
"""Parse a CoreDSL input using Treenail into the MLIR representation
|Usage: tgc-hammer parseCoreDSL -o isax.mlir isax.core_desc
|""".stripMargin)
override def getRequiredTasks: Seq[Task] = {
Seq(
new TreenailTask(Path(coreDSL(), os.pwd), Path(output(), os.pwd))
TreenailTask(coreDSL(), output())
)
}
}

View File

@@ -13,7 +13,7 @@ trait BaseOption[T](using conv: ValueConverter[T]) extends ConfigElement {
}
def get: T = scallop()
def apply: T = get
def apply(): T = get
def getToolParameters: Seq[Shellable] = if (scallop.isDefined) Seq(s"$toolName", getToolArg) else Seq()

View File

@@ -5,8 +5,7 @@ import os.Shellable
class CommandGroup(name: String) extends BaseGroup {
override def getToolParameters: Seq[Shellable] = {
val sub = options.toSeq.map(_.getToolParameters.flatMap(_.value).mkString("=")).filter(!_.isEmpty)
println(sub)
val sub = options.toSeq.map(_.getToolParameters.flatMap(_.value).mkString("=")).filter(_.nonEmpty)
Seq(s"$name=\'${sub.mkString(" ")}\'")
}

View File

@@ -6,8 +6,6 @@ import os.Shellable
import scala.collection.mutable
export com.minres.tgc.hammer.cli.osPathConverter
trait BaseGroup extends ConfigElement {
protected val options = mutable.ListBuffer[ConfigElement]()
protected def add[T <: ConfigElement](option: T): T = {

View File

@@ -0,0 +1,13 @@
package com.minres.tgc.hammer.tasks
import os.*
case class CopyTask(from: Path, to: Path) extends Task {
override def validate(): Unit = {
}
override def execute(): Unit = {
copy(from, to)
}
}

View File

@@ -7,9 +7,6 @@ trait Task {
def execute(): Unit
def runExecutable(execPath: Path, args: Shellable*): os.CommandResult = {
println(s"Executing $execPath with")
println(args.flatMap(_.value).mkString(" "))
println(args)
val command = s"$execPath ${args.flatMap(_.value).mkString(" ")}"
os.proc("bash", "-c", command).call(stdout = os.Inherit)
}

View File

@@ -2,17 +2,16 @@ package com.minres.tgc.hammer.tasks.longnail
import os.Path
class LongnailHLSTask(schedulingFile: Option[Path], outDirectory: Path) extends LongnailBaseTask {
class LongnailHLSTask(schedulingSolutionFile: Path, schedulingSelectionFile: Option[Path], outDirectory: Path) extends LongnailBaseTask {
override def validate(): Unit = {
super.validate()
}
override def execute(): Unit = {
runExecutable(EXECUTABLE,
"--lower-lil-to-hw",
schedulingFile match {
case Some(value) => s"--solutionSelection $value"
case None => "--forceUseMinIISolution=true"
schedulingSelectionFile match {
case Some(value) => s"--lower-lil-to-hw=solutionSelection=$value"
case None => "--lower-lil-to-hw=forceUseMinIISolution=true"
},
"--simplify-structure",
"--cse",
@@ -22,8 +21,8 @@ class LongnailHLSTask(schedulingFile: Option[Path], outDirectory: Path) extends
"--hw-cleanup",
"--prettify-verilog",
"--hw-legalize-modules",
"--export-split-verilog",
"--dir-name", outDirectory
s"--export-split-verilog=dir-name=$outDirectory",
schedulingSolutionFile
)
}
}

View File

@@ -1,27 +1,30 @@
package com.minres.tgc.hammer.tasks.longnail
import com.minres.tgc.hammer.FileUtils.*
import com.minres.tgc.hammer.Global.OUT_DIR
import com.minres.tgc.hammer.options.*
import os.Path
import org.rogach.scallop.*
import os.Path
class SchedulingParameters extends OptionGroup {
override def name: String = "Longnail Scheduling Args"
add(new CommandGroup("--prepare-schedule-lil") {
choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = Some("LEGACY"))
value[Path](cliName = "cellLibrary", toolName = "library")
valueS[Path](name = "opTyLibrary")
choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = Some("LEGACY"), descr =
"Scheduling algorithm used by Longnail; Modulo Scheduling (MS) can be extended with Predicate-aware (PA) and Resource-aware (RA), Inter-Instruction sharing is activated in the MI variants")
value[Path](cliName = "cellLibrary", toolName = "library", descr = "The cell library used by Longnail (example: longnail/test/LILToHW/longnail*.yaml")
valueS[Path](name = "opTyLibrary", descr = "The operator type model used for detailed data (e.g. from OL SKY130 in longnail/opTyLibraries/OL2.yaml)")
})
add(new CommandGroup("--schedule-lil") {
valueS[Int](name = "schedulingTimeout")
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout")
value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath")
choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = Some("CBC"))
toggle(cliName = "verboseSched", toolName = "verbose")
value[Int](cliName = "clockPeriod", toolName = "clockTime")
valueS[Int](name = "schedulingTimeout", default = Some(10), descr = "Longnail scheduling timeout in seconds")
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout", default = Some(10), descr = "Longnail schedule refinement timeout in seconds")
value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath", default = Some(OUT_DIR / "scheduling.KConfig"), descr = "Path for the created KConfig file for selecting a scheduling solution")
choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = Some("CBC"), descr = "The ILP solver used by Longnail; currently only CBC is tested")
toggle(cliName = "verboseSched", toolName = "verbose", descr = "Enable verbose ILP solver messages")
value[Int](cliName = "clockPeriod", toolName = "clockTime", descr = "The target clock period; uses same time unit as delays in opTyLibrary")
})
value[Int](cliName = "--maxLoopUnrollFactor", toolName = "max-unroll-factor")
value[Path](cliName = "--schedulingMLIR", toolName = "o")
value[Int](cliName = "--maxLoopUnrollFactor", toolName = "max-unroll-factor", default = Some(16), descr = "Longnail max loop unroll factor")
val schedulingSolutionFile: ValueOption[Path] = value[Path](cliName = "--schedulingMLIR", toolName = "o", default = Some(OUT_DIR / "scheduling_solutions.mlir"), descr = "Output file with different scheduling solutions")
}