Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Nov 7, 2024
1 parent 386e88b commit 8090701
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
25 changes: 14 additions & 11 deletions core/src/main/java/org/lflang/analyses/dag/DagGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import java.util.PriorityQueue;
import java.util.Set;
import java.util.stream.Collectors;

import org.lflang.MessageReporter;
import org.lflang.TimeUnit;
import org.lflang.TimeValue;
import org.lflang.analyses.dag.DagNode.dagNodeType;
import org.lflang.analyses.scheduler.StaticScheduler;
import org.lflang.analyses.statespace.StateSpaceDiagram;
import org.lflang.analyses.statespace.StateSpaceExplorer.Phase;
import org.lflang.analyses.statespace.StateSpaceNode;
Expand Down Expand Up @@ -386,23 +383,29 @@ public Dag generateDag(StateSpaceDiagram stateSpaceDiagram) {

/**
* Check if a DAG meets certain criteria of a scheduler.
*
* @return true if it is, false if it is not.
*/
public void validateDag(Dag dag, StaticSchedulerType.StaticScheduler schedulerType, int fragmentId) {
public void validateDag(
Dag dag, StaticSchedulerType.StaticScheduler schedulerType, int fragmentId) {
// Check if the DAG is acyclic.
if (!dag.isValidDAG())
throw new RuntimeException("The DAG is invalid:" + " fragment " + fragmentId);
throw new RuntimeException("The DAG is invalid:" + " fragment " + fragmentId);

// If the EGS scheduler is in use, disallow WCETs of 0, because EGS
// might generate a partition mixing reactions and dummy nodes.
if (schedulerType == StaticSchedulerType.StaticScheduler.EGS) {
boolean wcetOfZeroDetected = dag.dagNodes.stream()
.filter(node -> node.nodeType == dagNodeType.REACTION)
.map(node -> node.nodeReaction)
.flatMap(reaction -> reaction.wcets.stream())
.anyMatch(wcet -> wcet.equals(TimeValue.ZERO));
boolean wcetOfZeroDetected =
dag.dagNodes.stream()
.filter(node -> node.nodeType == dagNodeType.REACTION)
.map(node -> node.nodeReaction)
.flatMap(reaction -> reaction.wcets.stream())
.anyMatch(wcet -> wcet.equals(TimeValue.ZERO));
if (wcetOfZeroDetected) {
throw new RuntimeException("A WCET of 0 is detected. When EGS scheduler is used, WCETs cannot be 0, otherwise reaction nodes and virtual nodes might be on the same partition. Please update the reaction WCETs.");
throw new RuntimeException(
"A WCET of 0 is detected. When EGS scheduler is used, WCETs cannot be 0, otherwise"
+ " reaction nodes and virtual nodes might be on the same partition. Please update"
+ " the reaction WCETs.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public PretVmObjectFile generateInstructions(Dag dagParitioned, StateSpaceFragme
// ALTERNATIVE DESIGN: remove the DU here and let the head node,
// instead of the tail node, handle DU. This potentially allows
// breaking the hyperperiod boundary.
//
//
// At this point, the global offset register has been
// updated in SYNC_BLOCK.
//
Expand All @@ -602,11 +602,7 @@ public PretVmObjectFile generateInstructions(Dag dagParitioned, StateSpaceFragme
// contribute the lag at the beginning of the hyperperiod.
if (!targetConfig.get(FastProperty.INSTANCE))
addInstructionForWorker(
instructions,
worker,
current,
null,
new InstructionDU(registers.offset, 0L));
instructions, worker, current, null, new InstructionDU(registers.offset, 0L));
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/java/org/lflang/analyses/scheduler/EgsScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.lflang.MessageReporter;
import org.lflang.analyses.dag.Dag;
import org.lflang.analyses.dag.DagNode;
Expand All @@ -32,7 +31,8 @@ public EgsScheduler(CFileConfig fileConfig) {
this.fileConfig = fileConfig;
}

public Dag partitionDag(Dag dag, MessageReporter reporter, int fragmentId, int workers, String filePostfix) {
public Dag partitionDag(
Dag dag, MessageReporter reporter, int fragmentId, int workers, String filePostfix) {
// Set all Paths and files
Path src = this.fileConfig.srcPath;
Path graphDir = fileConfig.getSrcGenPath().resolve("graphs");
Expand All @@ -56,7 +56,8 @@ public Dag partitionDag(Dag dag, MessageReporter reporter, int fragmentId, int w
"--out_dot",
partionedDagDotFile.toString(),
"--workers",
String.valueOf(workers+1), // There needs to be +1 for the dummy nodes, otherwise EGS complains.
String.valueOf(
workers + 1), // There needs to be +1 for the dummy nodes, otherwise EGS complains.
"--model",
new File(egsDir, "models/pretrained").getAbsolutePath());

Expand Down Expand Up @@ -105,11 +106,13 @@ public Dag partitionDag(Dag dag, MessageReporter reporter, int fragmentId, int w

// Check that the returned number of workers is less than the one set by the user
if (egsNumberOfWorkers > workers) {
reporter.nowhere().error(
"The EGS scheduler returned a minimum number of workers of "
+ egsNumberOfWorkers
+ " while the user specified number is "
+ workers);
reporter
.nowhere()
.error(
"The EGS scheduler returned a minimum number of workers of "
+ egsNumberOfWorkers
+ " while the user specified number is "
+ workers);
}

// Define a color for each worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.lflang.MessageReporter;
import org.lflang.analyses.dag.Dag;
import org.lflang.analyses.dag.DagNode;
Expand Down Expand Up @@ -40,7 +39,8 @@ public long getTotalWCET() {
}
}

public Dag partitionDag(Dag dag, MessageReporter reporter, int fragmentId, int numWorkers, String filePostfix) {
public Dag partitionDag(
Dag dag, MessageReporter reporter, int fragmentId, int numWorkers, String filePostfix) {

// Prune redundant edges.
dag.removeRedundantEdges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.lflang.MessageReporter;
import org.lflang.TimeValue;
import org.lflang.analyses.dag.Dag;
Expand Down Expand Up @@ -297,7 +296,8 @@ public static boolean validateXMLSchema(String xsdPath, String xmlPath) {
}

/** Main function for assigning nodes to workers */
public Dag partitionDag(Dag dagRaw, MessageReporter reporter, int fragmentId, int numWorkers, String filePostfix) {
public Dag partitionDag(
Dag dagRaw, MessageReporter reporter, int fragmentId, int numWorkers, String filePostfix) {

// Prune redundant edges.
dagRaw.removeRedundantEdges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* @author Shaokai Lin
*/
public interface StaticScheduler {
public Dag partitionDag(Dag dag, MessageReporter reporter, int fragmentId, int workers, String filePostfix);
public Dag partitionDag(
Dag dag, MessageReporter reporter, int fragmentId, int workers, String filePostfix);

public int setNumberOfWorkers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public void generate() {
StaticScheduler scheduler = createStaticScheduler();

// Store the static scheduler type.
StaticSchedulerType.StaticScheduler schedulerType = targetConfig.get(SchedulerProperty.INSTANCE).staticScheduler();
StaticSchedulerType.StaticScheduler schedulerType =
targetConfig.get(SchedulerProperty.INSTANCE).staticScheduler();

// Determine the number of workers, if unspecified.
if (this.workers == 0) {
Expand Down Expand Up @@ -173,15 +174,16 @@ public void generate() {

// Validate the generated raw DAG.
dagGenerator.validateDag(dag, schedulerType, i);

// Generate a dot file.
Path file = graphDir.resolve("dag_raw" + "_frag_" + i + ".dot");
dag.generateDotFile(file);

// Generate a partitioned DAG based on the number of workers.
// FIXME: Bring the DOT generation calls to this level instead of hiding
// them inside partitionDag().
Dag dagPartitioned = scheduler.partitionDag(dag, messageReporter, i, this.workers, "_frag_" + i);
Dag dagPartitioned =
scheduler.partitionDag(dag, messageReporter, i, this.workers, "_frag_" + i);

// Do not execute the following steps for the MOCASIN scheduler yet.
// FIXME: A pass-based architecture would be better at managing this.
Expand Down

0 comments on commit 8090701

Please sign in to comment.