Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark Runner for C Benchmarks #777

Merged
merged 54 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
91570d2
Big benchmark using benchmark runner
mattchorlian Dec 1, 2021
4560e7d
fixed use of benchmark runner in Big, removed unused deque files
LDeng0205 Dec 2, 2021
e417a52
fixed typo
LDeng0205 Dec 2, 2021
b7176d1
Updating all micro benchmarks to use benchmark runner; fixed weird st…
LDeng0205 Dec 2, 2021
62ba6bf
Merge branch 'master' of https://github.com/lf-lang/lingua-franca int…
mattchorlian Dec 2, 2021
c109406
simplified benchmark runner with updated Big.lf file
mattchorlian Dec 2, 2021
3cf777d
fixed errors with BenchmarkRunner, and compilation errors in Big
LDeng0205 Dec 2, 2021
a5b7058
updated all micro benchmarks to use the new benchmarkrunner
LDeng0205 Dec 2, 2021
91092e2
including new BenchmarkRunner
LDeng0205 Dec 2, 2021
728da34
removed unused state variables in BenchmarkRunner.lf
LDeng0205 Dec 2, 2021
da0dab4
BoundedBuffer w/ benchmark runner
mattchorlian Dec 2, 2021
3af2780
Merge branch 'c-benchmark-runner' of https://github.com/lf-lang/lingu…
mattchorlian Dec 2, 2021
288118a
import benchmark runner for BoundedBuffer
mattchorlian Dec 2, 2021
c264646
using default value for iteration. added benchmark runner for apsp
LDeng0205 Dec 2, 2021
118c265
fixed error in bounded buffer
LDeng0205 Dec 2, 2021
08f70c6
Merge branch 'master' of https://github.com/lf-lang/lingua-franca int…
mattchorlian Dec 8, 2021
caa303a
more concurrency benchmarks with benchmark runner
mattchorlian Dec 8, 2021
5e4d546
update LogisticMap
mattchorlian Dec 9, 2021
006f371
added casting for calloc to fix compiler error when using CCpp target
LDeng0205 Jan 9, 2022
d6dcedf
Added benchmark runner to all paralellism benchmarks
LDeng0205 Jan 14, 2022
95e18e6
Merge branch 'master' of https://github.com/lf-lang/lingua-franca int…
mattchorlian Jan 14, 2022
ce6e354
Merge branch 'c-benchmark-runner' of https://github.com/lf-lang/lingu…
mattchorlian Jan 14, 2022
2426135
adding Philosophers, SleepingBarber, SortedLinkList
mattchorlian Jan 14, 2022
56abc46
attempt to fix failing benchmark tests
housengw Jan 15, 2022
2ddf6e1
copy BenchmarkRunner.lf source in savina yaml
housengw Jan 15, 2022
d06cde6
fix benchmark paths
housengw Jan 15, 2022
8d8a12f
fix path for lib
housengw Jan 16, 2022
63bfc1f
fix duplicate iteration=1 arg
housengw Jan 16, 2022
447b660
fix missing semicolon in BoundedBuffer
mattchorlian Jan 16, 2022
f1285e7
fix missing numIterations parameter in benchmarks
housengw Jan 16, 2022
8ded516
use up-to-date deque
housengw Jan 16, 2022
6629d27
delete stale deque
housengw Jan 16, 2022
d2d6f6a
use benchmark-tests.yml on this branch
housengw Jan 17, 2022
75b5346
consistent use of numIterations for concurrency benchmarks
mattchorlian Jan 17, 2022
2ddf499
fix early request_stop() bug
housengw Jan 17, 2022
654cce1
consistent use of numIterations all other benchmarks
mattchorlian Jan 17, 2022
0886c75
resolve conflicts
housengw Jan 17, 2022
4cbcad1
Merge remote-tracking branch 'origin/c-benchmark-runner' into fix-fai…
housengw Jan 17, 2022
40e4b7b
add num_iterations parameter to savina files
housengw Jan 17, 2022
f55a329
Merge pull request #852 from lf-lang/fix-failing-benchmark-ci
housengw Jan 17, 2022
47cc7c0
fix small bugs in PingPong, MatMul .yaml files
mattchorlian Jan 17, 2022
2050023
move numIterations parameter passing to target yaml files
housengw Jan 18, 2022
f8761b2
use this branch's ci.yml
housengw Jan 18, 2022
1a7378c
fix segfault in multithreaded philosopher
housengw Jan 18, 2022
c8668c6
fix ProdCons segfault
housengw Jan 18, 2022
814d848
resolve conflicts
housengw Jan 19, 2022
aa36832
deleting ProdCons.lf
mattchorlian Jan 26, 2022
ec1aa95
removed outdated matmul benchmark runner, changed name of Sorted Link…
LDeng0205 Jan 26, 2022
30a2530
fix SortedList config
mattchorlian Feb 4, 2022
7b86729
use master for workflow
mattchorlian Feb 4, 2022
2c3b411
typo in SortedList config
mattchorlian Feb 4, 2022
5aa722b
added banking and modified include path of deque in boundedbuffer to …
LDeng0205 Feb 4, 2022
95029e3
Merge branch 'master' of https://github.com/lf-lang/lingua-franca int…
mattchorlian Feb 4, 2022
ec040f9
Merge branch 'c-benchmark-runner' of https://github.com/lf-lang/lingu…
mattchorlian Feb 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

# Run the C benchmark tests.
c-benchmark-tests:
uses: lf-lang/lingua-franca/.github/workflows/benchmark-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/benchmark-tests.yml@c-benchmark-runner
mattchorlian marked this conversation as resolved.
Show resolved Hide resolved
with:
target: 'C'

Expand Down
94 changes: 29 additions & 65 deletions benchmark/C/Savina/src/BenchmarkRunner.lf
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,37 @@ target C;
*
* How to use:
* - Instantiate this reactor in the main reactor of the benchmark.
* - Connect the ports inStart, outIterationStart, inIterationFinish with
* - Connect the ports start, finish with
* the appropriate reactors of the benchmark.
* - Optionally connect the ports for initialization and cleanup.
* - Create a startup reaction in the main reactor that calls printBenchmarkInfo(),
*
* Prototype startup reaction in the main reactor of a benchmark:
* runner = new BenchmarkRunner(num_iterations=num_iterations);
* reaction(startup) -> runner.inStart {=
* reaction(startup) {=
* printBenchmarkInfo("ThreadRingReactorLFCppBenchmark");
* printSystemInfo();
* SET(runner.inStart, true);
* =}
*
* @param num_iterations How many times to execute the kernel of the benchmark to measure.
* @param use_init Benchmarks needs initialization and handles the corresponding signals.
* @param use_cleanup_iteration Benchmark needs cleanup after each iteration and handles the corresponding signals.
*
* @author Hannes Klein
* @author Shaokai Lin
* @author Matt Chorlian
* @author Arthur Deng
*/
reactor BenchmarkRunner(num_iterations:int(12), use_init:bool(false), use_cleanup_iteration:bool(false)) {
reactor BenchmarkRunner(num_iterations:int(12)) {

/** Signal to start execution. Set this input from a startup reaction in the main reactor. */
input inStart:bool;

/** Signals for starting and finishing the kernel and runtime measurement. */
output outIterationStart:bool;
input inIterationFinish:bool;

/** Signals for initializations that are not part of the measured kernel. */
output outInitializeStart:bool;
input inInitializeFinish:bool;

/** Signals for cleanup operations after each iteration of the kernel. */
output outCleanupIterationStart:bool;
input inCleanupIterationFinish:bool;
output start:bool;
input finish:bool;


/** Events to switch between the phases of running the iterations. */
logical action initBenchmark:bool;
logical action cleanupIteration:bool;
logical action nextIteration:bool;
logical action finish:bool;
logical action done:bool;

/** Number of iterations already executed. */
state count:unsigned(0);
Expand All @@ -66,63 +55,38 @@ reactor BenchmarkRunner(num_iterations:int(12), use_init:bool(false), use_cleanu
state startTime:instant_t;

/** Runtime measurements. */
state measuredTimes:interval_t[];
state measuredTimes: interval_t[];


reaction(startup) {=
reaction(startup) -> nextIteration {=
// Initialize an array of interval_t
self->measuredTimes = calloc(self->num_iterations, sizeof(interval_t));
=}

reaction(inStart) -> nextIteration, initBenchmark {=
if(self->use_init) {
schedule(initBenchmark, 0);
} else {
schedule(nextIteration, 0);
}
=}

reaction(initBenchmark) -> outInitializeStart {=
SET(outInitializeStart, true);
=}

reaction(inInitializeFinish) -> nextIteration {=
self->measuredTimes = (interval_t *) calloc(self->num_iterations, sizeof(interval_t));
schedule(nextIteration, 0);
=}


reaction(cleanupIteration) -> outCleanupIterationStart {=
SET(outCleanupIterationStart, true);
=}

reaction(inCleanupIterationFinish) -> nextIteration {=
schedule(nextIteration, 0);
=}

reaction(nextIteration) -> outIterationStart, finish {=
reaction(nextIteration) -> start, done {=
if (self->count < self->num_iterations) {
self->startTime = get_physical_time();
SET(outIterationStart, true);
SET(start, true);
} else {
schedule(finish, 0);
schedule(done, 0);
}
=}

reaction(inIterationFinish) -> nextIteration, cleanupIteration {=
reaction(finish) -> nextIteration {=
interval_t end_time = get_physical_time();
interval_t duration = end_time - self->startTime;
self->measuredTimes[self->count] = duration;
self->count += 1;

printf("Iteration: %d\t Duration: %.3f msec\n", self->count, toMS(duration));

if(self->use_cleanup_iteration) {
schedule(cleanupIteration, 0);
} else {
schedule(nextIteration, 0);
}
schedule(nextIteration, 0);

=}

reaction(finish) {=
reaction(done) {=
double* measuredMSTimes = getMSMeasurements(self->measuredTimes, self->num_iterations);
qsort(measuredMSTimes, self->num_iterations, sizeof(double), comp);

Expand All @@ -140,14 +104,14 @@ reactor BenchmarkRunner(num_iterations:int(12), use_init:bool(false), use_cleanu
}

int comp (const void * elem1, const void * elem2) {
int f = *((double*)elem1);
int s = *((double*)elem2);
if (f > s) return 1;
if (f < s) return -1;
return 0;
}
static double median(double* execTimes, int size) {
int f = *((double*)elem1);
int s = *((double*)elem2);
if (f > s) return 1;
if (f < s) return -1;
return 0;
}
static double median(double* execTimes, int size) {
if (size == 0) {
return 0.0;
}
Expand All @@ -162,7 +126,7 @@ reactor BenchmarkRunner(num_iterations:int(12), use_init:bool(false), use_cleanu

static double* getMSMeasurements(interval_t* measured_times, int num_iterations) {

double* msMeasurements = calloc(num_iterations, sizeof(double));
double* msMeasurements = (double *) calloc(num_iterations, sizeof(double));
for (int i = 0; i < num_iterations; i++) {
msMeasurements[i] = toMS(measured_times[i]);
}
Expand Down
40 changes: 32 additions & 8 deletions benchmark/C/Savina/src/concurrency/BoundedBuffer.lf
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ target C {
]]] */
threads: 0,
/// [[[end]]]
files: ["/lib/c/reactor-c/util/deque.h", "/lib/c/reactor-c/util/deque.c", "../include/PseudoRandom.h"],
files: ["../util/deque.h",
"../util/deque.c",
"../include/PseudoRandom.h"],
flags: "-lm",
logging: "warn"
};

import BenchmarkRunner from "../BenchmarkRunner.lf";


preamble {=
#include "PseudoRandom.h"
#include <math.h>
Expand All @@ -47,11 +52,11 @@ preamble {=
if(cost > 0) {
for(size_t i = 0; i < cost; i++) {
for(size_t j = 0; j < 100; j++) {
res += log(labs(nextDouble(&random)) + 0.01);
res += log(fabs(nextDouble(&random)) + 0.01);
}
}
} else {
res += log(labs(nextDouble(&random)) + 0.01);
res += log(fabs(nextDouble(&random)) + 0.01);
}

return res;
Expand All @@ -65,6 +70,9 @@ reactor ManagerReactor(bufferSize: size_t(50), numProducers: size_t(40), numCons
#include "deque.c"
=}

input start: bool;
output finished: bool;

state adjustedBuffersize: size_t(0);
state pendingData: deque_t;
state numTerminatedProducers: size_t(0);
Expand All @@ -78,7 +86,7 @@ reactor ManagerReactor(bufferSize: size_t(50), numProducers: size_t(40), numCons
input[numConsumers] consumerAvailable: bool;
output[numConsumers] consumerData: double;

reaction(startup) -> producerCommand {=
reaction(start) -> producerCommand {=
// reset local state
self->adjustedBuffersize = self->bufferSize - self->numProducers;
self->numTerminatedProducers = 0;
Expand All @@ -94,9 +102,10 @@ reactor ManagerReactor(bufferSize: size_t(50), numProducers: size_t(40), numCons
}
=}

reaction(consumerAvailable) -> consumerData, producerCommand {=
reaction(consumerAvailable) -> consumerData, producerCommand, finished {=
// abort if all producers have terminated and all data has been send
if((self->numTerminatedProducers == self->numProducers) && deque_is_empty(&self->pendingData)) {
SET(finished, true);
return;
}

Expand Down Expand Up @@ -150,9 +159,10 @@ reactor ProducerReactor(bank_index: size_t(0), numItemsToProduce: size_t(1000),
input produce: bool;
output data: double

input reset: bool;
output finished: bool;

reaction (startup) {=
reaction (reset) {=
// reset local state
self->prodItem = 0.0;
self->itemsProduced = 0;
Expand All @@ -174,12 +184,14 @@ reactor ConsumerReactor(bank_index: size_t(0), consCost: size_t(25)) {

state consItem: double(0.0);

input reset: bool;

input data: double;
output available: bool;

logical action sendAvailable;

reaction (startup) -> sendAvailable {=
reaction (reset) -> sendAvailable {=
// reset local state
self->consItem = 0.0;
schedule(sendAvailable, 0);
Expand All @@ -198,6 +210,7 @@ reactor ConsumerReactor(bank_index: size_t(0), consCost: size_t(25)) {

/* [[[cog
cog.outl('main reactor (')
cog.outl(f' numIterations: size_t({numIterations}),')
cog.outl(f' bufferSize: size_t({bufferSize}),')
cog.outl(f' prodCost: size_t({prodCost}),')
cog.outl(f' consCost: size_t({consCost}),')
Expand All @@ -206,6 +219,7 @@ reactor ConsumerReactor(bank_index: size_t(0), consCost: size_t(25)) {
cog.outl(f' numProducers: size_t({numProducers})')
]]] */
main reactor (
numIterations: size_t(12),
bufferSize: size_t(50),
prodCost: size_t(25),
consCost: size_t(25),
Expand All @@ -215,7 +229,17 @@ main reactor (
// [[[end]]]
) {

runner = new BenchmarkRunner(num_iterations=numIterations);
manager = new ManagerReactor(bufferSize=bufferSize, numProducers=numProducers, numConsumers=numConsumers);

(runner.start)+ -> manager.start, producers.reset, consumers.reset;
manager.finished -> runner.finish;

reaction(startup) {=
printBenchmarkInfo("ProdConsBenchmark");
printSystemInfo();
=}

producers = new[numProducers] ProducerReactor(numItemsToProduce=numItemsPerProducer, prodCost=prodCost);
consumers = new[numConsumers] ConsumerReactor(consCost=consCost);

Expand All @@ -225,4 +249,4 @@ main reactor (

consumers.available -> manager.consumerAvailable;
manager.consumerData -> consumers.data;
}
}
18 changes: 15 additions & 3 deletions benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ target C {
files: "../include/PseudoRandom.h"
};

import BenchmarkRunner from "../BenchmarkRunner.lf";


reactor ArbiterReactor(numRounds:size_t(1000), numSmokers:size_t(200)) {

Expand All @@ -80,13 +82,16 @@ reactor ArbiterReactor(numRounds:size_t(1000), numSmokers:size_t(200)) {

state roundsSoFar: size_t(0);
state random: PseudoRandom*;

input inStart:bool;
output outFinished:bool;

output[numSmokers] startSmoking: size_t;

logical action chooseSmoker;
logical action stop;

reaction(startup) -> chooseSmoker {=
reaction(inStart) -> chooseSmoker {=
// Initialize the random state variable
self->random = (PseudoRandom*)malloc(sizeof(PseudoRandom));
self->random->mValue = self->numRounds * self->numSmokers;
Expand Down Expand Up @@ -117,6 +122,10 @@ reactor ArbiterReactor(numRounds:size_t(1000), numSmokers:size_t(200)) {
}
=}

reaction(stop) -> outFinished {=
SET(outFinished, true);
=}

reaction(shutdown) {=
free(self->random);
=}
Expand Down Expand Up @@ -149,15 +158,18 @@ reactor SmokerReactor {


/* [[[cog
cog.outl(f'main reactor (numRounds:size_t({numRounds}), numSmokers:size_t({numSmokers}))')
cog.outl(f'main reactor (numIterations:size_t({numIterations}), numRounds:size_t({numRounds}), numSmokers:size_t({numSmokers}))')
]]] */
main reactor (numRounds:size_t(1000), numSmokers:size_t(200))
main reactor (numIterations:size_t(12), numRounds:size_t(1000), numSmokers:size_t(200))
/// [[[end]]]

{

arbiter = new ArbiterReactor(numRounds=numRounds, numSmokers=numSmokers);
runner = new BenchmarkRunner(num_iterations=numIterations)

runner.start -> arbiter.inStart;
arbiter.outFinished -> runner.finish;

reaction(startup) {=
// based on the Savina implementation:
Expand Down
Loading