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

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._ ...@@ -30,25 +30,22 @@ import de.tu_darmstadt.cs.esa.tapasco.reports._
using an external tool (e.g., Vivado). **/ using an external tool (e.g., Vivado). **/
trait Composer { trait Composer {
import 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. **/ /** Returns the approximate peak memory usage per process in GiB. **/
def maxMemoryUsagePerProcess: Int def maxMemoryUsagePerProcess: Int
/** Start run of external tool. /** Start run of external tool.
* @param maxThreads maximum number of parallel threads to use
* @param bd Composition to synthesize * @param bd Composition to synthesize
* @param target Platform and Architecture combination to synthesize for * @param target Platform and Architecture combination to synthesize for
* @param f target design frequency (PE speed) * @param f target design frequency (PE speed)
* @param platformFeatures Platform features (optional).
* @param archFeatures ArchitectureFeatures (optional). * @param archFeatures ArchitectureFeatures (optional).
* @param platformFeatures Platform features (optional).
* @param cfg implicit Configuration instance * @param cfg implicit Configuration instance
* @param maxThreads maximum number of parallel threads to use (default: unlimited)
* @return Composer.Result with error code / additional data * @return Composer.Result with error code / additional data
**/ **/
def compose(bd: Composition, target: Target, f: Double = 0, archFeatures: Seq[Feature] = Seq(), 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. /** Removes all intermediate files for the run, leaving results.
* @param bd Composition to synthesize * @param bd Composition to synthesize
...@@ -77,8 +74,8 @@ object Composer { ...@@ -77,8 +74,8 @@ object Composer {
} }
} }
def apply(i: Implementation)(implicit cfg: Configuration): Composer = i match { def apply(i: Implementation)(implicit cfg: Configuration, maxThreads: Option[Int]): Composer = i match {
case Implementation.Vivado => new VivadoComposer()(cfg) case Implementation.Vivado => new VivadoComposer()(cfg, maxThreads)
} }
/** Extended result with additional information as provided by the tool. **/ /** Extended result with additional information as provided by the tool. **/
......
...@@ -36,7 +36,7 @@ import ComposeResult._ ...@@ -36,7 +36,7 @@ import ComposeResult._
import LogFormatter._ import LogFormatter._
/** Implementation of [[Composer]] for Vivado Design Suite. */ /** 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._ import VivadoComposer._
private[this] val logger = de.tu_darmstadt.cs.esa.tapasco.Logging.logger(this.getClass) 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 { ...@@ -45,7 +45,8 @@ class VivadoComposer()(implicit cfg: Configuration) extends Composer {
/** @inheritdoc */ /** @inheritdoc */
def compose(bd: Composition, target: Target, f: Heuristics.Frequency = 0, archFeatures: Seq[Feature] = Seq(), 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 // create output struct
val files = VivadoComposer.Files(bd, target, f) val files = VivadoComposer.Files(bd, target, f)
// create output directory // create output directory
...@@ -187,8 +188,8 @@ class VivadoComposer()(implicit cfg: Configuration) extends Composer { ...@@ -187,8 +188,8 @@ class VivadoComposer()(implicit cfg: Configuration) extends Composer {
target. pd.api.getOrElse("missing") + "}" + NL + target. pd.api.getOrElse("missing") + "}" + NL +
"set TAPASCO_SIM_MODULE " + target.pd.testbenchTemplate.getOrElse("missing") + NL + "set TAPASCO_SIM_MODULE " + target.pd.testbenchTemplate.getOrElse("missing") + NL +
"set TAPASCO_BOARD_PRESET " + target.pd.boardPreset + NL + "set TAPASCO_BOARD_PRESET " + target.pd.boardPreset + NL +
"set_param general.maxThreads " + maxThreads + NL + (maxThreads map (mt => "set_param general.maxThreads %d%s".format(mt, NL)) getOrElse "") +
"set tapasco_jobs " + maxThreads + NL + (maxThreads map (mt => "set tapasco_jobs %d%s".format(mt, NL)) getOrElse "") +
"set tapasco_freq " + f + NL + "set tapasco_freq " + f + NL +
(platformFeatures.map { f => new FeatureTclPrinter("platform").toTcl(f) } mkString NL) + (platformFeatures.map { f => new FeatureTclPrinter("platform").toTcl(f) } mkString NL) +
(archFeatures.map { f => new FeatureTclPrinter("architecture").toTcl(f) } mkString NL) + 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 ...@@ -24,6 +24,7 @@ private class ConcreteRun(val no: Int, val element: DesignSpace.Element, val tar
def start(signal: Option[CountDownLatch]): Unit = { def start(signal: Option[CountDownLatch]): Unit = {
val id = "%05d".format(no) 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( val t = new ComposeTask(
composition = element.composition, composition = element.composition,
designFrequency = element.frequency, designFrequency = element.frequency,
......
...@@ -16,15 +16,15 @@ import scala.util.Properties.{lineSeparator => NL} ...@@ -16,15 +16,15 @@ import scala.util.Properties.{lineSeparator => NL}
* It will run the composition tool (e.g., Xilinx Vivado) as a separate process * It will run the composition tool (e.g., Xilinx Vivado) as a separate process
* and return the result (see [[activity.composers]]). * and return the result (see [[activity.composers]]).
**/ **/
class ComposeTask( class ComposeTask(composition: Composition,
composition: Composition, designFrequency: Heuristics.Frequency,
designFrequency: Heuristics.Frequency, implementation: Composer.Implementation,
implementation: Composer.Implementation, target: Target,
target: Target, features: Option[Seq[Feature]] = None,
features: Option[Seq[Feature]] = None, logFile: Option[String] = None,
logFile: Option[String] = None, debugMode: Option[String] = None,
debugMode: Option[String] = None, val onComplete: Boolean => Unit)
val onComplete: Boolean => Unit)(implicit cfg: Configuration) extends Task with LogTracking { (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] implicit val _logger = de.tu_darmstadt.cs.esa.tapasco.Logging.logger(getClass)
private[this] val _slurm = Slurm.enabled private[this] val _slurm = Slurm.enabled
private[this] var _composerResult: Option[Composer.Result] = None private[this] var _composerResult: Option[Composer.Result] = None
...@@ -41,8 +41,7 @@ class ComposeTask( ...@@ -41,8 +41,7 @@ class ComposeTask(
private def nodeExecution: Boolean = { private def nodeExecution: Boolean = {
val appender = LogFileTracker.setupLogFileAppender(_logFile.toString) val appender = LogFileTracker.setupLogFileAppender(_logFile.toString)
val composer = Composer(implementation) val composer = Composer(implementation)(cfg, maxThreads)
composer.maxThreads = 1
_logger.debug("launching compose run for {}@{} [current thread: {}], logfile {}", _logger.debug("launching compose run for {}@{} [current thread: {}], logfile {}",
target.ad.name: Object, target.pd.name: Object, Thread.currentThread.getName(): Object, _logFile: Object) target.ad.name: Object, target.pd.name: Object, Thread.currentThread.getName(): Object, _logFile: Object)
if (debugMode.isEmpty) { 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