Skip to content

Commit

Permalink
Merge pull request #16 from abs-tudelft/feature/better-reporting
Browse files Browse the repository at this point in the history
Better reporting
  • Loading branch information
ccromjongh authored Oct 9, 2024
2 parents 916efb8 + d860f87 commit 34926b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
36 changes: 24 additions & 12 deletions library/src/main/scala/nl/tudelft/tydi_chisel/TydiLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,17 @@ sealed abstract class PhysicalStreamBase(private val e: TydiEl, val n: Int, val
}

protected def reportProblem(problemStr: String, compatCheckResult: CompatCheckResult.Value): Unit = {
compatCheckResult match {
case CompatCheckResult.Error => throw TydiStreamCompatException(problemStr)
case CompatCheckResult.Warning => printWarning(problemStr)
val checkResult = nl.tudelft.tydi_chisel.compatCheckResult match {
case None => compatCheckResult
case x: Some[_] => x.get
}

checkResult match {
case CompatCheckResult.Error => throw TydiStreamCompatException(problemStr)
case CompatCheckResult.Warning => {
val stackTrace = new Exception().getStackTrace.slice(2, 8).mkString("\nTrace:\n\t", "\n\t", "\n")
printWarning(problemStr + stackTrace)
}
}
}

Expand All @@ -358,22 +366,21 @@ sealed abstract class PhysicalStreamBase(private val e: TydiEl, val n: Int, val
// Number of lanes should be the same
if (toConnect.n != this.n) {
reportProblem(
s"Number of lanes between source and sink is not equal. ${this} has n=${this.n}, ${toConnect
.toString()} has n=${toConnect.n}",
s"Number of lanes between source and sink is not equal.\n\t- ${this} has n=${this.n}\n\t- ${toConnect} has n=${toConnect.n}",
compatCheckResult
)
}
// Dimensionality should be the same
if (toConnect.d != this.d) {
reportProblem(
s"Dimensionality of source and sink is not equal. ${this} has d=${this.d}, ${toConnect} has d=${toConnect.d}",
s"Dimensionality of source and sink is not equal.\n\t- ${this} has d=${this.d}\n\t- ${toConnect} has d=${toConnect.d}",
compatCheckResult
)
}
// Sink C >= source C for compatibility
if (toConnect.c > this.c) {
reportProblem(
s"Complexity of source stream > sink. ${this} has c=${this.c}, ${toConnect} has c=${toConnect.c}",
s"Complexity of source stream > sink.\n\t- ${this} has c=${this.c}\n\t- ${toConnect} has c=${toConnect.c}",
compatCheckResult
)
}
Expand All @@ -382,13 +389,13 @@ sealed abstract class PhysicalStreamBase(private val e: TydiEl, val n: Int, val
def elementCheck(toConnect: PhysicalStreamBase, compatCheckResult: CompatCheckResult.Value): Unit = {
if (this.elWidth != toConnect.elWidth) {
reportProblem(
s"Size of stream elements is not equal. ${this} has |e|=${this.elWidth}, ${toConnect} has |e|=${toConnect.elWidth}",
s"Size of stream elements is not equal.\n\t- ${this} has |e|=${this.elWidth}\n\t- ${toConnect} has |e|=${toConnect.elWidth}",
compatCheckResult
)
}
if (this.userElWidth != toConnect.userElWidth) {
reportProblem(
s"Size of stream elements is not equal. ${this} has |u|=${this.userElWidth}, ${toConnect} has |u|=${toConnect.userElWidth}",
s"Size of stream elements is not equal.\n\t- ${this} has |u|=${this.userElWidth}\n\t- ${toConnect} has |u|=${toConnect.userElWidth}",
compatCheckResult
)
}
Expand All @@ -399,16 +406,21 @@ sealed abstract class PhysicalStreamBase(private val e: TydiEl, val n: Int, val
typeCheck: CompatCheck.Value,
compatCheckResult: CompatCheckResult.Value
): Unit = {
if (typeCheck == CompatCheck.Strict) {
val check = nl.tudelft.tydi_chisel.compatCheck match {
case None => typeCheck
case x: Some[_] => x.get
}

if (check == CompatCheck.Strict) {
if (this.getDataType.getClass != toConnect.getDataType.getClass) {
reportProblem(
s"Type of stream elements is not equal. ${this} has e=${this.getDataType.getClass}, ${toConnect} has e=${toConnect.getDataType.getClass}",
s"Type of stream elements is not equal.\n\t- ${this} has e=${this.getDataType.getClass}, |e|=${this.elWidth}\n\t- ${toConnect} has e=${toConnect.getDataType.getClass}, |e|=${toConnect.elWidth}",
compatCheckResult
)
}
if (this.getUserType.getClass != toConnect.getUserType.getClass) {
reportProblem(
s"Type of user elements is not equal. ${this} has u=${this.getUserType.getClass}, ${toConnect} has u=${toConnect.getUserType.getClass}",
s"Type of user elements is not equal.\n\t- ${this} has u=${this.getUserType.getClass}, |u|=${this.userElWidth}\n\t- ${toConnect} has u=${toConnect.getUserType.getClass}, |u|=${toConnect.userElWidth}",
compatCheckResult
)
}
Expand Down
9 changes: 2 additions & 7 deletions library/src/main/scala/nl/tudelft/tydi_chisel/TydiUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,8 @@ class MultiProcessorGeneral(
*/
class StreamDuplicator(val k: Int = 2, template: PhysicalStream) extends TydiModule {
// Create a new instance so we do not need to worry about directions.
private val stream: PhysicalStream = PhysicalStream(
new BitsEl(template.elWidth.W),
n = template.n,
d = template.d,
c = template.c,
u = UInt(template.userElWidth.W)
)
private val stream: PhysicalStream =
PhysicalStream(template.getDataType, n = template.n, d = template.d, c = template.c, u = template.getUserType)
val in: PhysicalStream = IO(Flipped(stream))
val out: Vec[PhysicalStream] = IO(Vec(k, stream))

Expand Down
16 changes: 16 additions & 0 deletions library/src/main/scala/nl/tudelft/tydi_chisel/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ package object tydi_chisel {
val firNoOptimizationOpts: Array[String] = Array("-disable-opt", "-disable-all-randomization", "-strip-debug-info")
val firNormalOpts: Array[String] = Array("-O=debug", "-disable-all-randomization", "-strip-debug-info")
val firReleaseOpts: Array[String] = Array("-O=release", "-disable-all-randomization", "-strip-debug-info")

private[this] var _compatCheckResult: Option[CompatCheckResult.Value] = None

def compatCheckResult: Option[CompatCheckResult.Value] = _compatCheckResult

def setCompatCheckResult(value: CompatCheckResult.Value): Unit = {
_compatCheckResult = Some(value)
}

private[this] var _compatCheck: Option[CompatCheck.Value] = None

def compatCheck: Option[CompatCheck.Value] = _compatCheck

def setCompatCheck(value: CompatCheck.Value): Unit = {
_compatCheck = Some(value)
}
}

0 comments on commit 34926b8

Please sign in to comment.