Skip to content

Commit

Permalink
Merge pull request #743 from lf-lang/c-new-scheduler
Browse files Browse the repository at this point in the history
C new scheduler
  • Loading branch information
edwardalee authored Feb 26, 2022
2 parents 742d0c3 + 900c449 commit 14e26fe
Show file tree
Hide file tree
Showing 47 changed files with 486 additions and 125 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/c-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
required: false
type: boolean
default: false
scheduler:
required: false
type: string

jobs:
run:
Expand Down Expand Up @@ -53,14 +56,19 @@ jobs:
- name: Build RTI docker image
uses: ./.github/actions/build-rti-docker
if: ${{ runner.os == 'Linux' }}
- name: Perform tests for C target
- name: Perform tests for C target with default scheduler
run: |
./gradlew test --tests org.lflang.tests.runtime.CTest.* --tests org.lflang.tests.lsp.LspTests.lspWithDependenciesTestC
if: ${{ !inputs.use-cpp }}
- name: Perform tests for CCpp target
if: ${{ !inputs.use-cpp && !inputs.scheduler }}
- name: Perform tests for C target with specified scheduler (no LSP tests)
run: |
echo "Specified scheduler: ${{ inputs.scheduler }}"
./gradlew test --tests org.lflang.tests.runtime.CSchedulerTest.* -Dscheduler=${{ inputs.scheduler }}
if: ${{ !inputs.use-cpp && inputs.scheduler }}
- name: Perform tests for CCpp target with default scheduler
run: |
./gradlew test --tests org.lflang.tests.runtime.CCppTest.*
if: ${{ inputs.use-cpp }}
if: ${{ inputs.use-cpp && !inputs.scheduler }}
- name: Report to CodeCov
uses: codecov/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/concurrency/BoundedBuffer.lf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/concurrency/Dictionary.lf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target CCpp {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/concurrency/LogisticMap.lf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
3 changes: 2 additions & 1 deletion benchmark/C/Savina/src/concurrency/Philosophers.lf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down Expand Up @@ -183,7 +184,7 @@ reactor Arbitrator(num_philosophers:int(20)) {
if (finished[i]->is_present) {
self->finished_philosophers++;
if (self->num_philosophers == self->finished_philosophers) {
printf("Arbitrator: All philosophers are seated. Number of denials to philosophers: %d\n", self->retries);
printf("Arbitrator: All philosophers are sated. Number of denials to philosophers: %d\n", self->retries);
SET(allFinished, true);
}
}
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/concurrency/SleepingBarber.lf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/concurrency/SortedList.lf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target CCpp {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/micro/Big.lf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target C{
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/micro/Chameneos.lf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/micro/Counting.lf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/micro/PingPong.lf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/micro/ThreadRing.lf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
3 changes: 2 additions & 1 deletion benchmark/C/Savina/src/micro/Throughput.lf
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
threads: 2,
/// [[[end]]]
flags: "-lm",
flags: "-lm"
};

import BenchmarkRunner from "../BenchmarkRunner.lf";
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/Apsp.lf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/FilterBank.lf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/GuidedSearch.lf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ target CCpp {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/MatMul.lf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/NQueens.lf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ target C{
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/PiPrecision.lf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/RadixSort.lf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/C/Savina/src/parallelism/Trapezoidal.lf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target C {
/* [[[cog
if (threaded_runtime=="True"):
cog.outl(f"threads: {threads},")
cog.outl(f"scheduler: {scheduler},")
else:
cog.outl("threads: 0,")
]]] */
Expand Down
1 change: 1 addition & 0 deletions benchmark/runner/conf/default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
iterations: 12
threads: null
timeout: 1200
savina_path: "${oc.env:SAVINA_PATH}"
lf_path: "${oc.env:LF_PATH}"
continue_on_error: False
Expand Down
3 changes: 3 additions & 0 deletions benchmark/runner/conf/target/lf-c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ prepare: ["mkdir", "src"]
copy: ["cp", "-r", "${benchmark.targets.lf-c.copy_sources}", "src"]
gen: ["cog", "-r", "${args:benchmark.targets.lf-c.gen_args}",
"-D", "threads=${threads}",
"-D", "scheduler=${target.params.scheduler}",
"-D", "numIterations=${iterations}",
"-D", "threaded_runtime=True",
"src/${benchmark.targets.lf-c.lf_file}"]
compile: ["${lf_path}/bin/lfc", "src/${benchmark.targets.lf-c.lf_file}"]
run: ["bin/${benchmark.targets.lf-c.binary}"]
parser:
_target_: "parser.parse_lfc_output"
params:
scheduler: "GEDF_NP"
3 changes: 2 additions & 1 deletion org.lflang.lfc/src/org/lflang/lfc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public class Main {
* @author Marten Lohstroh <[email protected]>
*/
enum CLIOption {
COMPILER(null, "target-compiler", true, false, "Target compiler to invoke.", true),
CLEAN("c", "clean", false, false, "Clean before building.", true),
COMPILER(null, "target-compiler", true, false, "Target compiler to invoke.", true),
EXTERNAL_RUNTIME_PATH(null, "external-runtime-path", true, false, "Specify an external runtime library to be used by the compiled binary.", true),
FEDERATED("f", "federated", false, false, "Treat main reactor as federated.", false),
HELP("h", "help", false, false, "Display this information.", true),
Expand All @@ -117,6 +117,7 @@ enum CLIOption {
QUIET("q", "quiet", false, false, "Suppress output of the target compiler and other commands", true),
RTI("r", "rti", true, false, "Specify the location of the RTI.", true),
RUNTIME_VERSION(null, "runtime-version", true, false, "Specify the version of the runtime library used for compiling LF programs.", true),
SCHEDULER("s", "scheduler", true, false, "Specify the runtime scheduler (if supported).", true),
THREADS("t", "threads", true, false, "Specify the default number of threads.", true),
VERSION(null, "version", false, false, "Print version inforomation.", false);

Expand Down
2 changes: 2 additions & 0 deletions org.lflang.tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ test {
events "passed", "skipped", "failed"
showStandardStreams = true
}
// Pass the scheduler property on to the Java VM
systemProperty 'scheduler', System.getProperty('scheduler')
// Suggested by Gradle documentation: https://guides.gradle.org/performance/#parallel_test_execution
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnitPlatform()
Expand Down
1 change: 0 additions & 1 deletion org.lflang.tests/src/org/lflang/tests/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected boolean supportsDockerOption() {
return false;
}


@Test
public void runExampleTests() {
runTestsForTargets(Message.DESC_EXAMPLE_TESTS,
Expand Down
6 changes: 3 additions & 3 deletions org.lflang.tests/src/org/lflang/tests/Configurators.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface Configurator {
* @param test The test to configure.
* @return True if successful, false otherwise.
*/
static boolean useSingleThread(LFTest test) {
public static boolean useSingleThread(LFTest test) {
test.getContext().getArgs().setProperty("threads", "0");
return true;
}
Expand All @@ -62,7 +62,7 @@ static boolean useSingleThread(LFTest test) {
* @param test The test to configure
* @return True if successful, false otherwise.
*/
static boolean useFourThreads(LFTest test) {
public static boolean useFourThreads(LFTest test) {
test.getContext().getArgs().setProperty("threads", "4");
return true;
}
Expand All @@ -73,7 +73,7 @@ static boolean useFourThreads(LFTest test) {
* @param test The test to configure.
* @return True
*/
static boolean noChanges(LFTest test) {
public static boolean noChanges(LFTest test) {
return true;
}

Expand Down
1 change: 1 addition & 0 deletions org.lflang.tests/src/org/lflang/tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public static class Message {
public static final String DESC_TARGET_SPECIFIC = "Run target-specific tests (threads = 0)";
public static final String DESC_AS_CCPP = "Running C tests as CCpp.";
public static final String DESC_FOUR_THREADS = "Run non-concurrent and non-federated tests (threads = 4).";
public static final String DESC_SCHED_SWAPPING = "Running with non-default runtime scheduler ";

/* Missing dependency messages */
public static final String MISSING_DOCKER = "Executable 'docker' not found or 'docker' daemon thread not running";
Expand Down
75 changes: 75 additions & 0 deletions org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.lflang.tests.runtime;

import java.util.EnumSet;

import org.junit.jupiter.api.Test;

import org.lflang.Target;
import org.lflang.TargetProperty.SchedulerOption;
import org.lflang.tests.Configurators;
import org.lflang.tests.TestBase;
import org.lflang.tests.TestRegistry.TestCategory;

/**
*/
public class CSchedulerTest extends TestBase {


public CSchedulerTest() {
super(Target.C);
}

/**
* Swap the default runtime scheduler with other supported versions and
* run all the supported tests. Only run tests for a specific non-default
* scheduler if specified using a system property (e.g., -Dscheduler=GEDF_NP).
*/
@Test
public void runWithNonDefaultSchedulers() {
EnumSet<TestCategory> categories = EnumSet.of(TestCategory.CONCURRENT,
TestCategory.MULTIPORT);

// Add federated and docker tests if supported
if (!isWindows()) {
categories.add(TestCategory.FEDERATED);
if (isLinux()) {
categories.add(TestCategory.DOCKER_FEDERATED);
}
}
var name = System.getProperty("scheduler");

if (name != null) {
var option = EnumSet.allOf(SchedulerOption.class).stream()
.filter(it -> it.name().equals(name)).findFirst();
if (option.isPresent()) {
this.runTest(option.get(), categories);
} else {
throw new RuntimeException("Cannot find runtime scheduler called " + name);
}
} else {
for (SchedulerOption scheduler: EnumSet.allOf(SchedulerOption.class)) {
if (scheduler == SchedulerOption.getDefault()) continue;
this.runTest(scheduler, categories);
}
}
}

private void runTest(SchedulerOption scheduler, EnumSet<TestCategory> categories) {
this.runTestsForTargets(
Message.DESC_SCHED_SWAPPING + scheduler.toString() +".",
categories::contains,
test -> {
test.getContext()
.getArgs()
.setProperty(
"scheduler",
scheduler.toString()
);
return Configurators.useFourThreads(test);
},
TestLevel.EXECUTION,
true
);
}
}

4 changes: 1 addition & 3 deletions org.lflang.tests/src/org/lflang/tests/runtime/CTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Scoping unit tests. */

/*************
Copyright (c) 2019, The University of California at Berkeley.
Expand Down Expand Up @@ -100,7 +98,7 @@ public void runMultiportTests() {
public void runWithFourThreads() {
super.runWithFourThreads();
}

@Test
@Override
public void runSerializationTests() {
Expand Down
Loading

0 comments on commit 14e26fe

Please sign in to comment.