Update file handling and descriptions
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package com.minres.tgc.hammer
|
package com.minres.tgc.hammer
|
||||||
|
|
||||||
|
import org.rogach.scallop.{ValueConverter, listArgConverter, singleArgConverter}
|
||||||
import os.*
|
import os.*
|
||||||
|
import Global.*
|
||||||
|
|
||||||
|
import scala.collection.IterableOps
|
||||||
|
|
||||||
object FileUtils {
|
object FileUtils {
|
||||||
def changeExtension(path: os.Path, newExt: String): os.Path = {
|
def changeExtension(path: os.Path, newExt: String): os.Path = {
|
||||||
@@ -8,4 +12,23 @@ object FileUtils {
|
|||||||
val newName = s"$baseName.$newExt"
|
val newName = s"$baseName.$newExt"
|
||||||
path / os.up / newName
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.minres.tgc.hammer
|
package com.minres.tgc.hammer
|
||||||
|
|
||||||
|
import com.minres.tgc.hammer.FileUtils.*
|
||||||
import os.Path
|
import os.Path
|
||||||
|
|
||||||
object Global {
|
object Global {
|
||||||
@@ -9,5 +10,6 @@ object Global {
|
|||||||
lazy val TREENAIL: Path = HAMMER / "deps" / "treenail"
|
lazy val TREENAIL: Path = HAMMER / "deps" / "treenail"
|
||||||
lazy val LONGNAIL: Path = HAMMER / "deps" / "longnail"
|
lazy val LONGNAIL: Path = HAMMER / "deps" / "longnail"
|
||||||
lazy val BASE_DIR: Path = os.pwd
|
lazy val BASE_DIR: Path = os.pwd
|
||||||
|
lazy val OUT_DIR: Path = Main.conf.outputDirectory()
|
||||||
lazy val CORE_DATASHEETS: Path = HAMMER / "coreDatasheets"
|
lazy val CORE_DATASHEETS: Path = HAMMER / "coreDatasheets"
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ import com.minres.tgc.hammer.Global.CORE_DATASHEETS
|
|||||||
import org.rogach.scallop.*
|
import org.rogach.scallop.*
|
||||||
|
|
||||||
trait CoreSelection { this: MySubcommand =>
|
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"
|
def getCoreDatasheet: os.Path = CORE_DATASHEETS / s"$core.yaml"
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +1,13 @@
|
|||||||
package com.minres.tgc.hammer.cli
|
package com.minres.tgc.hammer.cli
|
||||||
|
|
||||||
import com.minres.tgc.hammer.Global
|
import org.rogach.scallop.*
|
||||||
import org.rogach.scallop.{ScallopConf, ScallopOption, ValueConverter, fileConverter, listArgConverter, singleArgConverter}
|
|
||||||
import os.Path
|
import os.Path
|
||||||
|
import com.minres.tgc.hammer.FileUtils.*
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class HammerConf(arguments: Seq[String]) extends ScallopConf(arguments) {
|
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 TreenailCommand)
|
addSubcommand(new TreenailCommand)
|
||||||
addSubcommand(new LongnailSchedCommand)
|
addSubcommand(new LongnailSchedCommand)
|
||||||
|
|
||||||
verify()
|
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))
|
|
||||||
}
|
|
||||||
|
@@ -1,18 +1,22 @@
|
|||||||
package com.minres.tgc.hammer.cli
|
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.longnail.{LongnailMergeTask, LongnailScheduleTask}
|
||||||
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
|
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
|
||||||
import com.minres.tgc.hammer.tasks.longnail.SchedulingParameters
|
import com.minres.tgc.hammer.tasks.longnail.SchedulingParameters
|
||||||
import org.rogach.scallop.ScallopOption
|
import org.rogach.scallop.*
|
||||||
import os.Path
|
import os.Path
|
||||||
|
|
||||||
class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelection {
|
class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelection {
|
||||||
val inputFiles: ScallopOption[List[Path]] = trailArg[List[Path]]("inputFiles", 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 outputDirectory: ScallopOption[Path] = opt[Path](group = mainGroup)
|
|
||||||
val schedParams: SchedulingParameters = addConfigElement(new SchedulingParameters)
|
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] = {
|
override def getRequiredTasks: Seq[Task] = {
|
||||||
val (coreDSLFiles, mlirFiles) = inputFiles().partition(_.ext == "core_desc")
|
val (coreDSLFiles, mlirFiles) = inputFiles().partition(_.ext == "core_desc")
|
||||||
@@ -21,8 +25,8 @@ class LongnailSchedCommand extends MySubcommand("scheduleISAX") with CoreSelecti
|
|||||||
if (allMlirFiles.size == 1) {
|
if (allMlirFiles.size == 1) {
|
||||||
treenailTasks :+ LongnailScheduleTask(allMlirFiles.head, getCoreDatasheet, schedParams)
|
treenailTasks :+ LongnailScheduleTask(allMlirFiles.head, getCoreDatasheet, schedParams)
|
||||||
} else {
|
} else {
|
||||||
val mergedInput = outputDirectory() / "merged.mlir"
|
val mergedInput = OUT_DIR / "merged.mlir"
|
||||||
val concatInput = outputDirectory() / "concat.mlir"
|
val concatInput = OUT_DIR / "concat.mlir"
|
||||||
treenailTasks :+ LongnailMergeTask(allMlirFiles, concatInput, mergedInput) :+ LongnailScheduleTask(mergedInput, getCoreDatasheet, schedParams)
|
treenailTasks :+ LongnailMergeTask(allMlirFiles, concatInput, mergedInput) :+ LongnailScheduleTask(mergedInput, getCoreDatasheet, schedParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
package com.minres.tgc.hammer.cli
|
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 com.minres.tgc.hammer.tasks.Task
|
||||||
import org.rogach.scallop.{ScallopOption, ScallopOptionGroup, Subcommand, Util}
|
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) {
|
abstract class MySubcommand(name: String) extends Subcommand(name) {
|
||||||
protected val mainGroup: ScallopOptionGroup = group()
|
protected val mainGroup: ScallopOptionGroup = group()
|
||||||
|
@@ -1,21 +1,22 @@
|
|||||||
package com.minres.tgc.hammer.cli
|
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 com.minres.tgc.hammer.tasks.{Task, TreenailTask}
|
||||||
import org.rogach.scallop.*
|
import org.rogach.scallop.*
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import os.Path
|
import os.Path
|
||||||
|
|
||||||
class TreenailCommand extends MySubcommand("parseCoreDSL") {
|
class TreenailCommand extends MySubcommand("parseCoreDSL") {
|
||||||
val coreDSL: ScallopOption[File] = trailArg[File]("coreDSL")
|
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(os.Path("isax.mlir", Global.BASE_DIR)))
|
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] = {
|
override def getRequiredTasks: Seq[Task] = {
|
||||||
Seq(
|
Seq(
|
||||||
new TreenailTask(Path(coreDSL(), os.pwd), Path(output(), os.pwd))
|
TreenailTask(coreDSL(), output())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,7 @@ import os.Shellable
|
|||||||
|
|
||||||
class CommandGroup(name: String) extends BaseGroup {
|
class CommandGroup(name: String) extends BaseGroup {
|
||||||
override def getToolParameters: Seq[Shellable] = {
|
override def getToolParameters: Seq[Shellable] = {
|
||||||
val sub = options.toSeq.map(_.getToolParameters.flatMap(_.value).mkString("=")).filter(!_.isEmpty)
|
val sub = options.toSeq.map(_.getToolParameters.flatMap(_.value).mkString("=")).filter(_.nonEmpty)
|
||||||
println(sub)
|
|
||||||
Seq(s"$name=\'${sub.mkString(" ")}\'")
|
Seq(s"$name=\'${sub.mkString(" ")}\'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,8 +6,6 @@ import os.Shellable
|
|||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
export com.minres.tgc.hammer.cli.osPathConverter
|
|
||||||
|
|
||||||
trait BaseGroup extends ConfigElement {
|
trait BaseGroup extends ConfigElement {
|
||||||
protected val options = mutable.ListBuffer[ConfigElement]()
|
protected val options = mutable.ListBuffer[ConfigElement]()
|
||||||
protected def add[T <: ConfigElement](option: T): T = {
|
protected def add[T <: ConfigElement](option: T): T = {
|
||||||
|
@@ -7,9 +7,6 @@ trait Task {
|
|||||||
def execute(): Unit
|
def execute(): Unit
|
||||||
|
|
||||||
def runExecutable(execPath: Path, args: Shellable*): os.CommandResult = {
|
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(" ")}"
|
val command = s"$execPath ${args.flatMap(_.value).mkString(" ")}"
|
||||||
os.proc("bash", "-c", command).call(stdout = os.Inherit)
|
os.proc("bash", "-c", command).call(stdout = os.Inherit)
|
||||||
}
|
}
|
||||||
|
@@ -1,27 +1,30 @@
|
|||||||
package com.minres.tgc.hammer.tasks.longnail
|
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 com.minres.tgc.hammer.options.*
|
||||||
import os.Path
|
|
||||||
import org.rogach.scallop.*
|
import org.rogach.scallop.*
|
||||||
|
import os.Path
|
||||||
|
|
||||||
class SchedulingParameters extends OptionGroup {
|
class SchedulingParameters extends OptionGroup {
|
||||||
override def name: String = "Longnail Scheduling Args"
|
override def name: String = "Longnail Scheduling Args"
|
||||||
|
|
||||||
add(new CommandGroup("--prepare-schedule-lil") {
|
add(new CommandGroup("--prepare-schedule-lil") {
|
||||||
choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = Some("LEGACY"))
|
choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = Some("LEGACY"), descr =
|
||||||
value[Path](cliName = "cellLibrary", toolName = "library")
|
"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")
|
||||||
valueS[Path](name = "opTyLibrary")
|
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") {
|
add(new CommandGroup("--schedule-lil") {
|
||||||
valueS[Int](name = "schedulingTimeout")
|
valueS[Int](name = "schedulingTimeout", default = Some(10), descr = "Longnail scheduling timeout in seconds")
|
||||||
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout")
|
value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout", default = Some(10), descr = "Longnail schedule refinement timeout in seconds")
|
||||||
value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath")
|
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"))
|
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")
|
toggle(cliName = "verboseSched", toolName = "verbose", descr = "Enable verbose ILP solver messages")
|
||||||
value[Int](cliName = "clockPeriod", toolName = "clockTime")
|
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[Int](cliName = "--maxLoopUnrollFactor", toolName = "max-unroll-factor", default = Some(16), descr = "Longnail max loop unroll factor")
|
||||||
value[Path](cliName = "--schedulingMLIR", toolName = "o")
|
value[Path](cliName = "--schedulingMLIR", toolName = "o", default = Some(OUT_DIR / "scheduling_solutions.mlir"), descr = "Output file with different scheduling solutions")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user