From 44e97826d4b7c3fe4b49d44ce5ac04b52b595ab7 Mon Sep 17 00:00:00 2001 From: Colin Schmidt Date: Sun, 17 Mar 2019 14:05:51 -0700 Subject: [PATCH] Fix cost metric for non Compiler libs Also a small fix from reviewer --- macros/src/main/scala/CostMetric.scala | 11 ++++++++++- macros/src/main/scala/MacroCompiler.scala | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/macros/src/main/scala/CostMetric.scala b/macros/src/main/scala/CostMetric.scala index ce95a861..e940cd8e 100644 --- a/macros/src/main/scala/CostMetric.scala +++ b/macros/src/main/scala/CostMetric.scala @@ -122,7 +122,16 @@ object DefaultMetric extends CostMetric with CostMetricCompanion { } val depthCost = (mem.src.depth.toDouble / lib.src.depth.toDouble) val widthCost = (memWidth.toDouble / lib.src.width.toDouble) - return Some(depthCost * widthCost) + val bitsCost = (lib.src.depth * lib.src.width) + // The most complicated case occurs when you have a 1x1 lib and a 1Mx1M lib and a third sane lib. + // In this case you want to ensure that a lib slightly smaller or larger than mem as the third lib + // will always be selected over the stupid libs. + if(widthCost < 1 && depthCost < 1) Some(bitsCost) // If the lib is bigger than pick the smallest lib + // If its not bigger in both dimensions pick the smallest in the dimension that the lib is larger in + else if(widthCost < 1) Some(depthCost * lib.src.width) + else if(depthCost < 1) Some(widthCost * lib.src.depth) + // If the lib is equal or smaller than source mem pick the largest lib + else Some(depthCost * widthCost) } override def commandLineParams = Map() diff --git a/macros/src/main/scala/MacroCompiler.scala b/macros/src/main/scala/MacroCompiler.scala index 4250ad6e..7a76e756 100644 --- a/macros/src/main/scala/MacroCompiler.scala +++ b/macros/src/main/scala/MacroCompiler.scala @@ -569,7 +569,6 @@ class MacroCompilerPass(mems: Option[Seq[Macro]], val memMask = mem.ports map (_.maskGran) find (_.isDefined) map (_.get) val libMask = group.ports map (_.maskGran) find (_.isDefined) map (_.get) (memMask, libMask) match { - case (_, Some(1)) => true case (None, _) => true case (Some(_), None) => false case (Some(m), Some(l)) => l <= m //Ignore memories that don't have nice mask