Commit 5cec7aba authored by Jens Korinth's avatar Jens Korinth

Closes #2 - Fix number of threads in Compose

* replaced maxThread var in trait Composer by implicit argument to
  compose method, facilitates easy pass-through
* in Tcl, tapasco_jobs global and the Vivado maxThreads setting are only
  written if maxThreads is not None (default value)
* dse.Run sets the implicit to 1
parent ce53b756
......@@ -30,25 +30,22 @@ import de.tu_darmstadt.cs.esa.tapasco.reports._
using an external tool (e.g., Vivado). **/
trait Composer {
import Composer._
// FIXME this seems not a clean approach
private final val MAX_CPUS = 8
var maxThreads: Int = Seq(Runtime.getRuntime().availableProcessors(), MAX_CPUS).min
/** Returns the approximate peak memory usage per process in GiB. **/
def maxMemoryUsagePerProcess: Int
/** Start run of external tool.
* @param maxThreads maximum number of parallel threads to use
* @param bd Composition to synthesize
* @param target Platform and Architecture combination to synthesize for
* @param f target design frequency (PE speed)
* @param platformFeatures Platform features (optional).
* @param archFeatures ArchitectureFeatures (optional).
* @param platformFeatures Platform features (optional).
* @param cfg implicit Configuration instance
* @param maxThreads maximum number of parallel threads to use (default: unlimited)
* @return Composer.Result with error code / additional data
**/
def compose(bd: Composition, target: Target, f: Double = 0, archFeatures: Seq[Feature] = Seq(),
platformFeatures: Seq[Feature] = Seq())(implicit cfg: Configuration): Result
platformFeatures: Seq[Feature] = Seq())(implicit cfg: Configuration, maxThreads: Option[Int] = None): Result
/** Removes all intermediate files for the run, leaving results.
* @param bd Composition to synthesize
......@@ -77,8 +74,8 @@ object Composer {
}
}
def apply(i: Implementation)(implicit cfg: Configuration): Composer = i match {
case Implementation.Vivado => new VivadoComposer()(cfg)
def apply(i: Implementation)(implicit cfg: Configuration, maxThreads: Option[Int]): Composer = i match {
case Implementation.Vivado => new VivadoComposer()(cfg, maxThreads)
}
/** Extended result with additional information as provided by the tool. **/
......
......@@ -36,7 +36,7 @@ import ComposeResult._
import LogFormatter._
/** Implementation of [[Composer]] for Vivado Design Suite. */
class VivadoComposer()(implicit cfg: Configuration) extends Composer {
class VivadoComposer()(implicit cfg: Configuration, maxThreads: Option[Int]) extends Composer {
import VivadoComposer._
private[this] val logger = de.tu_darmstadt.cs.esa.tapasco.Logging.logger(this.getClass)
......@@ -45,7 +45,8 @@ class VivadoComposer()(implicit cfg: Configuration) extends Composer {
/** @inheritdoc */
def compose(bd: Composition, target: Target, f: Heuristics.Frequency = 0, archFeatures: Seq[Feature] = Seq(),
platformFeatures: Seq[Feature] = Seq()) (implicit cfg: Configuration): Composer.Result = {
platformFeatures: Seq[Feature] = Seq()) (implicit cfg: Configuration, maxThreads: Option[Int]): Composer.Result = {
logger.debug("VivadoComposer uses at most {} threads", maxThreads getOrElse "unlimited")
// create output struct
val files = VivadoComposer.Files(bd, target, f)
// create output directory
......@@ -187,8 +188,8 @@ class VivadoComposer()(implicit cfg: Configuration) extends Composer {
target. pd.api.getOrElse("missing") + "}" + NL +
"set TAPASCO_SIM_MODULE " + target.pd.testbenchTemplate.getOrElse("missing") + NL +
"set TAPASCO_BOARD_PRESET " + target.pd.boardPreset + NL +
"set_param general.maxThreads " + maxThreads + NL +
"set tapasco_jobs " + maxThreads + NL +
(maxThreads map (mt => "set_param general.maxThreads %d%s".format(mt, NL)) getOrElse "") +
(maxThreads map (mt => "set tapasco_jobs %d%s".format(mt, NL)) getOrElse "") +
"set tapasco_freq " + f + NL +
(platformFeatures.map { f => new FeatureTclPrinter("platform").toTcl(f) } mkString NL) +
(archFeatures.map { f => new FeatureTclPrinter("architecture").toTcl(f) } mkString NL) + NL
......
......@@ -24,6 +24,7 @@ private class ConcreteRun(val no: Int, val element: DesignSpace.Element, val tar
def start(signal: Option[CountDownLatch]): Unit = {
val id = "%05d".format(no)
implicit val maxThreads: Option[Int] = Some(1) // limit number of threads in DSE to control load
val t = new ComposeTask(
composition = element.composition,
designFrequency = element.frequency,
......
......@@ -16,15 +16,15 @@ import scala.util.Properties.{lineSeparator => NL}
* It will run the composition tool (e.g., Xilinx Vivado) as a separate process
* and return the result (see [[activity.composers]]).
**/
class ComposeTask(
composition: Composition,
designFrequency: Heuristics.Frequency,
implementation: Composer.Implementation,
target: Target,
features: Option[Seq[Feature]] = None,
logFile: Option[String] = None,
debugMode: Option[String] = None,
val onComplete: Boolean => Unit)(implicit cfg: Configuration) extends Task with LogTracking {
class ComposeTask(composition: Composition,
designFrequency: Heuristics.Frequency,
implementation: Composer.Implementation,
target: Target,
features: Option[Seq[Feature]] = None,
logFile: Option[String] = None,
debugMode: Option[String] = None,
val onComplete: Boolean => Unit)
(implicit cfg: Configuration, maxThreads: Option[Int] = None) extends Task with LogTracking {
private[this] implicit val _logger = de.tu_darmstadt.cs.esa.tapasco.Logging.logger(getClass)
private[this] val _slurm = Slurm.enabled
private[this] var _composerResult: Option[Composer.Result] = None
......@@ -41,8 +41,7 @@ class ComposeTask(
private def nodeExecution: Boolean = {
val appender = LogFileTracker.setupLogFileAppender(_logFile.toString)
val composer = Composer(implementation)
composer.maxThreads = 1
val composer = Composer(implementation)(cfg, maxThreads)
_logger.debug("launching compose run for {}@{} [current thread: {}], logfile {}",
target.ad.name: Object, target.pd.name: Object, Thread.currentThread.getName(): Object, _logFile: Object)
if (debugMode.isEmpty) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment