Change cost to double from BigInt and fix default metric
I don't think it was adding anything and now we can get rid of the weird +1/-1
This commit is contained in:
committed by
Colin Schmidt
parent
45278a6de0
commit
a0510e6664
@@ -18,7 +18,7 @@ trait CostMetric extends Serializable {
|
|||||||
* @return The cost of this compile, defined by this cost metric, or None if
|
* @return The cost of this compile, defined by this cost metric, or None if
|
||||||
* it cannot be compiled.
|
* it cannot be compiled.
|
||||||
*/
|
*/
|
||||||
def cost(mem: Macro, lib: Macro): Option[BigInt]
|
def cost(mem: Macro, lib: Macro): Option[Double]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to return the map of arguments (or an empty map if there are none).
|
* Helper function to return the map of arguments (or an empty map if there are none).
|
||||||
@@ -43,7 +43,7 @@ trait CostMetricCompanion {
|
|||||||
* TODO: figure out what is the difference between this metric and the current
|
* TODO: figure out what is the difference between this metric and the current
|
||||||
* default metric and either revive or delete this metric. */
|
* default metric and either revive or delete this metric. */
|
||||||
object OldMetric extends CostMetric with CostMetricCompanion {
|
object OldMetric extends CostMetric with CostMetricCompanion {
|
||||||
override def cost(mem: Macro, lib: Macro): Option[BigInt] = {
|
override def cost(mem: Macro, lib: Macro): Option[Double] = {
|
||||||
/* Palmer: A quick cost function (that must be kept in sync with
|
/* Palmer: A quick cost function (that must be kept in sync with
|
||||||
* memory_cost()) that attempts to avoid compiling unncessary
|
* memory_cost()) that attempts to avoid compiling unncessary
|
||||||
* memories. This is a lower bound on the cost of compiling a
|
* memories. This is a lower bound on the cost of compiling a
|
||||||
@@ -61,9 +61,9 @@ object OldMetric extends CostMetric with CostMetricCompanion {
|
|||||||
/**
|
/**
|
||||||
* An external cost function.
|
* An external cost function.
|
||||||
* Calls the specified path with paths to the JSON MDF representation of the mem
|
* Calls the specified path with paths to the JSON MDF representation of the mem
|
||||||
* and lib macros. The external executable should print a BigInt.
|
* and lib macros. The external executable should print a Double.
|
||||||
* None will be returned if the external executable does not print a valid
|
* None will be returned if the external executable does not print a valid
|
||||||
* BigInt.
|
* Double.
|
||||||
*/
|
*/
|
||||||
class ExternalMetric(path: String) extends CostMetric {
|
class ExternalMetric(path: String) extends CostMetric {
|
||||||
import mdf.macrolib.Utils.writeMacroToPath
|
import mdf.macrolib.Utils.writeMacroToPath
|
||||||
@@ -71,7 +71,7 @@ class ExternalMetric(path: String) extends CostMetric {
|
|||||||
import scala.language.postfixOps // for !! postfix op
|
import scala.language.postfixOps // for !! postfix op
|
||||||
import sys.process._
|
import sys.process._
|
||||||
|
|
||||||
override def cost(mem: Macro, lib: Macro): Option[BigInt] = {
|
override def cost(mem: Macro, lib: Macro): Option[Double] = {
|
||||||
// Create temporary files.
|
// Create temporary files.
|
||||||
val memFile = File.createTempFile("_macrocompiler_mem_", ".json")
|
val memFile = File.createTempFile("_macrocompiler_mem_", ".json")
|
||||||
val libFile = File.createTempFile("_macrocompiler_lib_", ".json")
|
val libFile = File.createTempFile("_macrocompiler_lib_", ".json")
|
||||||
@@ -87,7 +87,7 @@ class ExternalMetric(path: String) extends CostMetric {
|
|||||||
libFile.delete()
|
libFile.delete()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Some(BigInt(result))
|
Some(result.toDouble)
|
||||||
} catch {
|
} catch {
|
||||||
case e: NumberFormatException => None
|
case e: NumberFormatException => None
|
||||||
}
|
}
|
||||||
@@ -113,18 +113,16 @@ object ExternalMetric extends CostMetricCompanion {
|
|||||||
/** The current default metric in barstools, re-defined by Donggyu. */
|
/** The current default metric in barstools, re-defined by Donggyu. */
|
||||||
// TODO: write tests for this function to make sure it selects the right things
|
// TODO: write tests for this function to make sure it selects the right things
|
||||||
object DefaultMetric extends CostMetric with CostMetricCompanion {
|
object DefaultMetric extends CostMetric with CostMetricCompanion {
|
||||||
override def cost(mem: Macro, lib: Macro): Option[BigInt] = {
|
override def cost(mem: Macro, lib: Macro): Option[Double] = {
|
||||||
val memMask = mem.src.ports map (_.maskGran) find (_.isDefined) map (_.get)
|
val memMask = mem.src.ports map (_.maskGran) find (_.isDefined) map (_.get)
|
||||||
val libMask = lib.src.ports map (_.maskGran) find (_.isDefined) map (_.get)
|
val libMask = lib.src.ports map (_.maskGran) find (_.isDefined) map (_.get)
|
||||||
val memWidth = (memMask, libMask) match {
|
val memWidth = (memMask, libMask) match {
|
||||||
case (Some(1), Some(1)) | (None, _) => mem.src.width
|
case (Some(_), Some(1)) | (None, _) => mem.src.width
|
||||||
case (Some(p), _) => p // assume that the memory consists of smaller chunks
|
case (Some(p), _) => p // assume that the memory consists of smaller chunks
|
||||||
}
|
}
|
||||||
return Some(
|
val depthCost = (mem.src.depth.toDouble / lib.src.depth.toDouble)
|
||||||
(((mem.src.depth - 1) / lib.src.depth) + 1) *
|
val widthCost = (memWidth.toDouble / lib.src.width.toDouble)
|
||||||
(((memWidth - 1) / lib.src.width) + 1) *
|
return Some(depthCost * widthCost)
|
||||||
(lib.src.depth * lib.src.width + 1) // weights on # cells
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override def commandLineParams = Map()
|
override def commandLineParams = Map()
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ class MacroCompilerPass(mems: Option[Seq[Macro]],
|
|||||||
|
|
||||||
// Try to compile mem against each lib in libs, keeping track of the
|
// Try to compile mem against each lib in libs, keeping track of the
|
||||||
// best compiled version, external lib used, and cost.
|
// best compiled version, external lib used, and cost.
|
||||||
val (best, cost) = (libs foldLeft (None: Option[(Module, ExtModule)], BigInt(Long.MaxValue))){
|
val (best, cost) = (fullLibs foldLeft (None: Option[(Module, ExtModule)], Double.MaxValue)){
|
||||||
case ((best, cost), lib) if mem.src.ports.size != lib.src.ports.size =>
|
case ((best, cost), lib) if mem.src.ports.size != lib.src.ports.size =>
|
||||||
/* Palmer: FIXME: This just assumes the Chisel and vendor ports are in the same
|
/* Palmer: FIXME: This just assumes the Chisel and vendor ports are in the same
|
||||||
* order, but I'm starting with what actually gets generated. */
|
* order, but I'm starting with what actually gets generated. */
|
||||||
|
|||||||
Reference in New Issue
Block a user