Skip to content

Commit

Permalink
Clean up mocasin-related codegen logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Oct 23, 2024
1 parent 47e0c4e commit 0dba557
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cli/lfc/src/main/java/org/lflang/cli/Lfc.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class Lfc extends CliBase {
@Option(
names = {"--mapper"},
description =
"Select a specific static scheduler if scheduler is set to STATIC."
"Select a specific mapper (i.e., static scheduler) if scheduler is set to STATIC."
+ " Options: LB (default), EGS, MOCASIN")
private String staticScheduler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,28 @@ public void generate() {
// them inside partitionDag().
Dag dagPartitioned = scheduler.partitionDag(dag, i, this.workers, "_frag_" + i);

// Do not execute the following step for the MOCASIN scheduler yet.
// Do not execute the following steps for the MOCASIN scheduler yet.
// FIXME: A pass-based architecture would be better at managing this.
if (!(targetConfig.get(SchedulerProperty.INSTANCE).staticScheduler()
== StaticSchedulerType.StaticScheduler.MOCASIN
&& (targetConfig.get(SchedulerProperty.INSTANCE).mocasinMapping() == null
|| targetConfig.get(SchedulerProperty.INSTANCE).mocasinMapping().size() == 0))) {
// Ensure the DAG is valid before proceeding to generating instructions.
if (!dagPartitioned.isValidDAG())
throw new RuntimeException("The generated DAG is invalid:" + " fragment " + i);
// Generate instructions (wrapped in an object file) from DAG partitions.
PretVmObjectFile objectFile = instGen.generateInstructions(dagPartitioned, fragment);
// Point the fragment to the new object file.
fragment.setObjectFile(objectFile);
// Add the object file to list.
pretvmObjectFiles.add(objectFile);
}
if (usingMocasinButNoMappingYet()) continue;

// Ensure the DAG is valid before proceeding to generating instructions.
if (!dagPartitioned.isValidDAG())
throw new RuntimeException("The generated DAG is invalid:" + " fragment " + i);

// Generate instructions (wrapped in an object file) from DAG partitions.
PretVmObjectFile objectFile = instGen.generateInstructions(dagPartitioned, fragment);

// Point the fragment to the new object file.
fragment.setObjectFile(objectFile);

// Add the object file to list.
pretvmObjectFiles.add(objectFile);
}

// Do not execute the following step if the MOCASIN scheduler in used and
// mappings are not provided.
// FIXME: A pass-based architecture would be better at managing this.
if (targetConfig.get(SchedulerProperty.INSTANCE).staticScheduler()
== StaticSchedulerType.StaticScheduler.MOCASIN
&& (targetConfig.get(SchedulerProperty.INSTANCE).mocasinMapping() == null
|| targetConfig.get(SchedulerProperty.INSTANCE).mocasinMapping().size() == 0)) {
if (usingMocasinButNoMappingYet()) {
messageReporter
.nowhere()
.info(
Expand Down Expand Up @@ -235,6 +232,16 @@ public void generate() {
instGen.generateCode(executable);
}

/**
* Check if Mocasin is used but no mapping is provided yet.
*/
private boolean usingMocasinButNoMappingYet() {
return (targetConfig.get(SchedulerProperty.INSTANCE).staticScheduler()
== StaticSchedulerType.StaticScheduler.MOCASIN
&& (targetConfig.get(SchedulerProperty.INSTANCE).mocasinMapping() == null
|| targetConfig.get(SchedulerProperty.INSTANCE).mocasinMapping().size() == 0));
}

/**
* Generate a list of state space fragments for an LF program. This function calls
* generateStateSpaceDiagram(<phase>) multiple times to capture the full behavior of the LF
Expand Down

0 comments on commit 0dba557

Please sign in to comment.